Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Jar generated with ant will not use manifest class-path

Posts: 16
  • Mark post as helpful
  • send pies
  • 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'/>

<pathconvert property='lib.path.manifest' pathsep=' '>
<path refid='lib.path'/>
<globmapper from='*' to='lib/*'/>
<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'/>
<mkdir dir='dist'/>
<jar jarfile='dist/${name}-${version}.jar' basedir='build'>
<attribute name='Built-By' value='Pander'/>
<attribute name='Class-Path' value='${lib.path.manifest}'/>
<attribute name='Main-Class' value='com.svg.${name}.${Name}'/>
<checksum file='dist/${name}-${version}.jar' forceOverwrite='yes'/>

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

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
  • 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.

It's a pleasure to see superheros taking such an interest in science. And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic