aspose file tools*
The moose likes Beginning Java and the fly likes compiling packages with javac using appropriate directory structure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "compiling packages with javac using appropriate directory structure" Watch "compiling packages with javac using appropriate directory structure" New topic
Author

compiling packages with javac using appropriate directory structure

Rob Sweeny
Greenhorn

Joined: Jan 14, 2010
Posts: 16
Hi All,

I am trying to set up a meaningful directury structure to house my source and class files
and finally use javac to compile my .java files into class files.

As a noob I'm having problems doing so.

javac can't find my main class GreetingsUniverse.java

This is what I have so far:

C:\java\classes\com\scjaexam\tutorial\planets
C:\java\src\com\scjaexam\tutorial\planets

C:\java\src\com\scjaexam\tutorial\GreetingsUniverse.java



C:\java\src\com\scjaexam\tutorial\planets\Earth.java




c:\java>javac -classpath classes -sourcepath src GrettingsUniverse.java
javac: file not found: GrettingsUniverse.java

c:\java>javac -classpath classes -sourcepath c:\src GrettingsUniverse.java
javac: file not found: GrettingsUniverse.java

c:\java>javac -classpath classes -sourcepath "c:\src" GrettingsUniverse.java
javac: file not found: GrettingsUniverse.java

c:\java>javac -classpath classes -sourcepath "C:\java\src\com\scjaexam\tutorial" GrettingsUniverse.java
javac: file not found: GrettingsUniverse.java


I was able to compile and interpret the code successfully when all files where in the same dir without using the package or imports statements.
Matt Jarchow
Greenhorn

Joined: Jan 15, 2010
Posts: 1
The command you are looking for is:

javac -classpath classes -sourcepath src -d classes src\com\scjaexam\tutorial\GreetingsUniverse.java

You need to specify the full path of the file being compiled.

The -d argument is necessary for the compiler to know where to place your class files. If you leave that out, your .class files will be placed in the "src" heirarchy.
Stephan Eisenhoff
Greenhorn

Joined: Aug 09, 2013
Posts: 3
I am happy I found this topic. Strange that the answers are not provided with the OCA Study Guide... And even stranger they forget to put () after the method in their example. As a noob it took me till finding this forum where the question was answered to figure it out. I will stay be back here when I get in trouble with later questions.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: compiling packages with javac using appropriate directory structure