- 3,723,261 Users
- 2,244,521 Discussions
- 7,850,383 Comments
Forum Stats
Discussions
Categories
- 16 Data
- 362.2K Big Data Appliance
- 7 Data Science
- 2.1K Databases
- 607 General Database Discussions
- 3.7K Java and JavaScript in the Database
- 32 Multilingual Engine
- 497 MySQL Community Space
- 7 NoSQL Database
- 7.7K Oracle Database Express Edition (XE)
- 2.8K ORDS, SODA & JSON in the Database
- 421 SQLcl
- 61 SQL Developer Data Modeler
- 185.1K SQL & PL/SQL
- 21.1K SQL Developer
- 2.4K Development
- 3 Developer Projects
- 32 Programming Languages
- 135.6K Development Tools
- 12 DevOps
- 3K QA/Testing
- 334 Java
- 10 Java Learning Subscription
- 12 Database Connectivity
- 71 Java Community Process
- 2 Java 25
- 11 Java APIs
- 141.2K Java Development Tools
- 8 Java EE (Java Enterprise Edition)
- 153K Java Essentials
- 135 Java 8 Questions
- 86.2K Java Programming
- 270 Java Lambda MOOC
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 16 Java SE
- 13.8K Java Security
- 4 Java User Groups
- 22 JavaScript - Nashorn
- 18 Programs
- 147 LiveLabs
- 34 Workshops
- 10 Software
- 4 Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 4 Deutsche Oracle Community
- 16 Español
- 1.9K Japanese
- 3 Portuguese
javac compiler

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
-
Is a package statement used? Is the src folder in the classpath? Please post the java class.
-
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