Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
226 views
in Technique[技术] by (71.8m points)

java - Differences between classpath and sourcepath options of javac

I read the Sun documentation and a lot of posts on Stack Overflow, but I'm still confused about the differences between the Java compiler options -cp and -sourcepath.

Let say I have this directory structure:

c:Javaproject1src (where the Java source files are)  
c:Javaproject1in (where the Java class files will be or already are)  

Let's also say I have a source file MainClass.java in a package com.mypackage, and that the directory structure is ok in the source folder.

I'm in the project1 directory and run:

javac -d bin -sourcepath src src/com/mypackage/MainClass.java  

or

javac -d bin -classpath src src/com/mypackage/MainClass.java  

and I obtain the same result. In verbose mode, the search path for source files is src in both cases.

It would be great if anybody could help me figure out the specifics of these options.

question from:https://stackoverflow.com/questions/2441760/differences-between-classpath-and-sourcepath-options-of-javac

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
 -classpath classpath

Set the user class path, overriding the user class path in the CLASSPATH environment variable. If neither CLASSPATH or -classpath is specified, the user class path consists of the current directory.

If the -sourcepath option is not specified, the user class path is searched for source files as well as class files.

-sourcepath sourcepath

Specify the source code path to search for class or interface definitions. As with the user class path, source path entries are separated by semicolons (;) and can be directories, JAR archives, or ZIP archives. If packages are used, the local path name within the directory or archive must reflect the package name.

Note that classes found through the classpath are subject to automatic recompilation if their sources are found.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...