Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

compiling packages with javac using appropriate directory structure

 
Rob Sweeny
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic