ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From __matthewHawthorne <mhawtho...@alumni.pitt.edu>
Subject Re: Problem running executable jar - classpath issues
Date Wed, 23 Jul 2003 23:28:52 GMT
On second thought, the paths in the manifest classpath are relative to 
the jar file itself, _not_ where the JVM is started.  So, you'll 
probably have to do one of the things that you mentioned before:  Either 
copy /lib into /dist, or copy app.jar into the project root.  I suggest 
the latter, although it will duplicate more disk space, your /dist 
directory will become a good simulation of a deployment environment.




Duffey, Kevin wrote:

>I tried that. Still no go. It is definitely pissing me off! So my project dir:
>
>/src
>/lib/*.jar - 3rd party jars that both compile and runtime need to see/use
>/build/classes - compiled output
>/dist/app.jar - location of my packaged /build/classes executable jar
>/build.xml - the root path of project, my build script.
>
>So, build.xml, being in the root path would normally start the JVM from the path it is
located in, thus the root path. Relative to it is lib/*.jar.
>
>My manifest:
>
>Manifest-Version: 1.0
>Main-Class: com.mycompany.ui.App
>Created-By: 1.2 (Sun Microsystems Inc.)
>Implementation-Vendor: "MyCompany, Inc"
>Class-Path: lib/jdbc2_0-stdext.jar lib/jh.jar lib/jtds-0.5.1.jar lib/kxml2.jar lib/log4j.jar
lib/msbase.jar lib/mssqlserver.jar lib/msutil.jar lib/TableLayout.jar
>
>So, the above indicates for an executable jar that com.mycompany.ui.App will start and
relative to where ever it starts, it should find the .jar files in the lib dir based on the
Class-Path above.
>
>So, if build.xml is in root, and I start it from that location, but I specify jar="${dist.dir}/app.jar"
dir="." in the java task, shouldn't that work? The "." location is the location of the build.xml
file, the {dist.dir} is <project root>/dist. It shows that it starts, but every time
I get:
>
>
>execute:
>     [java] java.lang.NoClassDefFoundError: org/apache/log4j/Logger
>     [java] 	at com.mycompany.ui.App.<clinit>(App.java:49)
>     [java] Java Result: 1
>     [java] Exception in thread "main"
>
>the above error points I my executing class to:
>
>static Logger logger = Logger.getLogger(App.class);
>
>
>So, apparently it IS finding the App class to run, but the reference to the log4J class
is not being found.
>
>
>Any suggestions given what I am doing?
>
>-----Original Message-----
>From: __matthewHawthorne [mailto:mhawthorne@alumni.pitt.edu] 
>Sent: Wednesday, July 23, 2003 3:55 PM
>To: Ant Users List
>Subject: Re: Problem running executable jar - classpath issues
>
>I don't fully understand the details of your situation, but you might 
>want to try using the "dir" attribute in the <java/> task.  It will 
>allow you to invoke the JVM wherever you want, and then your executable 
>jar may be able to find it's 3rd party jars.
>
>Try <java dir=<your project root> ... />
>
>I hope this helps...
>
>
>
>
>Duffey, Kevin wrote:
>
>  
>
>>Hi all,
>>
>>My project builds everything into an executable .jar file, except it doesn't embed
3rd party .jar files it relies on because the JVM doesn't support finding classes in .jar
files embedded in the main executing jar file. So, I zip everything up, when unzipped it creates
a dir with the executable .jar file in the root, and a lib directory where it places all 3rd
party libraries.
>>
>>My script is able to compile against it no problem:
>>
>>
>>	<path id="compile.classpath">
>>		<fileset dir="${lib.dir}">
>>			<include name="*.jar"/>
>>		</fileset>
>>	</path>
>>
>>	<path id="test.classpath">
>>		<path refid="compile.classpath"/>
>>		<pathelement location="${junit.jar}"/>
>>		<pathelement location="${test.dir}"/>
>>	</path>
>>
>>	<path id="run.classpath">
>>		<path refid="compile.classpath"/>
>>		<pathelement location="${build.dir}/classes"/>
>>	</path>
>>
>>
>>The execute task:
>>
>>	<target name="execute">
>>		<java jar="${dist.dir}/app.jar" fork="true" failonerror="false">
>>			<classpath refid="run.classpath"/>
>>		</java>
>>	</target>
>>
>>The problem is, I build the app.jar into my <project root>/dist/app.jar, and
the lib files are not being found when it executes. They are in <project root>/lib/*.jar
(also known as ${lib.dir}). If I copy the lib directory to my dist directory, it works. Internally,
my code uses relative paths to find property files in the app.jar. But in my main class I
use Log4J, which is specified in the manifest class-path as lib/log4j.jar. Thus, it is relative
to the location of the startup of app.jar. However, it appears even though I have followed
the Java Development with Ant book, it still can't find my lib/*.jar files.
>>
>>So, I am guessing that even though my build script is in <project root> and
it starts the app.jar from within <project root>/dist/app.jar, it is seeing the root
dir as the <project root>/dist/ directory. If it wasn't, then the relative paths in
Class-Path in the manifest file would work. And that would explain why when I copy it to the
dist dir, it works.
>>
>>Can somebody please explain how to make this work? I don't want to have to copy my
app.jar into the <project root> dir, nor do I want to keep two directories of the libraries!
I want to use my <project root>/lib/*.jar from the app.jar located in <project root>/dist/app.jar,
and execute this from the build script.
>>
>>Thanks.
>>
>>
>>---
>>Outgoing mail is certified Virus Free.
>>Checked by AVG anti-virus system (http://www.grisoft.com).
>>Version: 6.0.501 / Virus Database: 299 - Release Date: 7/14/2003
>>
>>
>>
>>***************************************************************************
>>"The information contained in this e-mail message  may be confidential and 
>>protected from disclosure.  If you are not the intended recipient, any 
>>dissemination, distribution or copying is strictly prohibited.  If you think 
>>that you have received this e-mail message in error, please e-mail the 
>>sender at exchangeadmins@marketron.com."
>>***************************************************************************
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>>For additional commands, e-mail: user-help@ant.apache.org
>>
>>
>> 
>>
>>    
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org
>
>
>---
>Incoming mail is certified Virus Free.
>Checked by AVG anti-virus system (http://www.grisoft.com).
>Version: 6.0.501 / Virus Database: 299 - Release Date: 7/14/2003
> 
>
>---
>Outgoing mail is certified Virus Free.
>Checked by AVG anti-virus system (http://www.grisoft.com).
>Version: 6.0.501 / Virus Database: 299 - Release Date: 7/14/2003
> 
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org
>
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message