티스토리 뷰

SW개발

자바 클래스패스 가져오기

개소왕 2018. 6. 6. 16:33

String sPath = System.getProperty("java.class.path");

System.out.println(sPath);

// 결과 : /home/udell/workspace/170112ClusteringEx/target/test-classes:/home/udell/workspace/170112ClusteringEx/target/classes:/home/udell/.p2/pool/plugins/org.junit_4.12.0.v201504281640/junit.jar:/home/udell/.p2/pool/plugins/org.hamcrest.core_1.3.0.v201303031735.jar:...


// 분리

String[] classpathEntries = sPath.split(File.pathSeparator);


https://stackoverflow.com/questions/17540942/how-to-get-the-path-of-running-java-program?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa


sPath = new File(".").getAbsolutePath();

System.out.println(sPath);

// 결과 : /home/udell/workspace/170112ClusteringEx/.



sPath = this.getClass().getResource("Prac_1_Mahout.class").toString();

System.out.println(sPath);

// 결과 : file:/home/udell/workspace/170112ClusteringEx/target/classes/com/dogcowking/dev/prac/Prac_1_Mahout.class



sPath = new File(this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getAbsolutePath();

System.out.println(sPath);

// 결과 : /home/udell/workspace/170112ClusteringEx/target/classes


공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
글 보관함