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
Related
I have a project which I can build and deploy correctly using Ant
I want to build a war file to deploy the project.
I can get everything working except I cannot get the properties file to appear in the classes directory.
My properties file is located here: /h/a/A/I/S/src/Serv/log4j.properties
This is the war section of my build file:
<war destfile="Int.war" webxml="web/WEB-INF/web.xml">
<lib dir="${libDir}" />
<classes dir="${outputDir}" includes="/h/a/A/I/S/src/Serv/log4j.properties"/>
<classes dir="${outputDir}" />
</war>
I have read the previously asked similar questions here and added the second classes element here which includes the properties file but it did'nt worked for me, any suggestions
In this line, path of .properties file will be assumed by ant as "${outputDir}/h/a/A/I/S/src/Serv/log4j.properties" which is an invalid path in your project..
Try using copy task for moving .properties file to '${outputDir}' directory and then perform war packaging.
I'm trying to generate a war using an Ant script, but it seems that it won't run on jboss. Anyone knows the diference between this and create a war using Eclipse(File ->Export -> War)?
<war warfile="${docflow4-web-home}/deploy/${nome}.war" webxml="web/WEB-INF/web.xml">
<fileset dir="${docflow4-web-home}/web">
</fileset>
</war>
In Eclipse, optionally, there is a supply WAR export Options, such as whether or not to include Java™ source files in the WAR, and whether to overwrite any existing resources during the export process. Source files are not usually included in a WAR file, because they are not necessary for the server to run the web application. Otherwise, everything is similar to ant script.
In Ant script, your script seems alright, but it is aways nice using the tag , for example: <classes dir="${classes.dir}" /> because it defines a grouping to specify what goes into the WEB-INF\classes folder.
If you are using some third part jar, use the tag lib too, example:
<lib dir="thirdpartyjars">
<exclude name="portlet.jar"/>
</lib>
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?
How do you add a folder (e.g. a resource folder containing arts) to the classpath of a netbeans project? I managed to do that manually via editing the NB generated jar file of the project (that is its MANIFEST.MF file + copying the resources manually), but there should be a way to tell netbeans as well to mind the resources, no?
The folder structure looks like this:
/project/art/
/project/dist/lib/
/project/dist/art/
/project/dist/project.jar
/project/lib/
/project/src/
I don't want to package the art into the jar because I'd like the art to be easily exchangeable. If I add the art folder to the src folder then NB compiles fine, but the art resources end up in the jar.
Adding the art folder to the netbeans project libraries (Properties -> Libraries -> Add JAR/Folder) seemed not to work, because then I ended up with an error '...\project\art is a directory or can't be read. Not copying the libraries.' which in turn prevents even the real libraries folder from being copied.
Any ideas?
Best regards
Chris
2 Observations made, based on the comments from gpeche:
a) Rather specifying the additional resources folder in the "Run" tab than in the "Compile" tab of the project properties -> Libraries doesn't seem to make a lot of difference in Netbeans (I'm currently using 6.9.1). The output (and thus error) stays the same, that is nothing gets copied at all:
Created dir: C:\Users\Chrisi\Desktop\vocabulary\VocabularyTrainer\dist
C:\Users\Chrisi\Desktop\vocabulary\VocabularyTrainer\art is a directory or can't be read. Not copying the libraries.
Not copying the libraries.
Building jar: C:\Users\Chrisi\Desktop\vocabulary\VocabularyTrainer\dist\VocabularyTrainer.jar
Another interesting aspect is that in the help menu of the Libraries panel nothing is explicitly mentioned regarding folders as libraries. Could it be possible, that the button in Netbeans is falsely named, that is only real jar's are allowed?
b) Adding the resources folder to the Libraries list does have the impact though, to add another entry to the MANIFEST.MF. While - and that's the smaller issue - the classpath entry seems to be always expecting the resource folder to be a subfolder of the library folder (e.g. "lib/arts") the major problem is that there seems to be a slash missing.
As mentioned the NB generated entry in the MANIFEST.MF will look like this "lib/arts" (which does not work for me), while (manually set) "lib/arts/" does?!
The way I use resources from the folder is something like this:
URL resource = getClass().getResource("/gui/refresh.png");
ImageIcon tmp = new ImageIcon(resource);
Edit:
Based on Tushars comment and this posting I found the following solution to be an acceptable tradeoff between functionality and comfort.
I override the ANT target from the auto generated 'build-impl.xml' file which creates the Class-Path in the MANIFEST.MF file in the basic 'build.xml' file of the Netbeans project. The code which goes to the 'build.xml' file looks like this:
<property name="art.classpath" value="art/" />
<target name="-post-jar">
<mkdir dir="${dist.dir}/art"/>
<copy todir="${dist.dir}/art">
<fileset dir="${basedir}/art">
<!-- <exclude name="**/!source/**"/> if you want to exclude something... -->
</fileset>
</copy>
</target>
<target name="-init-macrodef-copylibs">
<macrodef name="copylibs" uri="http://www.netbeans.org/ns/j2se-project/3">
<element name="customize" optional="true"/>
<sequential>
<property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
<pathconvert property="run.classpath.without.build.classes.dir">
<path path="${run.classpath}"/>
<map from="${build.classes.dir.resolved}" to=""/>
</pathconvert>
<pathconvert pathsep=" " property="jar.classpath">
<path path="${run.classpath.without.build.classes.dir}"/>
<chainedmapper>
<flattenmapper/>
<globmapper from="*" to="lib/*"/>
</chainedmapper>
</pathconvert>
<taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" classpath="${libs.CopyLibs.classpath}" name="copylibs"/>
<copylibs compress="${jar.compress}" index="${jar.index}" jarfile="${dist.jar}" manifest="${manifest.file}" runtimeclasspath="${run.classpath.without.build.classes.dir}">
<fileset dir="${build.classes.dir}"/>
<manifest>
<attribute name="Class-Path" value="${jar.classpath} ${art.classpath}"/>
<customize/>
</manifest>
</copylibs>
</sequential>
</macrodef>
</target>
The tradeoff is that for development in Netbeans I still have to add the resource folder (e.g. 'art') to the libraries list to make the project run in Netbeans. This will cause an additional entry in the MANIFEST.MF file ('lib/art') along with the effect that the libraries will not get automatically copied to the 'dist' folder, with the message
...\art is a directory or can't be read. Not copying the libraries.
Not copying the libraries.
This behavor is - afaik - intended (to force everything to be bundled up in a jar), even though there are discussions about it going on. To make a real distribution bundle I'd have to take away the resource folder(s) from the library list in NB and rebuild.
Ideas about a more streamlined setup without any tradeoffs are of course still welcome. :)
Adding resource folder to classpath:
When you Clean-&-Build a NetBeans Ant Based Project it creates a manifest.mf file in the root directory of the project. This file gets included in the JAR file also. Modify this file and add entry like follows:
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
Class-Path: arts/
slash is important after arts in the class path.
Including the arts resource folder in the distribution
Either copy this folder in the dist folder after the build or add a ANT target to copy the required resources in the dist folder.
Add the target like as follows in the build.xml file:
<target name="-post-jar">
<mkdir dir="${dist.dir}/resources"/>
<copy todir="${dist.dir}/resources">
<fileset dir="${basedir}/resources" />
</copy>
</target>
Code to access such resources:
The code needed to access such resource files shall be as follows: (This will not work in design time but surely from the JAR file)
// pay attention to relative path
URL resource = ClassLoader.getSystemResource("gui/refresh.png");
ImageIcon tmp = new ImageIcon(resource);
NOTE: The files manifest.mf and build.xml located in the root directory of the project are accessible from the Files Panel in NetBeans IDE
Using NetBeans 8.0.2:
Right-click the project.
Select Properties.
Select Sources.
Click Add Folder for the Source Package Folders.
Select the the directory where the resources exist.
Click Open on the directory name.
Click OK to close the Project Properties dialog.
The resources are added to the project.
You'll see the directory added in your Navigation pane as well
In the other project, the resources are now available. For example, to read an image:
BufferedImage zero = ImageIO.read(OCR.class.getResourceAsStream("/0.bmp"));
In order to remove the lib/art from Class-Path and not get "is a directory or can't be read" need delete lib/art from path:
<pathconvert property="run.classpath.without.build.classes.dir">
<path path="${run.classpath}"/>
<map from="${build.classes.dir.resolved}" to=""/>
**<map from="${basedir}/art" to=""/> <!-- remove art from lib -->**
</pathconvert>
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.