Netbeans, Ant and nesting build directories - java

I am having a problem with an Ant project in Netbeans 7.4 . When building a certain web app that i had to create via importing it from a WAR into Netbeans it keeps nesting the output directories in the build directory deeper and deeper.
It happens during the Ant target -copy-webdir . It outputs "x.class omitted as pathtox/x.class" for every file in the build/web directory and creates an even deeper nested set of directories on each build.
Here is a small extract from the project.properties file:
build.classes.dir=${build.web.dir}/WEB-INF/classes
build.classes.excludes=**/*.java,**/*.form
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
build.web.dir=${build.dir}/web
build.web.excludes=${build.classes.excludes}
target -copy-webdir in the nbproject/build-impl.xml:
<target name="-copy-webdir">
<copy todir="${build.web.dir}">
<fileset dir="${web.docbase.dir}" excludes="${build.web.excludes},${excludes}" includes="${includes}"/>
</copy>
<copy todir="${build.web.dir}/WEB-INF">
<fileset dir="${webinf.dir}" excludes="${build.web.excludes}"/>
</copy>
</target>
What am i doing wrong here?

Related

Building a project and creating a war in different Environments using Ant

am working on an ant build script which builds and deploys the project, and stages the code to the staging environments, ie creates a war file in the staging environments. For example the staging environments in my case are as follows: Am giving these properties in the build.properties file.
Env1_Deploy
Env2_Deploy
Env3_Deploy
Env4_Deploy
Env5_Deploy
PROD_DEPLOY
If you notice the case, all the Env..... are in mixed case where as in PROD_DEPLOY is in upper case.
The way my ant script works is when I select the build.xml-->runas-->AntScript, It prompts a dialogue box where it asks me to select the environment to build. Then I can select one among the above and then it creates the war file in the selected env.
The issue am having is when I select the PROD_DEPLOY, it is creating a new folder PROD_DEPLOY_Deploy and then creating the war files there. Below is the build.properties file and the build.xml file , any help is appreciated.
******build.properties file*********
deploy.folder.suffix =_Deploy
deploy.folder.prod.suffix =_DEPLOY
*************War Task**********************
<war destfile="${selected.env}${deploy.folder.suffix}/${project.name}.war" needxmlfile="false">
<fileset dir="${webroot.dir}">
<include name="**/*.*"/>
</fileset>
<lib dir="${temp.dir}">
</lib>
<classes dir="${build.dir}"/>
</war>
Am not sure how to include the deploy.folder.prod.suffix if I want to select PROD_DEPLOY and create the war in PROD_DEPLOY

Build the java project using build.xml in Netbeans

When I try to do Clean and Build project in Netbeans for the project Jsignpdf I get below error. But If I debug the project it runs without error as I have included all the required libraries. I have limited knowledge of java and it is the first project I am trying to build.
ant -f "C:\\Documents and Settings\\user\\My Documents\\NetBeansProjects\\jsignpdf-master" clean jar
clean:
Cleaning build
C:\Documents and Settings\user\My Documents\NetBeansProjects\jsignpdf-master\build.xml:47: The following error occurred while executing this line:
C:\Documents and Settings\user\My Documents\NetBeansProjects\jsignpdf-itxt\src\build.xml:10: taskdef class net.sourceforge.jarbundler.JarBundler cannot be found
using the classloader AntClassLoader[]
BUILD FAILED (total time: 0 seconds)
As seen in this error message i clicked on the first build.xml link and it was pointing out below portion(target name="clean")
<target name="clean">
<echo message="Cleaning build" />
<delete dir="${build.dir}"/>
<delete dir="${dist.dir}"/>
<delete dir="${output.dir}"/>
<ant antfile="../jsignpdf-itxt/src/build.xml" useNativeBasedir="true" target="clean" />
</target>
When i clicked on second build.xml link mentioned in error i got below portion of xml highlighted.
<taskdef name="jarbundler" classname="net.sourceforge.jarbundler.JarBundler">
<classpath>
<pathelement location="${jarbundler.jar}"/>
</classpath>
</taskdef>
Actually i was getting lot of errors and solved them. There was also error like JarBundler not found.then I downloaded it from this link.It had .java files,not class files. So I created a package as relevant like net.sourceforge.jarbundler and placed the files which required. After doing all these I am still getting errors while building as described above. I googled a lot for building java app, build xml, ants etc etc and not able to resolve the errors after from last two days. Now my only hope is to some one help me on this error.For more information please download the project.

Using ant to create a distributable zip file with JAR and libraries and doc

