[英]How to compile set of java files in different packages and then build .jar file using command line?
[英]How to compile a java file using the command line?
我想測試 Java 在我的機器上是否正常工作,為此我編寫了這部分代碼。
這是代碼:
public class Test {
public static void main(String args[]){
System.out.println("This is a Test class");
}
}
Test.java 文件位於目錄C:\\Users\\HP\\Desktop\\JAVA Code 中,
我執行此 java compile 命令來編譯 java 類: javac Test.java ,出現以下錯誤:
C:\Users\HP\Desktop\JAVA Code>javac Test.java
Test.java:1: error: error while writing Test: Test.class (Le fichier spÚcifiÚ est introuvable)
public class Test {
^
1 error
感謝您的回復,最終我解決了錯誤 這是解決方案:我使用的是windows 10 ,所以當我編譯 JAVA 文件時,windows 由於權限拒絕了這個過程,我將javac.exe添加到授權應用程序列表中在 windows 中,它的工作原理。
您的工作目錄中 JAVA 和 Code 之間的空格可能存在問題。 這種約定(帶有空格的目錄名稱)可能會產生荒謬且耗時的麻煩。 請嘗試將C:\\Users\\HP\\Desktop\\JAVA%20Code作為 Test.java 文件的路徑。
如果使用 Mac,您可以使用~/Desktop/JAVA\\ Code 。
希望它能奏效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.