試圖從Thinking in Java
編譯.java文件。編譯器找不到Class.forName()的類
package pck;
/...
public class AtUnitExample1 {
public String methodOne() { return "This is methodOne"; }
@Test boolean testMethodOne() { return methodOne().equals("This is methodOne"); }
// ...
public static void main(String[] args) throws Exception {
// OSExecute.command("java net.mindview.atunit.AtUnit pck.AtUnitExample1"); // ORIGINAL
OSExecute.command("java -classpath ./out/production/Exercises/ net.mindview.atunit.AtUnit pck.AtUnitExample1"); // My version
}
}
СlassAtUnit
是一種實現JUnit
測試的,它會檢查與使用反射@Test
註釋方法。它將сlass的名稱作爲命令行參數進行檢查。
但是,當我嘗試編譯原始文件時,編譯器會拋出一個OSExecuteException
表示Could not find or load main class net.mindview.atunit.AtUnit
。
我認爲這可能是一個類的不同位置的問題,並改變了命令。在這種情況下,我有FileNotFoundException
與消息:/mnt/data-disk/MEGA/Программирование/Java/Exercises/pck.AtUnitExample1.class (No such file or directory)
。 AtUnit
嘗試撥打Class.forName()
時會出現異常。
怎麼了?
包的結構:
UPD:我改名西裏爾字母符號的文件夾,但它並不能幫助。
UPD2:項目類路徑:
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/charsets.jar
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/cldrdata.jar
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/dnsns.jar
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/icedtea-sound.jar
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/jaccess.jar
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/localedata.jar
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/nashorn.jar
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/sunec.jar
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/sunjce_provider.jar
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/sunpkcs11.jar
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/zipfs.jar
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/jce.jar
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/jsse.jar
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/management-agent.jar
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/resources.jar
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar
/mnt/data-disk/MEGA/Programming/Java/Exercises/out/production/Exercises/
/home/nikita/Downloads/javassist-3.9.0.GA.jar
/opt/idea-IC-172.3317.76/lib/idea_rt.jar
我想要做的第一件事是看看它是否在類路徑上,你可以這樣做https://www.mkyong.com/java/how-to-print-out-the-current-project- classpath/ –
你在UPD2中打印了哪個類路徑?由於您正在生成一個新的java進程,因此classpath可能與您的主進程不同。 – NilsH
我編譯了J Smith給我的代碼 – luckystrrrike