How to modify the manifest file

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

How to modify the manifest file

Inam
Hi all,

Does any one know how to read/modify the manifest file?
actually I want to modify this file pragmatically after running script "grails war" .

Thanks,
Inam.
Reply | Threaded
Open this post in threaded view
|

Re: How to modify the manifest file

Wolfgang Schell
Hi Inam,

Inam wrote
Does any one know how to read/modify the manifest file?
actually I want to modify this file pragmatically after running script "grails war" .
one simply but not optimal way is to patch the script $GRAILS_HOME/scripts/_GrailsWar.groovy. You can find an example patch, which provides basic OSGi bundle headers, at http://github.com/jetztgradnet/grails-osgi-testenv/blob/master/bundle-manifest.patch (also see http://blog.jetztgrad.net/2009/11/grails-on-osgi-2-first-steps/ for this).

Another possibility is to hook into WAR generation by waiting for the event "CreateWarStart" (create file _Events.groovy in your apps scripts directory, see http://grails.org/doc/1.1.x/guide/4.%20The%20Command%20Line.html#4.3%20Hooking%20into%20Events for details) and patching the existing manifest file. A separate event for manifest generation would be nice as well.

The manifest created by Grails contains some entries like "Grails-Version" and "Implementation-Title" (see http://github.com/grails/grails/blob/master/grails/scripts/_GrailsWar.groovy#L190). Note, that these entries belong to a subsection of the manifest, so if you add some entries make sure to put them at the beginning of the file. Otherwise they will be part of the subssection and be ignored by most applications reading the manifest!

HTH,

Wolfgang
Reply | Threaded
Open this post in threaded view
|

Re: How to modify the manifest file

Inam
In reply to this post by Inam
Wolfgang thanks for the reply.
Your second option (CreateWarStart) is best, actually I also following this approach here is the code (in _Events.groovy)

eventCreateWarEnd = {warName, stagingDir ->
        String metaInfo = "$stagingDir/META-INF"
        ant.mkdir(dir:metaInfo)
        String manifestFile = "$metaInfo/MANIFEST.MF"
        ant.manifest(file:manifestFile) {
                attribute(name:"Main-Class",value:"Start")
        }
}

but it didn't work, I thought I might not following the correct syntax, can you please figure out whats wrong in there?.

Thank you very much,
Inam.

Inam wrote
Hi all,

Does any one know how to read/modify the manifest file?
actually I want to modify this file pragmatically after running script "grails war" .

Thanks,
Inam.
Reply | Threaded
Open this post in threaded view
|

Re: How to modify the manifest file

Wolfgang Schell
Hi Inam,

Inam wrote
Your second option (CreateWarStart) is best, actually I also following this approach here is the code (in _Events.groovy)

eventCreateWarEnd = {warName, stagingDir ->
        String metaInfo = "$stagingDir/META-INF"
        ant.mkdir(dir:metaInfo)
        String manifestFile = "$metaInfo/MANIFEST.MF"
        ant.manifest(file:manifestFile) {
                attribute(name:"Main-Class",value:"Start")
        }
}
This looks good to me. One thing: you overwrite the manifest created by Grails. You might want to merge it, but I don't known, whether ant does this by default or if there is an easy way. This shouldn't

Inam wrote
attribute(name:"Main-Class",value:"Start")
So you want to be able to run your application using "java -jar myamc-0.1.war"? Do you intend to start an embedded servlet container? Or some GUI application?

Inam wrote
but it didn't work, I thought I might not following the correct syntax, can you please figure out whats wrong in there?.
What is it, that does not work? Do you get some error, e.g. by (g)ant? Did the manifest get generated? How does it look like? Does the resulting .war contain your manifest?

If your error occurs when running your app using "java -jar myamc-0.1.war", you need to consider two things:

1) You need to specifiy the classpath within the war file! When running your app using "java -jar ..." only the classpath specifiedc in the manifest is used, an classpath set using java -classpath ... -jar ..." is ignored! This means, you have to set the manifest entry "Class-Path" with the classes from WEB-INF/classes as well as all jars in WEB-INF/lib (and possibly other jars/classes, which you might need, but are placed elsewhere). See my example patch (http://github.com/jetztgradnet/grails-osgi-testenv/blob/master/bundle-manifest.patch) for an example on how to set the class path in the manifest. All  you should need to change is "Bundle-ClassPath" into "Class-Path".

2) Does your class Start reside within a package? If so, you have to change the value of manifest entry "Start" to my.package.Start


HTH,

Wolfgang
Reply | Threaded
Open this post in threaded view
|

Re: How to modify the manifest file

Inam
In reply to this post by Inam
Wolfgang thanks for the reply, let me explain what is not worked:
In the end WAR file contains the META-INF/MANIFEST.MF file, but her is the contents of this file:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Created-By: 14.0-b16 (Sun Microsystems Inc.)

and after hooking into CreateWarEnd event I was expecting some thing like this:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Created-By: 14.0-b16 (Sun Microsystems Inc.)
Main-Class: Start

but this didn't happen.
and:
1) No error occured when running app using "java -jar myamc-0.1.war.
2) My class "Start" not reside within any package, its in the root and if MANIFEST have the entry (Main-Class: Start) it should pick it.

why MANIFEST didn't has the (Main-Class: Start) in it?, I don't know, can you help me.

Thank you very much,
Inam.

Inam wrote
Hi all,

Does any one know how to read/modify the manifest file?
actually I want to modify this file pragmatically after running script "grails war" .

Thanks,
Inam.
Reply | Threaded
Open this post in threaded view
|

Re: How to modify the manifest file

Inam
In reply to this post by Inam
Done it
in the end the following piece of code did the trick for me:
(in _Events.groovy file)

eventCreateWarEnd = {warName, stagingDir ->
        ant.jar(destfile:warName, update:true) {
                manifest { attribute(name: "Main-Class", value: "Start") }
        }
}
thats it!
hope this will help some one else.
Thanks Wolfgang for your help, I really appreciate it.

Thanks,
Inam.

Inam wrote
Hi all,

Does any one know how to read/modify the manifest file?
actually I want to modify this file pragmatically after running script "grails war" .

Thanks,
Inam.
Reply | Threaded
Open this post in threaded view
|

Re: How to modify the manifest file

Wolfgang Schell
In reply to this post by Inam
Hi Inam,

Inam wrote
Wolfgang thanks for the reply.
Your second option (CreateWarStart) is best, actually I also following this approach here is the code (in _Events.groovy)

eventCreateWarEnd = {warName, stagingDir ->
        String metaInfo = "$stagingDir/META-INF"
        ant.mkdir(dir:metaInfo)
        String manifestFile = "$metaInfo/MANIFEST.MF"
        ant.manifest(file:manifestFile) {
                attribute(name:"Main-Class",value:"Start")
        }
}

but it didn't work, I thought I might not following the correct syntax, can you please figure out whats wrong in there?.
you already have a solution, but I think I spotted the mistake: you should have used the event CreateWarStart instead of CreateWarEnd.

When doing this in CreateWarEnd, the war has already been created and your change to MANIFEST.MF will not be integrated.

In your solution (see other email later in this thread) you re-create the WAR file, which would not be necessary when doing this in event CreateWarStart.

Regards,

Wolfgang