• Post Reply Bookmark Topic Watch Topic
  • New Topic

Few questions after building Ant file in eclipse  RSS feed

 
Ranch Hand
Posts: 254
1
Java MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created a build file using Export option in the context menu of the Eclipse project. Creating the build.xml was not a difficult thing, so to speak as it was managed by Eclipse.

Then I ran the build file by right clicking on it - and selecting the desired option. Now I added a sample java class in the default package. But running the build did not run this Java class.

This is the build.xml:



Some doubts that popped up into my head; how do I run the project after successfully building it? It appears from the docs that I would need a separate <target>. If I have two class files that I have to execute back to back what steps do I take?

And if I have to build this project from command line, how would I proceed? I'm new to Ant and will deeply appreciate your thoughts.
 
author & internet detective
Sheriff
Posts: 37819
582
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashan,
What do you mean by not running the second file? Did it not create a .class file? Or something else? To troubleshoot the problem, try right clicking the Ant xm and choosing "run as" > "Ant build...". The put "-v" in the main tab's argument section. That puts Ant into debug mode. Post the output here. (assuming it is very long, the last 50 lines should be fine)

To run at the command line, you type ant nameOfBuild file. You might need to add Ant to your path. (It can be found in the plugins directory of Eclipse or you can download it from the internet.)

This isn't the problem, but it isn't good practice to use the default package.
 
Ahsan Bagwan
Ranch Hand
Posts: 254
1
Java MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your response. Somehow the build failed. I have passed the "-v" argument as you suggested. Following is the output that got sent to the console:



I was under the impression that this build file is only bound to work with Eclipse. Will try running this from command line while ensuring that Ant is in the PATH.

And the test class was compiled after building it again. I am wondering which target was responsible for that.
 
Ahsan Bagwan
Ranch Hand
Posts: 254
1
Java MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also do Java developers find themselves hand coding the build file to customize something (for instance running JUnit test) after Eclipse has generated that very file?

Please pardon my ignorance; I have just started with Ant and the learning curve looks steep.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37819
582
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At least the error is in there:

com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK


This means you need to set JAVA_HOME and possibly add the JDK to your path on the operating system level. In Windows, it is under "System".

Most people don't generate an Ant build from Eclipse so the question of hand coding doesn't come up. People generally either write their own Ant build outside of Eclipse or use Maven.
 
Ahsan Bagwan
Ranch Hand
Posts: 254
1
Java MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a JDK version mismatch or something else? My bin/ directory of JDK is already on the path. Here is the output after running with -debug:



Edit: I realized that I had to add the JAVA_HOME variable as well. I went ahead and created a new system env variable with value:



But the same problem persists. Is my JAVA_HOME pointing to correct path?
 
author
Bartender
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That looks correct, please verify that this file exists: C:\Program Files\Java\jdk1.6.0_12\lib\tools.jar
That JAR file file contains the com.sun.tools.javac.Main class reported missing.
 
Ahsan Bagwan
Ranch Hand
Posts: 254
1
Java MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is indeed present in the \lib folder. And now the project also builds fine. I am baffled by seeing this kind of erratic behaviour.
 
Bring out your dead! Or a tiny ad:
ScroogeXHTML 7.1 - RTF to HTML5 / XHTML converter
https://coderanch.com/t/690611/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!