You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Garima Bathla <ga...@gmail.com> on 2009/06/22 07:33:12 UTC

Manifest Classpath ( programmatically generated but messedup).

Dear Fellow memebers,

I really need help , I have been stuck with same problem for few days now.

Problem:
As we all know, manifest file syntax is very sensitive ( sensitive to
spaces, # of characters in a line, \n character). And I have learnt it very
hard way that if Class-Path in a jar is not set as per the standards it will
be silently ignored.

I am in the process of generating MANIFEST.MF file programmatically by
Extending Jar Task; I am almost there, but the class-path that Jar task
prints in the Manifest file isn't formatted correctly.

*Code snippet:*
*String formattedManifestClassPath = "aaa.jar bbb.jar ccc.jar ddd.jar
eee.jar fff.jar ggg.jar hhh.jar iii.jar jjj.jar kkk.jar lll.jar mmm.jar
nnn.jar ooo.jar ppp.jar qqq.jar rrr.jar sss.jar ttt.jar uuu.jar vvv.jar
www.jar xxx.jar yyy.jar zzz.jar";*
**
*Manifest.Attribute classpathAttribute = new
Manifest.Attribute(Manifest.ATTRIBUTE_CLASSPATH,
formattedManifestClassPath);

*
*manifest.addConfiguredAttribute(classpathAttribute);*

Now the problem is that the Class-Path in MANIFEST.MF file is generated as

*Class-Path: aaa.jar bbb.jar ccc.jar ddd.jar eee.jar fff.jar ggg.jar hh*
* h.jar iii.jar jjj.jar kkk.jar lll.jar mmm.jar nnn.jar ooo.jar ppp.jar*
*  qqq.jar rrr.jar sss.jar ttt.jar uuu.jar vvv.jar www.jar xxx.jar yyy.*
* jar zzz.jar*
* *
So if I run

"java -jar generated.jar"

Class-Path is being ignored, because it is not well formed.  How can I
generate class-path in the correct format? How do I set the String?

I have tried inserting \n ( new line character after every jar entery), but
ManifestClasspath is still not correct as Jar task inserts a new line
character after every 71st character.

formattedManifestClassPath = "aaa.jar \n bbb.jar \n ccc.jar \n ddd.jar \n
eee.jar \n fff.jar \n ggg.jar \n hhh.jar \n iii.jar \n jjj.jar \n kkk.jar \n
lll.jar \n mmm.jar \n nnn.jar \n ooo.jar \n ppp.jar \n qqq.jar \n rrr.jar \n
sss.jar \n ttt.jar \n uuu.jar \n vvv.jar \n www.jar \n xxx.jar \n yyy.jar \n
zzz.jar";

Any pointers if you know will be very helpful.

Regards,
Garima.



**
**
* *

Re: Manifest Classpath ( programmatically generated but messedup).

Posted by Dominique Devienne <dd...@gmail.com>.
On Tue, Jun 23, 2009 at 12:40 PM, Garima Bathla<ga...@gmail.com> wrote:
> I am trying to set classpath for a standalone application and I am not able
> to figure out what exactly I am doing wrong. Below is the classpath that is
> being generated in the MANIFEST.MF And this isn't valid classpath , when I
> run java -jar mystandaloneapplication.jar, it cannot find any classes.

Well I can't see anything wrong with your classpath.

From: http://java.sun.com/docs/books/tutorial/deployment/jar/basicsindex.html :
To run an application packaged as a JAR file (requires the Main-class
manifest header): java -jar app.jar

Your snippet does not add a Main-Class attribute to the manifest. --DD

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


Re: Manifest Classpath ( programmatically generated but messedup).

Posted by Garima Bathla <ga...@gmail.com>.
Thanks DD for your prompt reply,

I am trying to set classpath for a standalone application and I am not able
to figure out what exactly I am doing wrong. Below is the classpath that is
being generated in the MANIFEST.MF And this isn't valid classpath , when I
run java -jar mystandaloneapplication.jar, it cannot find any classes.

Class-Path: aaa.jar bbb.jar ccc.jar ddd.jar eee.jar fff.jar ggg.jar hh
 h.jar iii.jar jjj.jar kkk.jar lll.jar mmm.jar nnn.jar ooo.jar ppp.jar
  qqq.jar rrr.jar sss.jar ttt.jar uuu.jar vvv.jar www.jar xxx.jar yyy.
 jar zzz.jar


*Code Snippet:*
 jar.classpath.id = aaa.jar bbb.jar ccc.jar ddd.jar eee.jar fff.jar ggg.jar
hhh.jar iii.jar jjj.jar kkk.jar lll.jar mmm.jar nnn.jar ooo.jar ppp.jar
qqq.jar rrr.jar sss.jar ttt.jar uuu.jar vvv.jar www.jar xxx.jar yyy.jar
zzz.jar
 <manifestclasspath property="jar.manifest.attribute.class-path"
       jarfile="${dir.build.packages}/${file.name}.jar" maxparentlevels="0">
       <classpath refid="jar.classpath.id" />
 </manifestclasspath>

 <jar manifest="${jar.package.manifest}"
               destfile="${dir.build.packages}/${file.name.jar}"
               basedir="${dir.build.jar}">
              <manifest>
                 <attribute name="Class-Path"
value="${jar.manifest.attribute.class-path}"/>
              </manifest>
 </jar>


How do I ensure that the class-path that is generated is valid and can be
loaded when I run java -jar command?

Is it possible that this can be a bug with long classpath's? I will really
really appreciate some help on this.

Regards,
Garima
On Mon, Jun 22, 2009 at 12:47 PM, Dominique Devienne <dd...@gmail.com>wrote:

> On Mon, Jun 22, 2009 at 11:58 AM, Garima Bathla<ga...@gmail.com>
> wrote:
> > That exactly is what  I am doing, using Ant's Manifest class. Problem
> > happens to be that my classpath is too big and Manifest file has limit of
> 72
> > characters per line, so even though it spits out my configured classpath
> ,
> > it ain't set correctly (as I have listed in the orginial thread).
> >
> > Any help is highly appreciated, it must not be this tricky to set long
> > classpaths programmatically?
>
> Manifest can break a CP longer than 72 char on several lines correctly,
> using the proper rules, and has been doing it correctly for years.
>
> Very few bugs reported against it turned out to be real bugs in fact.
> So I strongly suggest you take a second look, assuming it does the
> correct thing. Note though that line breaks is only the beginning.
>
> The Class-Path: attribute also needs to use the proper file and path
> separators,
> be absolute or relative to the jar, and for this you should depend on
> ManifestClasspath,
> another Ant class that can take a Path and again format it correctly. --DD
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>

Re: Manifest Classpath ( programmatically generated but messedup).

Posted by Dominique Devienne <dd...@gmail.com>.
On Mon, Jun 22, 2009 at 11:58 AM, Garima Bathla<ga...@gmail.com> wrote:
> That exactly is what  I am doing, using Ant's Manifest class. Problem
> happens to be that my classpath is too big and Manifest file has limit of 72
> characters per line, so even though it spits out my configured classpath ,
> it ain't set correctly (as I have listed in the orginial thread).
>
> Any help is highly appreciated, it must not be this tricky to set long
> classpaths programmatically?

Manifest can break a CP longer than 72 char on several lines correctly,
using the proper rules, and has been doing it correctly for years.

Very few bugs reported against it turned out to be real bugs in fact.
So I strongly suggest you take a second look, assuming it does the
correct thing. Note though that line breaks is only the beginning.

The Class-Path: attribute also needs to use the proper file and path separators,
be absolute or relative to the jar, and for this you should depend on
ManifestClasspath,
another Ant class that can take a Path and again format it correctly. --DD

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


Re: Manifest Classpath ( programmatically generated but messedup).

Posted by Garima Bathla <ga...@gmail.com>.
That exactly is what  I am doing, using Ant's Manifest class. Problem
happens to be that my classpath is too big and Manifest file has limit of 72
characters per line, so even though it spits out my configured classpath ,
it ain't set correctly (as I have listed in the orginial thread).

Any help is highly appreciated, it must not be this tricky to set long
classpaths programmatically?



On Mon, Jun 22, 2009 at 7:10 AM, Dominique Devienne <dd...@gmail.com>wrote:

> On Mon, Jun 22, 2009 at 12:33 AM, Garima Bathla<ga...@gmail.com>
> wrote:
> > I am in the process of generating MANIFEST.MF file programmatically by
> > Extending Jar Task; I am almost there, but the class-path that Jar task
> > prints in the Manifest file isn't formatted correctly.
>
> Have you looked at Ant's own Manifest and ManifestClassPath classes? --DD
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>

Re: Manifest Classpath ( programmatically generated but messedup).

Posted by Dominique Devienne <dd...@gmail.com>.
On Mon, Jun 22, 2009 at 12:33 AM, Garima Bathla<ga...@gmail.com> wrote:
> I am in the process of generating MANIFEST.MF file programmatically by
> Extending Jar Task; I am almost there, but the class-path that Jar task
> prints in the Manifest file isn't formatted correctly.

Have you looked at Ant's own Manifest and ManifestClassPath classes? --DD

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