简体   繁体   中英

javac -sourcepath option not working

I am at C:\ and from here I want to compile my Bingo.java source file which resides in C:\Users\Devashish\Documents\NetBeansProjects\Bingo\src\bingo\Bingo.java . If I understand -sourcepath properly, it is used to tell the java compiler where to look for .java source files.

I tried the following to set -sourcepath but none seem to work:

C:\>javac -sourcepath C:\Users\Devashish\Documents\NetBeansProjects\Bingo\src\
bingo\Bingo.java

C:\>javac -sourcepath C:\Users\Devashish\Documents\NetBeansProjects\Bingo\src\bingo\ Bingo.java

Even these...

C:\>javac -sourcepath C:\Users\Devashish\Documents\NetBeansProjects\Bingo\src bingo\Bingo.java

C:\>javac -sourcepath C:\Users\Devashish\Documents\NetBeansProjects\Bingo\src\bingo Bingo.java

All above give the File not found error.

I would like to mention that compiling without -sourcepath from the same location works fine:

C:\>javac C:\Users\Devashish\Documents\NetBeansProjects\Bingo\src\bingo\Bingo.java

I believe I'm doing something very stupid here but can't figure it out. Any help would be appreciated.

-sourcepath defines OTHER .java files that should be in your project. for example:

You have "C:\A.java":

public class A {
    public static void main(String args[]) {
       B.hello();
    }
}

And C:\dir\B.java:

public class B {
    public void hello() {
        System.out.println("Hello!");
    }
}

In this case, when you compile and run you need sourcepath to C:\dir\B.java.

EDIT: Classpath ( -cp ) is for .class , Sourcepath ( -sourcepath ) is for .java .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM