• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Jar generated with ant will not use manifest class-path

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I generate a jar with ant but it will not use the class-path specified in the manifest file. However, when I extract the jar and package it again manually it works ok. How do I fix my ant so it works directly?

ant file:

...
<path id='lib.path'>
<fileset dir='lib/'>
<include name='*.jar'/>
</fileset>
</path>

<pathconvert property='lib.path.manifest' pathsep=' '>
<path refid='lib.path'/>
<chainedmapper>
<flattenmapper/>
<globmapper from='*' to='lib/*'/>
</chainedmapper>
</pathconvert>
...
<target name='dist' depends='build' description='make distribution'>
<copy file='README' todir='build'/>
<copy file='LICENSE' todir='build'/>
<copy file='ChangeLog' todir='build'/>
<copy todir='build/lib'>
<fileset dir='lib'/>
</copy>
<mkdir dir='dist'/>
<jar jarfile='dist/${name}-${version}.jar' basedir='build'>
<manifest>
<attribute name='Built-By' value='Pander'/>
<attribute name='Class-Path' value='${lib.path.manifest}'/>
<attribute name='Main-Class' value='com.svg.${name}.${Name}'/>
</manifest>
</jar>
<checksum file='dist/${name}-${version}.jar' forceOverwrite='yes'/>
</target>

<target name='run'>
<java jar='dist/${name}-${version}.jar' fork='true'/>
</target>
...

The resulting manifest in the generated jar is:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.5
Created-By: Blackdown-1.4.2-02 (Blackdown Java-Linux Team)
Built-By: Pander
Main-Class: com.svg.vault.Vault
Class-Path: lib/BrowserLauncher2.jar

but "ant run" or "java -jar bla.jar" will abort on being unable to find classes of lib/BrowserLauncher2.jar

but if I unjar the file and create a new jar with
jar mcf specifying the manifest and the contents of the just extracted jar, the new jar will work with "java -jar bla.jar"

How can I fix this so that the jar generated by ant works with java -jar ?
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am willing to bet that the problem is with the relative path used in the Class-Path attributed is being resolved from a directory other than the one you expect. What is used as the "current working directory" when you run "ant run" or "java -jar ..." with the ant-generated jar file? Where is this lib/BrowserLauncher2.jar located relative to that directory? If you can figure out how ant is using the directory structure, you should be able to resolve this issue.

I should mention that I have successfully used Ant to generate a jar file and run it, so I doubt the problem is with Ant itself.

Layne
 
You are HERE! The other map is obviously wrong. Better confirm with this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic