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.
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>.
I'm trying to call Findbugs via Ant, but receiving this error:
Cannot run program "C:\Program Files (x86)\Java\jre6\bin\javaw.exe" (in
directory "H:\Users\MyName\workspace\MyProject"):
CreateProcess error=206, The filename or extension is too long
How can I fix this? o.O
I had the same problem.
I used
<fileset dir="${basedir}/build">
<include name="**/*.class"/>
</fileset>
inside findbugs target and it seems that there is too much .class files to be passed to findbug (?via command line?) because when I used
<fileset dir="${basedir}/build/com/domain/package">
<include name="**/*.class"/>
</fileset>
that had low number of classes, the error was gone.
So, I solved the problem by making one jar file and feeding it to findbugs target with
<findbugs home="${findbugs.home}">
...
<class location="${basedir}/targets/classes-to-analyze.jar"/>
</findbugs>
I think one of the effective file paths are really long when java tries to compile clases.
One worth try is to put codebase in a directory such as C:\MyProject instead of something like C:\Users\MyName\workspace\MyProject
To solve this issue you need to generate a manifestclasspath and a pathing jar.
First Generate your classpath.
<path id="javac.path">
<fileset dir="lib/" includes="**/*.jar"/>
</path>
Next Generate your manifestclasspath
<target name="generate-manifest-classpath">
<manifestclasspath property="manifest.classpath" jarfile="pathing.jar">
<classpath refid="javac.path"/>
</manifestclasspath>
<jar destfile="pathing.jar" basedir="${the location of your build classes}">
<manifest>
<attribute name="Class-Path" value="${manifest.classpath}"/>
</manifest>
</jar>
<path id="javac.classpath">
<pathelement path="pathing.jar"/>
</path>
</target>
Next Implement your Manifestclasspath
<javac srcdir="${foo.dir}" destdir="${bar.dir}"
<classpath refid="javac.classpath"/>
</javac>
This will solve the 206 error message if implemented correctly.
I had the same error on IntelliJ while starting debug mode only. To fix is I've changed:
Run > Edit Configurations > "Configuration" tab > Shorten command line
to "JAR-manifest"
I am trying to convert a web service from using the version of ant that comes with weblogic (OFM 11G Release 1 (10.3.6)) to a newer, standalone version of ant (1.8.4). During the build with 1.8.4 I am receiving the following warnings which I would like to eliminated if possible. The warning occurs with all exception classes in the project. Can anyone provide a suggestion? I am new to weblogic web services.
[jwsc] [WARNING] skipping exception constructor for ca.bc.gov.webade.WebADEException: could not find property corresponding to ctor param 'arg0' on public WebADEException(java.lang.String,java.lang.Exception)
Here is the JWSC portion of the build file. The task is defined using the same paths as part of the build classpath below. The weblogic paths correspond to to WLS_HOME and MODULES_DIR environment variables as set by weblogic.
<target name="jwsc" depends="compile">
<path id="JWSCclasspath">
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
<fileset dir="${webade.lib.dir}" includes="*.jar" />
<!-- Reference compiled classes rather than jar file due to issue deleting the jar file at the end of the build -->
<pathelement path="${build.bus.dir}"/>
<pathelement path="{weblogic.dir}"/>
<fileset dir="${weblogic.dir}" >
<include name="*.jar" />
</fileset>
<pathelement path="${weblogic.modules}" />
<fileset dir="${weblogic.modules}" >
<include name="*.jar"/>
</fileset>
</path>
<jwsc srcdir="${src.dir}" destdir="${deploy.dir}" classpathref="JWSCclasspath">
<jws file="${war.path}/MapViewerServicesPortTypeImpl.java" type="JAXRPC">
<WLHttpTransport contextPath="mapViewer" serviceUri="MapViewerWS" portName="MapViewerServicesPort"></WLHttpTransport>
</jws>
</jwsc>
</target>
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.
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.