Apache Ant - Installing Maven Ant Tasks - eclipse

This is for running files as Ant builds in Eclipse. I have my Ant set up, now I need to install the Maven Ant Tasks. I followed the instructions on the Maven website: downloaded the JAR and put it in my .ant/lib, and double checked that my environment variables were correct. When I try to run as an Ant build in Eclipse, however, it gives me this error:
No types or tasks have been defined in this namespace yet
This appears to be an antlib declaration.
Action: Check that the implementing library exists in one of:
-C:\Users\arempel\Documents\eclipse\eclipse\plugins\org.apache.ant_1.8.3.v201301120609\lib
-C:\Users\arempel\.ant\lib
-a directory added on the command line with the -lib argument
Now I know there are a ton of resolved questions like this that have been answered, but I've tried all of the solutions I could find to no avail. I've tried using -lib in prompt, tried setting the classpath variable, tried playing around with my environment variables, but I'm still screwing up somehow.
Does anyone know what I'm doing wrong, what I'm missing?

When running Ant within Eclipse, it is Eclipse itself which is managing the classpath of Ant.
Look into the global preferences of Eclipse, and then into the Ant/Runtime panel. The first tab, 'Classpath' is the one you want to modify. Click on the 'Global Entries' and then hit the button 'Add JARs...'. Select the jar of the Maven Ant Tasks and you're done.

Related

Force the use of an alternate POM file in eclipse

In my maven project I usually use the POM file named pom.xml. I have a second POM file though (call it pom_alt.xml), which I occasionally use to perform a very different build of the same project. To do so I specify the -f option in the command line
mvn clean package -fpom_alt.xml
as suggested by man mvn:
-f,--file
Force the use of an alternate POM file.
Now, when I am coding in eclipse I usually need maven to use pom.xml, but sometimes I should code or debug while the other file pom_alt.xml is used instead. Is there a way to tell the eclipse maven integration to use that file? Currently I am temporarily copy-pasting from pom_alt.xml to pom.xml since I seldom happen to need that, but you can see that's not optimal.
I am with Eclipse IDE for Java EE Developers, Mars Release 4.5.0.
UPDATE
I could build from the command line or use Run As Maven build as in
Carlos Andres' solution, but ideally I would like to define a persistent setting, like a property or preference. This because I find nice if the POM file can be fixed while I am doing things like running as Java Application and test cases, or executing on a server. Processes that require a project clean or server restart are often triggering a maven build with the default POM.
Check that M2E - Maven Integration for Eclipse is installed on Eclipse. Once that is installed go to the project and press right click
Next, put the command that you want to execute
This option allow you to save the commands, and the next time all your commands will be saved.
To execute the command recorded go to

Force Eclipse to clean a project automatically before every run

I'm looking for a solution that will force Eclipse to automatically clean a project before I run it (I'm talking about running a project using just Eclipse- no Maven, no Ant). For building I already have a Maven configuration, but sometimes I run the build directly from Eclipse as well and this is when I need that cleaning.
Shouldn't it be possible to have Maven and Eclipse use different class folders, e.g. /target for the Maven build and /bin for the Eclipse internal Java compiler? If so, you should be able to have 2 different launch configurations running the code from 2 different locations.
Second alternative: You can create a small Ant script to clear the target directory. That Ant script can be run from inside Eclipse, so a workaround is running the Ant launch configuration first and your Java launch configuration afterwards. To make this a one-step process, please install the launch groups feature from Eclipse CDT (you only need that small feature, not the whole CDT!), then you can create a "batch" like launch configuration from the other two launch configurations. Now everything is inside Eclipse with a single launch configuration!

finding what commands are executed by eclipse

I have a project in eclipse right now that is compiled using ant. I am wondering what eclipse is doing behind the curtains whenever I double click on the jar target of one of this build files.
Is it possible to get the commands that eclipse is executing with ant, as I'd like to setup a shell script that compiles the project. How can I find what commands it is actually executing and what parameters it is passing.
I imagine there are also some variables like classpath, and buildpath that are set, where do I find them as to be easily copied over.
Eclipse comes with its own installation of ant. Is it possible to use that bundled installation of ant to build via command line.
Any help appreciated,
Ted.
One possible way is to look at the process executed by Eclipse when building.
For that, use Process Explorer (if you are on Windows) in order to display the full command line and all its parameter when running that build.

eclipse ant integration and code formatting

I have configured Eclipse to use ant for doing the builds by setting the builders in project properties to point to the ant build script.
The build goes thru fine. However in my eclipse project I have not imported the required jars as a part of the project settings. All of this is done in ant's build.xml.
So in the java files, I get red squiglly lines for all the import packages which eclipse is not able to resolve.
How do I make these squiglly lines go away? One way is to import the required jars in eclipse, but then I am maintaining the project at two places, ant build.xml and eclipse
go to Project Properties/Build Path and enter the jars you rely on there.
You could use Ivy to manage your dependencies. If you configure it properly, you will only be defining the jars in one place but both Eclipse and Ant will be able to see them. The eclipse plug-in is IvyDE.

Refresh an Eclipse project with Ant

We have some Ant script fosr building the different jars we use, in several Eclipse projects. There is some interdependency
At the end of the build, we have to refresh some of the Eclipse projects in order to make the build path valid. Without this, it doesn't see one of the just-built jars and Eclipse throws a build path error.
There is a way to avoid the manual refresh step?
Try this:
<eclipse.refreshLocal resource="project_name/folder_name" depth="infinite" />
There are option details at the Eclipse help system.
Important: you have to choose "Run in the same JRE as workspace" at the Ant run configuration.
You may want to turn on "Refresh Automatically".
See Window->Preferences->General->Workspace->Refresh Automatically
and it'll monitor filesystem changes for you.
If you're running the ant script from within eclipse you can right-click on it and select "Run As >" then "Ant Build...". There's a 'Refresh' panel in the options to run the script which you can choose to refresh various things after the script completes.
This might not be answering your question exactly but I don't quite understand what is causing the problem.
As I understand it you have a project A that creates a jar file and that jar file is referenced by project B. When you re-build project A, you need to refresh so that project B can see the new jar file. Is that correct?
I do something similar but I don't get any build path errors because the name of the project A jar file hasn't changed.
Another option is for Project B to reference Project A directly instead of referencing its jar file.
I think I may have misunderstood the problem you are having but I hope this helps anyway.
it can be done by following Ant tasks provided by the Eclipse platform.
<eclipse.refreshLocal resource="MyProject/MyFolder" depth="infinite"/>
Note: make sure to run Ant inside the same VM where Eclipse workspace is running, for details check following links
Problem: failed to create task or type eclipse.refreshLocal
Ant tasks provided by the Eclipse platform