Ant build won't run in Eclipse - eclipse

I have an Ant build.xml which no longer runs when launched in Eclipse.
I click on the External Tools Configuration, select the Ant Build I've been running, and click Run.
Nothing happens -- no console window and the build doesn't appear to launch (the classes are not compile nor is the WAR file created).
I recently added a plugin (Spring IDE), this is the only thing I can think of that has changed recently as far as my Eclipse configuration.
I can run the Ant build fine from the command line.
Can anyone suggest where I might look to track down my error?
I'm using the Eclipse Helios release, Build id: 20100617-1415 on Windows XP.

As per pstanton's comment this symptom will occur if your ANT_HOME folder is not correctly defined in Eclipse. Eclipse seems to ignore the ANT_HOME system property.
window->preferences->ant->runtime->Classpath Tab

I faced same problem today , reason behind this was ANT_HOME path variable explained in other answers also.
Initially I added ANT_HOME at 2 places given below and it was not working.
window->preferences->ant->runtime->properties Tab
window->preferences->ant->runtime->Classpath Tab
But when I remove Classpath tab ant home entry ( by setting it to default using Restore default option on right bottom of preferences window ) it worked :). So far it is just a surprise for me because I added same ant home path at both the places.

You can check out the example in this Apache Ant tutorial.
But you can also try to run your same build.xml ant files through a Java Launcher, with org.apache.tools.ant.Main as the Main class.
That would at least prove your scripts are working in an Eclipse environment.
When you look at the Ant FAQ, you also see:
I installed Ant 1.6.x and now get java.lang.InstantiationException: org.apache.tools.ant.Main
The cause of this is that there is an old version of ant somewhere in the class path or configuration.
Maybe your error message is somehow hidden, but it can be worth checking your classpath and see if no other ant library is there.

Related

Eclipse Mars - Web Application - Tomcat - Maven - Deploy and Debug

Is there a foolproof simple method to run and debug a Simple (tutorial level) Maven Web App in a local apache tomacat server from Eclipse Mars?.
I am developing a web app and I am able to run it sometimes, and sometimes not, and I am able to debug it sometimes, and sometimes not. Its a bit frustrating.
My current preference is to run the project from a Maven configuration having as goal tomcat:run. It builds and runs always, but it wont debug, i.e. if I place a breakpoint within my Java code in the servlet code, it is not reached. (some times it is reached the first time I run the project, but then it fails to find the source code of some file, and stops breaking for the subsequent runs...)
I have tried also "Debug on Server" configuration, but then, in that case I had to run a Maven install before running the project or, otherwise, some classes would not be found. And that also stopped working now. It just cant find some of the classes from src, although the Web Deployment Assembly configuration has the source being deployed into WEB-INF/classes.
(you may have been downvoted because there are a few questions lumped in to one. I'll try to answer them all because I'm all too familiar with your pain)
Eclipse's maven integration is notoriously flaky when it comes to debugging webapps, even with MARS. You can indeed use tomcat6:run or tomcat7:run for webapps. Here's a few 'best practices' that keep me sane:
Always execute 'clean' as part of the goal.
Make sure you follow the standard maven WAR project layout. You can break from this but have to be careful to specify all the overridden paths for META-INF etc.
When you stop/kill the process in Eclipse, you will often find that the process actually continues running but has detached itself from eclipse.exe as a parent process. You need to manually kill the java.exe process or you'll find 'port already in use' errors. ProcessExplorer is very useful for keeping an eye on this.
When you hit a breakpoint and it says 'source not found', there are a few things you can try.
Add your maven installation under window-preferences - maven/installations. Set this as the default one.
In your run configuration, make sure that you are using your system installation instead of the embedded one.
When you hit a breakpoint, close the editor and then reopen it by clicking on the point in the debug tree.
So you are trying to debug a maven project with goal "tomcat:run" in Eclipse and the application is breaking at the breakpoints set but you are getting "Source not found" error.
Follow the below steps to fix this:
Go to your debug configuration
In the Main tab, make sure you have "Resolve Workspace artifacts" checked
Make sure the Base Directory is set as your maven project
In the Source tab, make sure you have added your project as a "Java Project" or "Workspace" or "Project"
Step 4 is important, Add -> Java Project/Project and select your project

Eclipse "Waiting for virtual machine to exit"

