Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

javac -sourcepath & ant src(or srcdir)

807601Dec 14 2007 — edited Dec 15 2007
Hi all:
I encountered a very confusing problem when using javac.
Now I have a class Test.java, which belongs to the package "test", see the source code below:
package test;
public class Test {
	public static void main(String[] args) {
		System.out.println("test success!");
	}
}
My test folder archive:


tmp/--src/--test/--Test.java
|
build.xml


The compile target in build.xml is:
	<target name="compile" depends="init">
		<javac destdir="classes">
			<src path="src"/>
		</javac>
	</target>
Now I am under the base directory(~/*/tmp/$), when run ant in the terminal there is no doubt that the ant will successfully build my class "Test.java" into the folder classes.

It's known to all that "src" in ant is used to set the -sourcepath option used by "javac". However, when I directly use javac in terminal(still under the base directory) by setting the -sourcepath options, the compiler tell me it cannot find my class. See below for details:
wxiong@earth:~/workspace/tmp$ ls -a
*. .. build.xml src*
wxiong@earth:~/workspace/tmp$ ls -a src
*. .. test*
wxiong@earth:~/workspace/tmp$ ls -a src/test
*. .. Test.java*
*//above is my workspace info, and below I run the "javac"*
wxiong@earth:~/workspace/tmp$ javac -sourcepath src test/Test.java
javac: file not found: test/Test.java
Usage: javac <options> <source files>
use -help for a list of possible options
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 11 2008
Added on Dec 14 2007
1 comment
407 views