[英]Java Class Files not recognized by ls or ls -a
After I successfully compile both java files using " javac -d /mypath/classes -s /mypath/source filename.java" I run the Main file from the source directory using " java -classpath -d /mypath/classes Main " The terminal will successfully output as follows:使用“ javac -d /mypath/classes -s /mypath/source filename.java”成功编译两个java文件后,我使用“ java -classpath -d /mypath/classes Main ”从源目录运行Main文件 终端将成功输出如下:
Make: Mazda
Color: White
Year: 1997
Model: Miata MX-5
When I ls either the classes directory or source directory I get nothing.当我 ls 类目录或源目录时,我什么也没得到。 I try ls -l and I total 0 in both directories.
我尝试 ls -l 并且我在两个目录中总共为 0。 I tried ls -a and the terminal tells me " . .. " I think that signifies there are two files in there, but I cant see them at all.
我试过 ls -a 并且终端告诉我“...”我认为这意味着那里有两个文件,但我根本看不到它们。 How do I make it so I can see the created class files and source files that I compiled with
javac
?我如何制作它以便我可以看到我用
javac
编译的创建的类文件和源文件?
#Car.java
public class Car {
String model;
String make;
String color;
int year;
public void getCarFacts(){
System.out.println("Model: " + model);
System.out.println("Make: " + make);
System.out.println("Color: " + color);
System.out.println("Year: " + year);
}
}
#Main.java
public class Main{
public static void(String args[]){
Car myCar
myCar = new Car();
myCar.model = "Miata MX-5";
myCar.make = "Mazda";
myCar.color = "White";
myCar.year = 1997;
myCar.getCarFacts();
}
}
# ===File Tree===
├── classes
├── source
└── workspace
├── Car.java
└── Main.java
Entire terminal output from start to finish从头到尾的整个终端输出
achrotz@penguin:~/hope/proj1$ tree ./
./
├── classes
├── source
└── workspace
├── Car.java
└── Main.java
3 directories, 2 files
achrotz@penguin:~/hope/proj1$ cd workspace
achrotz@penguin:~/hope/proj1/workspace$ javac -d /hope/proj1/classes -s /hope/proj1/source Car.java
achrotz@penguin:~/hope/proj1/workspace$ javac -d /hope/proj1/classes -s /hope/proj1/source Main.java
achrotz@penguin:~/hope/proj1/workspace$ cd ..
achrotz@penguin:~/hope/proj1$ cd source
achrotz@penguin:~/hope/proj1/source$ java -classpath /hope/proj1/classes Main
Make: Mazda
Color: White
Year: 1997
Model: Miata MX-5
achrotz@penguin:~/hope/proj1/source$ cd ..
achrotz@penguin:~/hope/proj1$ cd source
achrotz@penguin:~/hope/proj1/source$ ls -a
. ..
achrotz@penguin:~/hope/proj1/source$ ls -l
total 0
achrotz@penguin:~/hope/proj1/source$ ls
achrotz@penguin:~/hope/proj1/source$ cd ..
achrotz@penguin:~/hope/proj1$ cd classes
achrotz@penguin:~/hope/proj1/classes$ ls -a
. ..
achrotz@penguin:~/hope/proj1/classes$ ls -l
total 0
achrotz@penguin:~/hope/proj1/classes$ ls
You have one directory structure at root level /hope/proj1/...
where your source files and classes are then you have the same structure in your home directory that is empty and where you perform your ls
, ~/hope/proj1 /...
您在根级别
/hope/proj1/...
有一个目录结构,其中您的源文件和类在您的主目录中具有相同的结构,该结构是空的,并且您在其中执行ls
, ~/hope/proj1 /...
This will compile the Car.java file found outside of your home folder这将编译在您的主文件夹之外找到的 Car.java 文件
javac -d /hope/proj1/classes -s /hope/proj1/source Car.java
This will compile the Car.java file found inside of your home folder and store the class file inside the home folder as well这将编译在您的主文件夹中找到的 Car.java 文件,并将类文件也存储在主文件夹中
javac -d ~/hope/proj1/classes -s ~/hope/proj1/source Car.java
but since you seem to have the source files in the workspace folder the above would have to be changed to但由于您似乎在工作区文件夹中有源文件,因此必须将上述内容更改为
javac -d ~/hope/proj1/classes -s ~/hope/proj1/workspace Car.java
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.