I'm working on a blackberry project using eclipse and bb-ant tools. I've created a build.xml file to perform the build. Everytime I try to run an Ant build, eclipse pops up the progress dialog and it hangs stating "Waiting for virtual machine to exit."
I downloaded an open source Blackberry project that has an ant build and it is showing the same behavior.
Does anyone have any suggestions?
Edit:
I used the command line to build my xml file and it built fine. However, when I tried from Eclipse it still hangs.
I've tried both the standard eclipse plugin directory and the path I downloaded ant to.
You could check if your ANT_HOME settings are correct (see also this blog post).
"Window > Preference > Ant > Runtime": "Ant Home Entries".
if the jars files are from a plugin directory (beside the default 'org.apache.ant_1.7.1.v20090120-1145' one) and not an independent ant installation, that might explain the problem.
Try clicking the "Ant Home" button on the right side and setting up ant home such as "C:\path\to\apache-ant-1.7.0"
There are similar bugs to this kind of situation (bug 173419, ticket 91).
It is worth checking the JVM used for the project.
It can also occurs when a ant task is poorly implemented.
You had the problem because the java version ant tries to run with is incorrect.
By default, eclipse will try to run the ant build with the java version it uses to compile the java files (Blackberry JRE), which won't work! You need to change the jre version by choosing "Run As... > Ant build". Before clicking run, go to the JRE tab, choose "Separate JRE:" and change "Blackberry JRE " to a standard java JRE. Press the run button and everything should work correctly.
I hit this problem also. Although I never used the same solution, you pointed me in the same direction.
I was using a ant file as a builder in my project, and I disabled the Allocate Console build option. This is when I hit the 'Waiting for virtual machine to exit'.
So I simply enabled the Launch in background option and it worked.

How can I add my application to Tomcat in Eclipse?

I have a web app built with Maven.
Most of the time, I built the application using Intellij IDEA, but now I want to import the application in Eclipse to see something in this IDE.
After mvn eclipse:eclipse, I add in Eclipse the app, but when I try to add the app to the server (tomcat), I receive:
There are no resources that can be added or removed from the server
Solutions?
You need the project to have a Eclipse Dynamic Web Module facet. You can try doing this via the project properties dialog and looking at project facets, then clicking the appropriate check box. This may not be available however, so you may need to do the next thing.
Create a backup of your project and follow the directions at dzone.com. This'll allow you to modify the project facets via your eclipse .project file.
Keep in mind, once you add those facets, you cannot change them back via Eclipse. Definitely make sure you have a backup before starting.
This step worked for me:
Right-Click on the Project Name, then
Maven-->Update Project..
Click OK
After doing this I was able to see my project in Add/Remove Programs.
As mentioned somewhere else adding Eclipse WTP didn't do any good, however I performed the above step after I had already added Eclipse WTP, so I am guessing that may not be needed.
This was done for Eclipse Juno.
Hope this helps someone.
Edited: You can follow this link as above mentioned I think might have needed WTP and that add a lot of other things into the workspace.
http://blog.teamextension.com/maven-as-eclipse-dynamic-web-module-556
Check whether Maven Integration for Eclipse WTP is installed. If not, install it from Eclipse Marketplace
After installation restart Eclipse
Right click your project and Maven--> update project configuration
Delete tomcat and re create tomcat (clean tomcat,add your project,publish and enjoy)
I've got Tomcat 6, Java 1.6, and was trying to get it to work in Eclipse Juno Service Release 1's "internal server" (whatever that's called.) Here's what I did that worked for me:
(Found these instructions at http://www.mkyong.com/eclipse/eclipse-ide-tomcat-version-6-0-only-supports-j2ee-1-2-1-3-1-4-and-java-ee-5-web-modules/)
I should point out that I followed ClutchDude's instructions to make my project a Dynamic Web Module facet. It didn't work on its own for me, but maybe it was part of making it work in the end.
Using Eclipse (or other text editor), open the file
.settings/org.eclipse.wst.common.project.facet.core.xml
Find the line that reads
<installed facet="jst.web" version="3.0"/>
3.0 is for Tomcat 7.x (so says mkyong.) Change it to 2.5 (or 2.4).
I restarted Eclipse and it worked for my project.
The reason why this is happening is because eclipse by default looks for the deployment descriptor in the folder {project.home}/Webcontent/WEB-INF/web.xml where as the Maven puts them in src/main/webapp/WEB-INF/web.xml.
So when you are trying to add your project onto the server eclipse cannot find a deployment descriptor and hence you get the annoying message.
This can be solved by adding the following entries in .settings/org.eclipse.wst.common which can be found in
Project home folder in your workspace if it is a new maven project.
The folder where you already imported from if you are using Import -> Maven projects.
Make the following changes in to the org.eclipse.wst.common
wb-resource deploy-path="/" source-path="/src/main/webapp"/. Add this entry.
Edit --> property name="java-output-path"
Please check the following link from more details. http://java.dzone.com/articles/webapps-eclipse-and-maven.
The comments section has an excellent example with a working project.
This issue was fixed for me my installing additional eclipse modules. in particular, the ones related to m2e-wtp. just do a search for m2e in the plugins search listing for your version of eclipse
If you face an error like "There are no resources that can be added or removed from the server",
then
1) Go to the META_INF of your websvcsEAR and go to the application.xml.
2) Goto modules-> clickDetails and add the module that is existing. i.e., some EAR which your project demands.
3) Click ok
4) Now go to your server -> right click -> add and remove -> add your EAR.
Maybe you don't need add your application to the server's configuration. I think that you must use m2e eclipse plugin in order to launch the app.
For example, in your eclipse you will see a contextual menu called "Run as" if you right-click on your pom file. You can clicking on "Maven build" and Maven will download all the information needed to start tomcat.
I hope this helps you.
I used
mvn eclipse:eclipse -Dwtpversion=2.0
in command line in the folder where I had my pom.xml. Then I refreshed the project in eclipse IDE. After that I was able to add my project.
I was able to resolve this by removing my EAR project from my Eclipse workspace, then re-importing it.
Well, with a Spring and maven project, i got it that way:
Eclipse Version: 2019-06 (4.12.0)
Java 1.8
Tomcat 7
Yes, go to Project Properties >> Facets >> select Dynamic Web Module but dont apply yet!!!
Right under, it should appear a link Further Configuration Available. Click on it, otherwise one will have to edit .settings/org.eclipse.wst.common.component manually. Update source directory to src/main/java. (source)
Then in Facets window check Java - mine was pointing to 11 even though i don't have Java 11 installed or configured like a JRE runtime. I could only add/remove when changed to 1.8. (source). Note: That was really the problem, why don't Eclipse get this configuration automatically from the project?
Finally Eclipse creates some directories like WEB-INF and META-INF, just delete them.

