In one project I am currently doing we have to deliver the final project as a source package with an Ant build file. Since I recently have gotten into the habit of using Eclipse (which is somewhat of a standard at the Technical University of Vienna), I wanted to somehow integrate both goals. As luck have it, Eclipse can start a new project by importing an Ant build file. Unfortunately the process is not without some detours…
First of all, Eclipse behaved somewhat strangely. The build.xml file I imported defined a source folder called src and this popped up quite nicely in the Package Explorer. Unfortunately, as soon as I make a new class, this is source folder turns into a link that points to a src folder on my Desktop! How strange is that? If someone has a clue as to why this happens, feel free to comment. Anyway, the fix is simple. Delete the «linked folder» and add a new source folder (Right Click, New->Source Folder) with the name defined in the Ant build file (build.xml). In my case, this was simply src.
Finally (after making a new class file to put into my new src directory) I get to run the Ant file. But, alas…
Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK
Say what? No clue why this happens, but after some googling I found the answer on this page:
Go to Window > Preferences > Ant > Runtime. Choose the Classpath tab. Select the Global Properties node in the tree and click Add External JARs. Select tools.jar from your JDK directory.
That fixed everything for me, but it also stated this, and I am quoting it just for completeness (maybe someone needs it):
Go to Window > Preferences > Java > Installed JREs. Double click your JRE and deselect “Use default system libraries”. Click Add External JARs and add the location of tools.jar to that classpath. Make sure you are using the SDK and not the JRE.
Hope someones find it useful.
Because I tend to forget things (oh, like that’s new) I have uploaded a small rar file that shows (me|you) how to setup Eclipse, Ant, jar creation, and a Java Logging properties file.
You get it here.
The dslab2.logging.properties file also has some comments as to how one specifies it to the app, as well as how to name logs.