Forum Stats

  • 3,840,393 Users
  • 2,262,599 Discussions


javac compiler

CTKMat Member Posts: 6 Red Ribbon
edited Jun 12, 2020 4:12PM 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 (

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

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

in the html page 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


  • dvohra21
    dvohra21 Member Posts: 14,628 Gold Crown
    edited Jun 12, 2020 4:12PM

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

  • Roland Mueller
    Roland Mueller Member Posts: 79 Blue Ribbon

    A bit experimenting shows that sourcepath is used to find additional Java source files but does not influence where the 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, but must be nevertheless fully qualified:

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