Ant build scripts totally hangs, with no messages in console

I have build.xml for my project, but even this small piece of code
<target name="init">
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>
It doesn't run
Console is empty but process is active. I still can terminate it over STOP button
In same time I cannot debug it as well, same stuff active process no output in console and I can wait forever! Any ideas?
JDK 1.6.0_14
Eclipse 3.5.1
Edited: Thank to Peter's Loron question I checked workspace log file MyWorkspace/.metadata/.log
There I saw error message I googled it and found that this happening because location of my Eclipse changed, but path to ANT jars remains old.
TO Fix that you have to go Preferences->Ant->Runtime and click Restore Default it will pickup new jar location and warn you about absence of tools.jar, copy it from somewhere and drop it in same folder where other ant jars.
Edited: Thank to Peter's Loron question I checked workspace log file MyWorkspace/.metadata/.log There I saw error message I googled it and found that this happening because location of my Eclipse changed, but path to ANT jars remains old.
TO Fix that you have to go Preferences->Ant->Runtime and click Restore Default it will pickup new jar location and warn you about absence of tools.jar, copy it from somewhere and drop it in same folder where other ant jars.
Here is yet another possible fix:
Go to Preferences->Ant->Runtime
Classpath tab
Click Restore Defaults button.
That happened to fix the issue for me.
I'm using IBM RAD7 (which is based on Eclipse) and I was having exactly the same problem. After much fiddling I went to "External Tools" | JRE Tab | select "Run in same JRE", mine was set yo use the Webpshere JRE. Took a day to fix it! Nigel
Another quick thing to look for... Check your VM memory specs... I was messing around with low memory settings and it caused the same issues as above...
If you are running the script using "External Tools Configuration" you should also check the following:
Open "External Tools Configuration" and select the launcher that starts the Ant script. In the tab "Common" make sure that "Allocate console (necessary for input)" is checked!
In my case it was not checked and was the reason why no console output was visible.

Ant build consoles get clobbered by dependent projects in Eclipse

I have a set of dependent projects in Eclipse, each with its own Ant build script. If I make a change in multiple projects, then select "Build All" (Ctrl+B), each Ant build is invoked in the correct order. But if there is an error in one project, Eclipse still tries to build the other projects also, and in the process clobbers the Ant console so that the build errors are no longer visible. This wouldn't be quite so annoying if I could open up the offending project and select "Build Project", but Eclipse out-smarts me: it won't rebuild until I open some file in the project, edit it, and save (typically I add and remove a space character wherever my cursor happens to be). An answer to any of the following questions would be welcome.
How can I configure Eclipse to (in preference order):
terminate a "Build All" as soon as any project's Ant build fails?
save all console output for "Build All" instead of resetting the console for each project?
spawn a separate console for each new instance of Ant?
allow me to force a "Build Project" even if it doesn't think anything has changed?
[UPDATE] Bonus Question:
How can I configure Eclipse so that fixing any build errors in a depended-on project counts as a "change" for the purposes of "Build Project"?
Have you tried redirecting standard out to file via a run configuration? A few screen shots to help if not... (you may try 'append' this is not in my screen shot :) )
One alternative is to have each Ant build log itself, e.g., using the following in build.xml
<record name="build.log"
loglevel="verbose"
append="false" />
Oddly, Eclipse seems to disable this logging somehow when running an Ant build.
I am not too big on ant, but can't you make the builds dependent on one another?