I am trying to select all jars from the current directory. I am getting confused between:
**/*.jar
*.jar
I assumed *.jar will work the same as **/*.jar. However the following examples are working differently:
<path id="master-classpath-common-lib" >
<fileset dir=".">
<include name="**/*.jar"/>
</fileset>
</path>
<path id="master-classpath-common-lib" >
<fileset dir=".">
<include name="*.jar"/>
</fileset>
</path>
For this case *.jar is not working at all.
Can anyone please give some hint on this.
*.jar means all the .jar files in only within the base directory, the directory specified in <fileset dir="${master.classpath}/lib">. This will not include the files in the subdirectories.
In **/*.jar, ** (used as the directory name) is a special feature, that means all the (nested) subdirectories.
Check out an example with explanation here.
Related
So I'm extending my company's ant build script to add in a special module we want build in some cases. I've written an ant script that points to where I know the compiled class files for the rest of our codebase are, because they get compiled earlier in the build process. I know with 100% certainty the files are in this location.
However, whenever I try to compile this module, the classpath reference can't see those classes, and I get a bunch of "package does not exist" and "can't find symbol" errors.
I just can't seem to figure out what I'm doing wrong. Hoping for help here.
Here's my build script code:
<property name="classpath" value="${dir.dev}/out/production/Main"
<path id="pfClasspath">
<fileset dir="${classpath}">
<include name="**/*.class"/>
</fileset>
<fileset dir="${dir.dev.lib}">
<include name="**/*.jar" />
</fileset>
<fileset file="${lib.json}" /> <!-- TODO try removing this -->
</path>
<target name="compile" depends="prepare">
<javac source="1.7" classpathref="pfClasspath" srcdir="${dir.project}/src" destdir="${dir.project.build.classes}" />
</target>
The directory the "classpath" property is pointing at 100% contains all of the class files for the rest of the project. That level is the equivalent of the "src" directory on the sources side, immediately within it are the com/companyName/etc... folders.
My code contains references to the classes compiled at this location. Yet ant isn't finding them. Any help?
Try
<path id="pfClasspath">
<pathelement path="${classpath}" />
...
</path>
instead. Specifying the classpath does not mean to specify every single class file that's on the classpath, which is what you do when you define your <path> element using a <fileset>.
Pretty green to Ant here. I've been running into a problem of trying to get a .jar file to compile in my script (specifically the rt.jar). I've tried two different ways to fix this (most of which has been found on this site).
Here is how I am setting my path:
<path id="build.class.path">
<fileset dir="${jboss.home}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${jre.dir}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</path>
However, when I try to compile my files with javac using the fork attribute:
<javac fork="true" includeantruntime="true" debug="on" srcdir="${src.dir}" destdir="${temp.dir.classes}" includes="**/*">
<classpath refid="build.class.path" />
</javac>
I get the following error:
Alternatively, I tried running without the fork attribute and get this error:
Now I know that the file that is not being found is in the rt.jar. But it doesn't seem to want to pick it up. I've double checked all of my enviroment variables constantly; even making sure that my JAVA_HOME one isn't pointing to the jre.
Hopefully, I'm just making a newbie mistake but any help would be greatly appreciated.
EDIT:
I've been playing around and got older verisons of the JDK and Jboss (both ver 7 now). Now my error is this:
This is now happening with and without fork.
In the following Ant script, what is the meaning of **/*?
<fileset dir="${server.src}" casesensitive="yes">
<include name="**/*.java"/>
</fileset>
** means any level of subdirectory
i.e. match a/x.java, a/b/y.java, a/b/c/z.java, etc.
I am getting the following exception when running an applet:
Exception in thread "AWT-EventQueue-4" java.lang.NoClassDefFoundError: ice/net/SnapshotCacheManager
but the file is inside the jar.
I searched online and found it might be related to the applet not looking in the current directory and i need to add .; to the CLASSPATH but i am not sure how to add it to the build.xml
Thanks
Doron
Edit: Finally I figured it out, it wasn't an ant problem or the build XML, I got this exception because I signed two jars containing the same package differently, so there was a collision, not a very informative exception....
it might be useful to see what is in your current build.xml file, but the section you probably want to look at is the <target> element specifically the <src path> and <fileset> elements. Here is a VERY rough example with some guiding variables.
<property name="classes.home" value="/myproject/src"/>
<target name="compile_myproject" depends="clean">
<javac destdir="${classes.home}" debug="off" optimize="on" deprecation="on">
<classpath>
<fileset dir="/location/of/jars/">
<include name="*.jar"/>
<exclude name="jar-I-dont-want.jar"/>
</fileset>
<fileset dir="/location/of/axis2/jars">
<include name="**/*.jar"/>
</fileset>
</classpath>
<src path="${classes.home}"/>
<include name="/test/**/*.java"/>
<include name="other/location/*.java"/>
<exclude name="/debug/and/useless/files/**/*.java"/>
</javac>
</target>
note that ${classes.home} is a special variable defined at the top of the build.xml file. Many variables can be used to make things easier and specify relative paths.
I'm sure this has either been asked before or is pretty straightforward. But for whatever reason, I cannot seem to make it work. I want to use ant to copy the ${build.classpath} (which contains a colon separated list of jars) to the ${output.dir}/myapp/WEB-INF/lib.
I have this right now and it doesn't seem to work:
<copy toDir="${output.dir}/myapp/WEB-INF/lib">
<fileset file="${build.classpath}" />
</copy>
It treats the whole classpath as one file. How do I get this to work?
The Ant Manual on the copy task contains the answer for your problem. One of the example snippets it provides:
Collect all items from the current CLASSPATH setting into a destination directory, flattening the directory structure.
<copy todir="dest" flatten="true">
<path>
<pathelement path="${java.class.path}"/>
</path>
</copy>
I think somethink like this should work:
<copy todir="${output.dir}/myapp/WEB-INF/lib" verbose="yes" flatten="yes" failonerror="no">
<fileset dir="${build.classpath}">
<include name="*.jar" />
</fileset>
</copy>
or with wildcard in include: <include name="**/*.jar" />
I think you should put all your colon separated jar files to one root folder. If it is not possible then create a separate task that put those jar files into one folder(may be temporary). And assign ${build.classpath} to that folder. Use <fileset dir="${build.classpath}"/> in your copy clause.
I hope, it should help.