I have a library that is typically distributed by making a zip file of the JAR and its dependencies and its javadoc by hand. I would like to automate this task in ant.
One quirk for the intended use case for this distribution is that when it is unpacked, the JAR my team has created and any library JARs should all be in the same path. We cannot have myproject.zip/the.jar and myproject.zip/lib/a_library.jar both should be in the root path of the zip.
I have had much success using the following task:
<target name="myproject.distributable" depends="artifact.mycompany_myproject, myproject.javadoc"
description="Build the distributable JAR for myproject">
<zip destfile="${basedir}/dist/myproject.zip">
<fileset file="${temp.jar.path.mycompany_myproject.jar}"/>
<zipfileset dir="mycompany_myproject/lib" prefix="lib">
<patternset id="myproject.dist.libs">
<include name ="**/*.jar"/>
</patternset>
</zipfileset>
<zipfileset dir="docs/myproject" prefix="docs"/>
</zip>
</target>
The only thing it doesn't do is 'flatten' or move the library JARs to the root path of the zip.
I have tried using <zipfileset prefix="/"> for the libs but that did not work as expected.
The prefix attribute of the zipfileset is used to describe where the files should appear in the created zip file. Since you want the jar files to appear at the root of the zip file you don't need to specify this, and can leave it out (I'm not sure what the effect of setting it to "/" will be, I think it'll be safer to omit it).
You problem seems to be that your libs are stored in subdirectories under your lib dir, but you want them to be directly in the root of the zip file. The 'zip' task, unlike the copy task, doesn't accept a mapper directly to change how files should appear in the zip, but if you're using ant 1.7 or later it will accept a resource collection. You can use a mappedresources element with a fileset and a flattenmapper to get the effect you're after:
<target name="myproject.distributable" depends="artifact.mycompany_myproject, myproject.javadoc" description="Build the distributable JAR for myproject">
<zip destfile="${basedir}/dist/myproject.zip">
<fileset file="${temp.jar.path.mycompany_myproject.jar}"/>
<mappedresources>
<fileset dir="mycompany_myproject/lib" includes="**/*.jar" />
<flattenmapper />
</mappedresources>
<zipfileset dir="docs/myproject" prefix="docs"/>
</zip>
</target>
This means you don't have to use copy first to put the jars into a staging area.
According to this post the zipgroupfileset should do the trick; have not tried it myself though...

How to distribute junit tests to another machine

The build.xml we have today have many targets to compile and run unit tests. The build.xml refers to many property files with relative to itself. All this works fine when build and test is done on same machine.
It is pretty simple to do build get all jars and any test input files to a build_home(another machine). How to run junit on the new location? Should I create small build.xml files to running the tests? (There is no way to create ant build.xml dynamically) Any solutions?
( GridGain is possible solution. Not tried yet. )
Edit: Mode details on why this more complicated: The source code is around 3G, doing clearcase update and build takes considerable time (40 minute) against real test time of junit testing - 60 minutes. We have many machines to run the tests -- loading Clearcase on all systems not possible.
I understand your question as you want to only run the Junit tests on another machine without actually building on it? You can run something on the lines below as build scripts from Cruise control and probably Hudson too
If you're using the task via ant, then follow the same principles as a standard build. You can check out the code to all target machines from source control.
Externalize all root directories to a build.properties. These are properties which have to be set on each machine like so.
#Overall Project Name
project.name=myapp
# Top Level Root directory of the new working project
toplevel.project.dir=D:/proj/eComm
# Root directory of the source code
root.project.dir=D:/proj/eComm/Construction
# JDK home directory
jdk.home=C:/jdk1.5.0_11
build.properties will also have some static properties defined relative to the above. These need not be changed by any user on any local machine.
ear.dist.dir = ${root.project.dir}/target
src.dir = ${root.project.dir}/src
test.src.dir = ${root.project.dir}/test
Ensure your build.xml only refers to any further sub directories via these properties without any hardcoded values in it.
My junit are in a separate file which is imported into the build.xml by
<import file="${root.project.dir.buildscripts.dir}/junit.xml"/>
and some part of junit.xml is shown below
<target name="run.junit" depends="clean.junit, junit.info, prepare.junit"
description="Compiles and runs all JUnit Tests in the 'test' directory and produces a report of all failures">
<junit printsummary="yes" fork="true" haltonfailure="no" showoutput="yes" maxmemory="512m">
<jvmarg line="${junit.jvm.arg}"/>
<classpath>
<fileset dir="${src.dir}">
<include name="**/*.*"/>
</fileset>
<fileset dir="${ear.dist.dir}/build/classes">
<include name="**/*.*"/>
</fileset>
<pathelement path="${test.run.path}"/>
</classpath>
<formatter type="xml"/>
<batchtest fork="true" todir="${ear.dist.dir}/build/junit">
<fileset dir="${test.src.dir}" includes="${test.pattern.include}"/>
</batchtest>
</junit>
</target>
Try Cruise Control. It's a great way to offload your build and unit test to another machine.

How can I include data text files in a jar using Ant?

In my src folder there is another folder called data which contains files data1.txt and data2.txt. The application loads a graph from these files in the initialization, so I want to include these files in my final jar. I use Ant to produce the jar file.
Example from http://ant.apache.org/manual/Tasks/jar.html :
<jar destfile="${dist}/lib/app.jar">
<fileset dir="${build}/classes"/>
<fileset dir="${src}/resources"/>
</jar>
So basically you would want to include the data-files in the same way as "resources" are included above.
From the documentation of the <jar> task:
It is possible to refine the set of files that are being jarred. This can be done with the includes, includesfile, excludes, excludesfile and defaultexcludes attributes.
Copy the files to your classes directory, where they will be included into the jar.
enter code here
<target name="copyHibernateXml">
<copy todir="classes">
<fileset dir="${basedir}/${sourceDir}" includes="*.xml,*.csv"/>
</copy>
</target>

Categories