Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #10937 > unrolled thread
| Started by | www <xsli2@yahoo.com> |
|---|---|
| First post | 2011-12-21 12:03 -0800 |
| Last post | 2011-12-22 02:22 -0800 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.java.programmer
cannot create the runnable JAR file containing 3rd party JAR files www <xsli2@yahoo.com> - 2011-12-21 12:03 -0800
Re: cannot create the runnable JAR file containing 3rd party JAR files markspace <-@.> - 2011-12-21 14:23 -0800
Re: cannot create the runnable JAR file containing 3rd party JAR files www <xsli2@yahoo.com> - 2011-12-21 17:29 -0800
Re: cannot create the runnable JAR file containing 3rd party JAR files Roedy Green <see_website@mindprod.com.invalid> - 2011-12-22 02:22 -0800
| From | www <xsli2@yahoo.com> |
|---|---|
| Date | 2011-12-21 12:03 -0800 |
| Subject | cannot create the runnable JAR file containing 3rd party JAR files |
| Message-ID | <12e4a109-e7da-410e-b16c-330884bf35d2@o14g2000vbo.googlegroups.com> |
Dear All:
My directory structure is the following:
libs/externa/ containing a.jar, b.jar
libs/installed/ the generated runnable JAR file, "sample.jar", will
be here
src/ containing Java source files
build/ containing Java class files
The main class is x.y.z.MyMain
I have had a really hard time to create a runnable JAR file using
Ant(version 1.6.5). The JAR file, libs/installed/sample.jar, can be
generated. However, when I run it, the classes inside a.jar or b.jar
are not available and causes NullPointerException. When I un-tar
sample.jar, everything is there. I think manifest classpath is causing
the problem.
Following is my brief build.xml:
<filelist id="external.jars" dir="libs/external">
<file name="a.jar" />
<file name="b.jar" />
</filelist>
<path id="project.classpath">
<pathelement location="./build" />
<filelist refid="external.jars"/>
</path>
<target name="build" depends="init">
<javac debug="true" debuglevel="${debuglevel}" destdir="$
{build.dir}" source="${source}" target="${target}">
<src path="src" />
<classpath refid="project.classpath" />
</javac>
</target>
<target name="jar" depends="clean, build">
<pathconvert property="manifest.classpath" pathsep=" ">
<mapper>
<chainedmapper>
<!-- remove absolute path -->
<flattenmapper />
<!-- add libs/external prefix -->
<globmapper from="*" to="libs/external/*" />
</chainedmapper>
</mapper>
<path>
<filelist refid="external.jars"/>
</path>
</pathconvert>
<jar destfile="libs/installed/sample.jar" basedir="./build"
update="true">
<manifest>
<attribute name="Main-Class" value="x.y.z.MyMain" />
<attribute name="Class-Path" value="${manifest.classpath}"/>
</manifest>
<fileset dir="${externals.dir}"/>
</jar>
</target>
Thank you very much.
[toc] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2011-12-21 14:23 -0800 |
| Message-ID | <jctm9m$qfb$1@dont-email.me> |
| In reply to | #10937 |
On 12/21/2011 12:03 PM, www wrote: > I have had a really hard time to create a runnable JAR file using > Ant(version 1.6.5). The JAR file, libs/installed/sample.jar, can be > generated. However, when I run it, the classes inside a.jar or b.jar > are not available and causes NullPointerException. When I un-tar > sample.jar, everything is there. I think manifest classpath is causing > the problem. > Could you show us the actual error message? It would help. Also when the error occurs, if there aren't too many lines in between the launch and the error message. Also please show us the Java command line itself and the contents of the Jar and manifest file. Like this: Brenden@Kageyama ~/Dev/proj/hw/dist $ java -jar hw.jar Hello world! <<-- you would have an error message here instead Brenden@Kageyama ~/Dev/proj/hw/dist $ jar -tf hw.jar META-INF/ META-INF/MANIFEST.MF hw/ hw/Hw.class Brenden@Kageyama ~/Dev/proj/hw/dist $ jar -xf hw.jar META-INF/MANIFEST.MF Brenden@Kageyama ~/Dev/proj/hw/dist $ ls META-INF README.TXT hw.jar Brenden@Kageyama ~/Dev/proj/hw/dist $ cat META-INF/MANIFEST.MF Manifest-Version: 1.0 Ant-Version: Apache Ant 1.8.2 Created-By: 1.7.0-b147 (Oracle Corporation) Class-Path: X-COMMENT: Main-Class will be added automatically by build Main-Class: hw.Hw > <pathconvert property="manifest.classpath" pathsep=" "> > <mapper> > <chainedmapper> > <!-- remove absolute path --> > <flattenmapper /> Neat, I learned something new.
[toc] | [prev] | [next] | [standalone]
| From | www <xsli2@yahoo.com> |
|---|---|
| Date | 2011-12-21 17:29 -0800 |
| Message-ID | <9c74a472-6587-4b57-9998-191f8e8e772e@v24g2000yqk.googlegroups.com> |
| In reply to | #10938 |
Thank you for the reply. I just found this link. My problem is exactly same as his: http://stackoverflow.com/questions/3770071/including-external-jar-files-in-a-new-jar-file-build-with-ant Another related link is: http://stackoverflow.com/questions/3143567/cannot-find-main-class-in-file-compiled-with-ant/3144290#3144290 I have not carefully studied/tried the posted answers yet. One issue is that our Ant version is 1.6.5. The ant tag "zipgroupfileset" is only available for Ant 1.7 or newer.
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2011-12-22 02:22 -0800 |
| Message-ID | <5616f793qjbdnkakkirbfl0krqotbho7ho@4ax.com> |
| In reply to | #10937 |
On Wed, 21 Dec 2011 12:03:22 -0800 (PST), www <xsli2@yahoo.com> wrote, quoted or indirectly quoted someone who said : >The JAR file, libs/installed/sample.jar, can be >generated. However, when I run it, the classes inside a.jar or b.jar >are not available and causes NullPointerException see http://mindprod.com/jgloss/jarlinking.html -- Roedy Green Canadian Mind Products http://mindprod.com If you can't remember the name of some method, consider changing it to something you can remember.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web