Based on this topic: Netbeans and external configuration files
I assume that what I want to do this is possible. But the answer is not really working for me.
The code is use know is from the last answer:
<target name="-pre-jar">
<echo>Copying resources files to build directory...</echo>
<mkdir dir="${dist.jar.dir}/resources"/>
<copy todir="${dist.jar.dir}/resources">
<fileset dir="resources" includes="**"/>
</copy>
</target>
But this just creates a dir named: ${dist.jar.dir} with my resources folder and files in it at the same location of my src,dist,build,nbproject folder. But I want it to be in dist, so my dist has, the jar, lib,webfiles and resources.
Thanks for any help and clarification.
If you want to copy all the contents of a specific directory to the \dist directory of the build you can do the following:
<target name="-pre-init">
<!-- Create a resource directory property -->
<property name="src.res.dir" value="${basedir}/res" />
</target>
<target name="-pre-jar">
<!-- Copy external resources folder -->
<copy todir="${build.classes.dir}\inside\res\dir">
<fileset dir="${src.res.dir}\inside\res\dir">
<include name="**/*" />
</fileset>
<copy>
</target>
This will copy the contents of a folder called \inside\res\dir inside of your projects $\res directory. I use this technique to include an application icon in the distribution.
You should then be able to access these resources from inside your application with something like the following:
ClassLoader.getSystemResource("inside/res/dir/file.ext")
Okay I solved it, so to copy a file, I placed the file in in a folder within src named resources with in there my file.
And then the following code does the trick:
<target name="-post-jar">
<copy file="${src.dir}/resources/filename.extension" flatten="true" todir="${dist.dir}/resources" />
</target>
Okay, for some reason my jar isn't being builded/updated any more if I use this in my build file..Anyone any clues?
solved needs to be "-post-jfx-jar" for jfx projects
Related
I'm working on apache freemarker with jersey, we are gaving .ftl templates in template folder, when i trying to create a war file with template its not creating.
<target name="war" depends="clean,compile,copy-resources">
<war destfile="${dist}/sample.war" webxml="WEB-INF/web.xml">
<fileset dir="WebContent"/>
<webinf dir="WEB-INF" includes="**/log4j.properties"></webinf>
<lib dir="${lib}"/>
<classes dir="${build}"/>
<templates dir="${templates}"/>
</war>
</target>
When build this code it is saying
war doesn't support the nested "templates" element.
class and lib folder is adding but template folder not created in war file.
Thanks,
Praveen R.
Take a look at the war Task, and see the example in that page.
However you should use zipfileset to include your .ftl files in the war, here is how it should look like:
<zipfileset dir="${home.dir}/PATH_TO_FTL" includes="**/*.ftl" />
To create and copy the template folder use below code
<copy todir="${templates}">
To add this folder to war file use this code
<webinf dir="WEB-INF" includes="**/log4j.properties,templates/"></webinf>
This solved my problem.
I am using ant to build my application with timestamp. It is running currently. Now i want to get the latest updated folder so that i can copy that to any other folder.
I tried and it is printing me the latest file only but its not copying that file to another folder.
Please help me
<tstamp>
<format property="timestamp" pattern="dd-MMM-yy" locale="en,UK"/>
</tstamp>
<timestampselector property="latest.modified">
<path>
<fileset dir="${Engine.stagging.dir}">
</fileset>
</path>
</timestampselector>
<copy todir="${prjHop.release.dir}" flatten="true" overwrite="true">
<fileset dir="${Engine.stagging.dir}">
<include name="${latest.modified}"/>
</fileset>
</copy>
Also tried this to copy
<copy todir="${prjHop.release.dir}">
<path refid="${latest.modified}"/>
</copy>
<echo message="${latest.modified}" />
this echo is printing current folder and file name. I just want to copy the file inside that folder.
Thanks
The ${latest.modified} contains the absolute path of the file. When you use this path in the include nested element, the copy task will not find the file in the directory specified in ${Engine.stagging.dir} and hence will not copy it.
You can do the copy as follows:
<copy file="${latest.modified}" todir="${prjHop.release.dir}"/>
I am new to Java programming. I initially started with NetBeans but have moved to Eclipse given the advice from a friend.
In NetBeans, a pre-written ant build script for the project would generate a Project.jar file and place all required libraries/jars in a lib/ folder.
However, in Eclipse it appears that I need to write my own ant script. I have written a few lines to generate the jar file:
<target name="compile">
<mkdir dir="${build.dir}"/>
<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="jars" debug="on"/>
</target>
How do I write a command to copy all of the jars in my User Library to a ${build.dir}/lib/ folder?
Thanks.
Use the copy task
like so, with the appropriate include or exclude pattern
<copy todir="${build.dir}/lib/">
<fileset dir="src_dir">
<include name="**/*.jar"/>
</fileset>
</copy>
<copy todir="${build.dir}/lib/">
<fileset dir="src_dir" excludes="**/*.java"/>
</copy>
If you are new to Java take the chance to have a look at maven. It is a build tool like ant with a lot of predefined 'goals' and a fully developed dependency (to other libraries) handling. You will find a eclipse plugin which will be very useful.
Maven projects have a special directory layout which is kind of best practise and helpful for beginners. If you work on a maven project you can just use the command
mvn dependency:copy-dependencies
as a console command (or eclipse run configuration) to copy your project dependencies (libraries) to the <project>\target\dependency directory.
I recommend to use ant4eclipse library for ant based eclipse projects. When you use it, you can access eclipse workspace/project settings, and can iterate tought eclipse project class path in ant.
See the example code bellow:
<path id="ant.classpath">
<fileset dir="${lib.dir}/ant4eclipse">
<include name="*.jar" />
</fileset>
<taskdef resource="net/sf/antcontrib/antlib.xml" />
<taskdef resource="net/sf/ant4eclipse/antlib.xml" />
<targetPlatform
<target name="copy_jars">
<getEclipseClasspath workspace="${basedir}/.."
projectname="TestProject"
targetPlatformLocation="c:/eclipse"
property="classpath"
relative="false"
runtime="true"
pathseparator="#" />
<!-- iterate over all classpath entries -->
<foreach list="${classpath}" delimiter="#"
target="copy_jar_file" param="classpath.entry" />
</target>
<target name="copy_jar_file">
<!-- check if current is a .jar-file ... -->
<if>
<isfileselected file="${classpath.entry}">
<filename name="**/*.jar" />
</isfileselected>
<then>
<!-- copy the jar file to a destination directory -->
<copy file="${classpath.entry}" tofile="${dest.dir}"/>
</then>
</if>
</target>
If you would like to use user libraries, you can define it by userlibraries command.
I'm using ant to build my web-app. I'm sure this is simple but I can't figure out how to tell ant to create a specific folder in the WEB-INF directory and copy files to it.
My ant war task looks like this:
<target name="warItUp" depends="compile">
<war destfile="MyApp.war" webxml="${home.dir}\WEB-INF\web.xml">
<classes dir="${classes.dir}"/>
<classes file="${src.dir}/hibernate.cfg.xml"/>
<classes dir="${src.dir}" includes="**/*.hbm.xml"/>
<!-- Include the PDF files -->
<fileset dir="${home.dir}/PDFs">
<include name="**/*.pdf"/>
</fileset>
<!-- Include the JSP files -->
<fileset dir="${home.dir}/JSPs">
<include name="**/*.jsp"/>
</fileset>
<!-- Include the images -->
<fileset dir="${home.dir}/images">
<include name="**/*"/>
</fileset>
</war>
All the fileset elements work i.e. they include the pdf, jsp and image files in the root directory of the war file.
But if I want to create a sub-directory in the WEB-INF directory of the war file and include files in it how do I specify that? e.g. say I wanted to include WEB-INF/TagLibraryDescriptors/MyTagLib.tld in the war file or if I wanted to create a WEB-INF/JSP folder in my war file and copy all JSP files to it.
Thanks.
OP here, thanks for all the responses. I found another solution - there is a webinf element that can be included in the war task.
This will copy files from the source JSPs folder into the WEB-INF folder in the war file:
<webinf dir="${home.dir}/JSPs"
includes="**/*.jsp">
</webinf>
whereas this will copy files from the source JSPs folder into the WEB-INF/JSPs folder (my preferred choice):
<webinf dir="${home.dir}"
includes="/JSPs/**/*.jsp">
</webinf>
I think I'll stick with this solution but thanks for the responses.
As an alternative to the nested webinf element, you can also use the zipfileset element, which lets you specify the source folder and the path prefix in the archive:
<zipfileset dir="${home.dir}/JSPs" includes="**/*.jsp" prefix="WEB-INF/JSPs"/>
Try to create this directory into your project and then just add fileset like the following:
<fileset dir="${home.dir}/WEB-INF/mydirectory/*">
<include name="**/*"/>
</fileset>
Why not creating the dir structure you need the mkdir way?
In my build.xml, below works fine :-
<path id="build.classpath">
<fileset dir="lib [myUtils]" includes="*.jar" />
</path>
if lib [myUtils] is of folder type, but don't works, if it's of Linked Folder type.
Also, I found this when googled :-
https://bugs.eclipse.org/bugs/show_bug.cgi?id=265960
https://bugs.eclipse.org/bugs/show_bug.cgi?id=43081
https://bugs.eclipse.org/bugs/show_bug.cgi?id=265960
Is there any trick to achieve this, without copying the dependencies in work folder??
Note that ant should work outside of eclipse as well. So you can't reply in IDE abstractions. You can use symbolic links (if your OS supports them).
If not, you can use the FileSync plugin to synchronize eclipse project folders with external folders. Or you can simply use the <copy> ant task.
I resolved this using copy task:
<copy todir="target/web/linked1">
<fileset dir="../linkdProject/source1" />
</copy>
<copy todir="target/web/linked2">
<fileset dir="../linkedProject/source2" />
</copy>
....
<war destfile="target/webApp.war">
<fileset dir="WebContent" />
<fileset dir="target/web" /> <!-- copy linked resources -->
...
</war>
<delete dir="target"/>