Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
450 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.

See Question&Answers more detail:os

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

1 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...