-sourcepath vs -classpath

Studying oracle certification, I try to use all possible scenarios that may arise during the exam. For example, there is little doubt about the shell command line (based on unix):

Suppose there is a folder with a name myProjectand a subfolder calledmyProject/source.

The file SubFile.javais in the folder myProject/source, and the other file File.javais in the folder myProject.

By typing the following commands, I get different types of behavior:

cd source (so currently I'm in "myProject / source")

javac -sourcepath ../ File.java
 // The ../ command does not work to access the Folder folder, then after compiling File.javafrom the myProjectfolder and returning to the subfolder if I try:

javac -classpath ../ SubFile.java

// with the flag -classpathit seems that it accepts the syntax ../for accessing the folder super.

Do you know why this works? and besides, is there access to the folder superwith the flag -sourcepath?

+5
source share
1 answer

It depends on whether there are SubFilelinks File.

Consider the following code:

public class SubFile {
    private static File file = new File();
}

It is assumed that this file is in the source folder and it is assumed that you are in the source folder, then

javac -sourcepath ../ SubFile.java

compiles SubFile.javain SubFile.classinside the source folder and compiles File.javain File.classin the parent folder. If there is no dependency between these files, the compiler will not compile File.java(which means that the compiler will not automatically compile all files on sourcepath).

-classpath, , - (, File.class ):

javac -classpath .. -sourcepath \temp SubFile.java

. javac - Java pathpath sourcepath javac .

:

. , , , .

+3

All Articles