• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compiling packeges

 
Juhan Voolaid
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to compile my project using javac command line tool, but without success. As most of you, I use a powerful IDE when developing and don't bother myself with such a trivial task like it is compiling.

Now when I want to try and build a larger project than a few source files the first time, I don't want to believe that it is so complicated.

My project's file structure is something like that:

src/rootPacket/*.java
src/rootPacket/child1/*.java
src/rootPacket/child1/grandChild1\*.java
... etc

So I how do you compile all that. There can also be child2 and child102 in the packet hierarchy.

As I was hoping to execute these commands, I failed miserably:
javac -sourcepath src -d classes *.java
javac -sourcepath src/* -d classes *.java
javac -sourcepath src/** -d classes *.java
javac -d classes src/*/*.java

.. etc


So how to use javac, the arguments and wildcards correctly and intelligently. I don't want to type in all the package or source file names separately.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Juhan,

I don't know for sure (because always use an IDE to develop), but to my opinion you have to get correct order to compile stuff using the command line. So if your 2nd package is depending on the 1st package you have to compile the 1st package. And to compile the 2nd package successfully you have to add the dir with the class files of 1st package to the classpath when using javac.

What's the reason why you would use javac to compile your classes? Why don't take the easy road and use an IDE (or an Ant build file for example).

Kind regards,
Roel
 
Anne Crace
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I never used that tool . I used Eclipse initially to compile and when near complete used Roel's Ant script, found here: Ant Build for SCJD. Ant really simplifies things and the learning curve is not too steep. It is really worthwhile to learn how to use it.
 
Juhan Voolaid
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, figured it out.

Here is how I did:

javac -d classes -sourcepath src [path to the main class: src\rootPacket\MainClass.java]

The sourcepath tells the location form where to look for the dependencies (that the main class needs). Since all the classes are dependent on one another, they all get compiled. I am afraid that will not be the case, when there are classes in the source directory that are never used by other classes.
 
Juhan Voolaid
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:
What's the reason why you would use javac to compile your classes? Why don't take the easy road and use an IDE (or an Ant build file for example).


Want to do it by the book .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic