eclipse several ant build file - eclipse

currently I'm developing in eclipse 3.5 in different project web applications for tomcat 6.0.24.
For each of this project I have written a ant build file to generate the war file to deploy the project to the tomcat container.
So I have to run for each project the ant build file (a lot of clicks, and a waste of time).
Question: Is there a possibility to run all needed ant build files with a single click, from a single project or whatever?

#thelost
thank you very much for your hint, you brought me on the right way,
I solved the problem:
<target name="build">
<ant antfile="jar-build.xml" target="GEN-JAR_FILES" />
<ant antfile="war-service01.xml" target="SVC01-WAR"/>
<ant antfile="war-service02.xml" target="SVC02-WAR"/>
</target>
best regards, Alex

Sure. E.g., you could create a master build file and use the Exec task.

Related

Eclipse: Automatically run Ant scripts in sequent order

I am using Eclipse's Ant view to run my build files. I have to run a couple of files in a specific order and I wonder whether there is any possibility to automate this (I'm sure there is...). However, they need to run subsequently, i.e. script two may not start until script one finished successfully. Most of my Ant scripts trigger Maven commands.
Is there any Eclipse plugin or feature that can assist me in running my Ant files automatically? Maybe even shutdown and restart my Java EE server before and after building?
I'd like to double-click just once and have my toolchain work, while I... get myself another cup of coffee.
I can think of two options:
Write a wrapper Ant script/target that calls the others in the desired order. It's been a number of years since I wrote any Ant but I remember doing that, probably using the <ant> task. It might make sense to simply define a target that has dependencies/prerequisites in the right sequence (in conjunction with the <import> task to pull in the separate buildfiles). Here is a discussion about the difference between these two approaches.
Use Eclipse's External Tool feature to invoke a batch/shell script that calls each Ant target.
This is what I finally came up with:
<project default="all" basedir=".." name="Build all projects">
<property name="folder.project.a" value="MyProjectA" />
<property name="folder.project.b" value="MyOtherProjectB" />
<!-- Target to build all projects -->
<target name="all" depends="projectA, projectB" />
<target name="projectA">
<echo>Building project A.</echo>
<ant antfile="${folder.project.a}/my_build_file.xml" />
</target>
<target name="projectB">
<echo>Building project B.</echo>
<ant antfile="${folder.project.b}/my_other_build_file.xml" />
</target>
</project>

How to run junit tests at build time in netbeans and jenkins?

I'm trying to set up a project to run junit tests at build time, so that every member of the team and the Jenkins build server runs the tests when it builds.
I believe we have set up a fairly standard webproject in Netbeans, but I can't seem to find anyone solving this problem on stackoverflow or google.
How would you go about doing this?
Go to file: /nbproject/build-impl.xml and fidn the dist target. It should look like this:
<target depends="init,compile,-pre-dist,do-dist,-post-dist" description="Build distribution (WAR)." name="dist"/>
Copy paste it into /build.xml, and add the "test" target into it:
<target depends="init,compile,test,-pre-dist,do-dist,-post-dist" description="Build distribution (WAR)." name="dist"/>
This was in Netbeans 7.3. It now builds and runs the tests on every build, also on the Jenkins build server.
Never modify your build-impl.xml! Netbeans regenerates this file when you perform any changes to your project.
The better approach would be to modify your build.xml and add a post-jar task:
<target name="-post-jar" depends="test"/>

Eclipse: Why is it eating my log4j.properties file?

Windows 7 Professional
Eclipse 3.7.2
I am migrating over to Eclipse from another IDE. I am compiling my project with the same ANT build.xml file I was using before. I do it by
highlighting my project in the project view
expanding the tree node
finding my build.xml file there
right clicking my build.xml file
choosing Run as > Ant Build
Works great, but every few builds Eclpise eats my log4j.properties file located at:
C:\AllProjects\Workspace\acme\war\WEB-INF\classes\log4j.properties
Eclipse basically eats all files in WEB-INF\classes that are not *.class files.
What am I doing to make this happen and how can I stop it?
Thanks
Since you're using ant instead of Eclipse to build, you could try turning off the setting to build the project automatically.
Select your project, then in the menu bar at the top of the screen, select Project and uncheck the Build Automatically option.
Edit: Second opinion
I would add an ant task to copy the log4j property file into your WEB-INF/classes folder every time you do a build. One nice advantage of this is that you can have a different property file for different build types (debug, release, etc.) and not worry about manually making changes to it. Also, this should make it easier to manage if you're using version control.
Copy your log4j.properties file to your source directory and add something like this to your ant build file:
<target name="copy-log4j-property-file">
<copy file="src/log4j.properties" todir="WEB-INF/classes" />
</target>
<target name="build" depends="copy-log4j-property-file">
<!-- the rest of your build things here -->
</target>
After selecting in Project explorer:
Properties > Java Compiler > Building > Output Folder
Uncheck "Scrub output folders when cleaning projects"
It is a solution for me ( though maybe not everyone ) because I use a time test ANT build.xml to do my compiling, building and cleaning for me. I just leave Eclipse's auto builds on so I get those nice error notifications as a I type, before I compile.

Creating ANT script to deploy to glassfish, run junit tests and then un-deploy

Hey guys, I have a j2ee app which I am building with Netbeans. My task is to modify the build.xml so that after the app builds, ANT deploys the app to a server, runs Junit tasks on the app, and then un-deploys the app. So far I have the deploy and un-deploy working but I'm running into some trouble running the junit tasks.
I have a client project in Netbeans where my junit tasks lie. My trouble is that when this project is built, it doesn't compile my junit tests into the .jar. This causes problems when I run my ant junit tasks and ANT cannot find the appropriate .class files for the junit tests.
In the Netbeans Project Properties it allows me to set "Source Package Folders" and "Test Package Folders". If I add the "test" folder into the "Source Package Folders" and build the project it compiles the tests and includes them with the jar. This works, however it prevents me from running my junit tests as tests in netbeans which slows development.
Has anyone had any experience with solving such a problem? There may be a simple solution I am overlooking so if anyone has a word of advice I would appreciate it. Thanks in advance.
-Brad
If I understand what you're asking,
You shouldn't need to compile the test classes into the jar. Just compile them into some directory, say 'classes'. Then just include this directory in the fileset nested element for the junit task.
A simple example,
<target name="junit">
<junit printsummary="true">
<classpath>
<pathelement location="${classes.dir}"/>
</classpath>
<test name="test.class.TestClass"/>
</junit>
</target>
Had to point my junit task to the correct classpath. Was pointing to the exact directory of the .class files(project1/classes/com/blah/blah2/blah3) which is incorrect. Set classpath to project1/classes and it worked. Noob mistake.

Is there a quick way to export a WAR file in Eclipse 3.4?

I know about the export->war file
I would like something similar to the .jardesc that allows you to define the destination. So I could right-click on that .jardesc and do export. Except .wardesc instead of .jardesc :)
Is the war export functionality tied to an eclipse ant task?
I've put together an AHK macro so it will do the GUI motions for me... but that's a hack not a solution.
Is the war export functionality tied to an eclipse ant task?
As far as I know, yes. You might try searching for a plugin that can do this for you; I found a couple, such as the war-plugin builder, but I haven't tried it myself, as I try to avoid using extra plugins in eclipse.
Theres the Ant WAR task.
Eclipse has the notion of external commands. If you can write e.g. an ant script that does the export the way you like it you can start it from the menu/button. For ant scripts you can also pick the ant target you want to call and pass properties. This allows you to edit e.g. the path name in the Launch Configuration.
The right way to do "war export" is to use a build system (like Maven) and let it do the heavy lifting. All you need is a pom.xml with <packaging>war</packaging>.
Eclipse's exports are meant for occasional exports by humans, not for automation. And if you would really like to automate, do it right. You will benefit from other things, too. The same pom file will run on your machine, on other developers' machines and on your build server.
WAR ant task
http://ant.apache.org/manual/Tasks/war.html
from the documentation:
Assume the following structure in the project's base directory:
thirdparty/libs/jdbc1.jar
thirdparty/libs/jdbc2.jar
build/main/com/myco/myapp/Servlet.class
src/metadata/myapp.xml
src/html/myapp/index.html
src/jsp/myapp/front.jsp
src/graphics/images/gifs/small/logo.gif
src/graphics/images/gifs/large/logo.gif
then the war file myapp.war created with
<war destfile="myapp.war" webxml="src/metadata/myapp.xml">
<fileset dir="src/html/myapp"/>
<fileset dir="src/jsp/myapp"/>
<lib dir="thirdparty/libs">
<exclude name="jdbc1.jar"/>
</lib>
<classes dir="build/main"/>
<zipfileset dir="src/graphics/images/gifs"
prefix="images"/>
</war>
will consist of
WEB-INF/web.xml
WEB-INF/lib/jdbc2.jar
WEB-INF/classes/com/myco/myapp/Servlet.class
META-INF/MANIFEST.MF
index.html
front.jsp
images/small/logo.gif
images/large/logo.gif