• Post Reply Bookmark Topic Watch Topic
  • New Topic

Quick compilation question!  RSS feed

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have four folders created in a C:/jakarta-tomcat-5/webapps/begjsp-tourism/WEB-INF/classes directory packaged at com.wrox.tourism. Each folder has java code that imports code from the other folders, but when I compile, the code does not recognize packages imported. How can I compile all the code in all four folders at the same time using a command prompt.
 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Write an ANT script, set the classpaths as appropiate before compiling certain packages and make a build (a .jar for example).
 
Robert Bonslater
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do I have to use ANT. Can I make some sort of compile.bat file to accomplish this for me, or maybe do something to my classpath.

Please advise.
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no, you don't have to use ANT.
If you compile from the correct location (meaning the root of the classpath) the compiler should find your classes as long as they're on the classpath.

Of course if you have circular references in your imports (class A uses class B uses class C uses class A for example) all bets are off..
 
Robert Bonslater
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just added all the directories in one compilation process on
command prompt and it compiled:

javac com\wrox\tourism\business\*.java com\wrox\tourism\entity\*.java com\wrox\tourism\actions\*.java com\wrox\tourism\db\*.java com\wrox\tourism\db\util\*.java

I still don't understand why one must compile it as a whole rather than in separate pieces. Do you know?
 
Robert Bonslater
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help.
 
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Do I have to use ANT. Can I make some sort of compile.bat file to accomplish this for me, or maybe do something to my classpath


ANT or any other build process is best recommended. Compiling from the cmd line or by setting cp as env variables doesnt augur well for portability or from a combined dev point of view (where there are many developers working on the same code and u use some kind of scm). You can get away with it if u are working on a project all by yourself for learning purposes, but as I said earlier, use the arguments I put forth as an excuse to study ANT - will stand u in good stead in the long run :-)

ram.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Robert Bonslater:

I still don't understand why one must compile it as a whole rather than in separate pieces. Do you know?


that all depends on how the pieces work together.
If you have a class that's not calling any of your other classes you can compile that without referring to those other classes.
But if the class you want to compile references 10 others that each reference another 5, you're looking at compiling a lot of stuff.
 
K Riaz
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is why I recommended ANT straightaway. You just edit your code and run the build file. No need to worry about the compilation order.

I don't understand why you don't wish to use it and are opting for a batch file. ANT is incredibly easy to use, and in your case, you will just need to make one <target> and invoke the javac command. Don't try to reinvent the wheel.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!