javac compiler — oracle-tech

    Forum Stats

  • 3,702,035 Users
  • 2,239,551 Discussions
  • 7,835,727 Comments

Discussions

javac compiler

40773204077320 Posts: 1
edited June 12 in Java Programming

Hi everyall,

I'm trying to compile a java program on Linux system form command line.

The program is very simple. It includes only a class, which is in a package.

Practically my project is composed by a directory (HelloWorld) that contains two ones.

One is named "src", the other is called "bin".

In the first one, there is another directory (principale) where there is the java file (Saluto.java)

In this situation if I execute the command "javac -d ./bin/ ./src/principale/Saluto.java from ~/HelloWorld/ it works.

But if I execute "javac -d ./bin/ -sourcepath ./src principale/Saluto.java" or  "javac -d ./bin/ -sourcepath ./src/principale Saluto.java" fomr the same  point it doesn't.

in the html page https://docs.oracle.com/en/java/javase/14/docs/specs/man/javac.html#options it is explained that:

--source-path path or -sourcepath path
Specifies where to find source files. Except when compiling multiple modules together, this is the source code path used to search for class or interface definitions
So "javac" should search source files in "path" (that are ~/HelloWorld/src/ or ~/HelloWorld/src/principale in case), but it shouldn't.
Does anyone tell me what I'm doing wrong?
Thanks very much

Answers

  • dvohra21dvohra21 Posts: 14,009 Gold Crown
    edited June 12

    Is a package statement used? Is the src folder in the classpath? Please post the java class.

  • Roland MuellerRoland Mueller Posts: 73 Blue Ribbon

    A bit experimenting shows that sourcepath is used to find additional Java source files but does not influence where the Saluto.java has to be located.

    Thus, if class Saluto would make use of another class - let's say Pronto - inside the same package then sourcepath is used to find Pronto.java, but Saluto.java must be nevertheless fully qualified:

    cd /tmp ; javac -d ~/HelloWorld/bin -sourcepath /usr/src/more ~/HelloWorld/src/principlale/Saluto.java

Sign In or Register to comment.