Java manifest file altered after exporting project - java

This question is a follow up of this and this question. I've placed the META-INF/MANIFEST.MF file as suggested to /src/main/resources and exported the project using the following MANIFEST.MF file:
Manifest-Version: 1.0
Main-Class: org.fiware.kiara.generator.kiaragen
there is a new line after the Main-Class entry before the end of the file. The artifact configuration is bellow:
The MANIFEST.MF file in the .jar file is different from the one specified in the resources directory:
$ cat META-INF/MANIFEST.MF
Manifest-Version: 1.0
Created-By: 1.5.0_13 (Apple Inc.)
Why is the Main-Class entry removed?

Simple - it is done due to the build cycle.
First your sorces gets compiled along with your manifest from the resources, second maven writes new manifest, and it gets simply overriden.
If you want to pust some custom stuff into your manifest, and you use Maven, you should rather modify your POM file to create proper manifest insteed of putting one in the resources.
Check following
https://maven.apache.org/shared/maven-archiver/examples/manifestFile.html for custom manifest includement.

Related

Adding a classpath to my jar through Manifest file

I built a jar file and I need to get access to a folder that's outside of it.
In my jar I have a MANIFEST.MF file. If i add the folder to it will I be able to use it?
Manifest-Version: 1.0
Main-Class: com.petapilot.migrations.MigrationsApplication
Or is is it a better opinion to set it using the flag classpathwhen I run my jar through the command line?

Creating Executable jar from CMD prompt

I have following class files,jar and manifest in a directory
Dot.class
Bridge.class
jsch.jar
MANIFEST.MD
Manifest file contains following two lines
Manifest-Version: 1.0
Main-Class:Dot
command used for creating jar file
jar cfm dot.jar MANIFEST.MD *
While executing generated jar it throws error saying no main manifest attribute
While seeing inside the generated jar META-INF folder contains auto generated manifest file, it doesn't have content for my main class.
I couldn't find successful steps ,Please correct me.
Had the same issue a few days ago and couldn't resolve it with the manifest file so I put the main class as a build parameter like this:
jar cfe Main.jar MainClass *.class
Add a space after ':' as in
Main-Class: Dot
Add a new line after the last line, in your case after Main-Class entry:
Manifest-Version: 1.0
Main-Class: Dot
The reason for 2. ist documented in https://docs.oracle.com/javase/tutorial/deployment/jar/modman.html in detail.
I tried below command and it works with the jar produced which i post.
java -cp "jsch.jar;." Dot

How exactly do I compile my Java into a JAR file?

So I'm trying to compile my game for my Object-Oriented Programming class into a jar file so it can be ran with java -jar javacoffeeadventure.jar.
My folder structure for a folder with java files removed looks like this:
audiomanager/
commandinterpreter/
gamemanager/
io/
logic/
META-INF/
player/
resources/
rooms/
main.class
Everything is packaged under javacoffeeadventure. For example, the main file is javacoffeeadventure.main. The META-INF folder contains one MANIFEST.MF file that I tried to edit and make the jar invoke main.class's main() method:
Manifest-Version: 1.0
Created-By: 1.8.0_60 (Oracle Corporation)
Main-Class: javacoffeeadventure.main
I know I use jar to compile into a jar file, but how would I use that command to create a jar file that is able to begin with javacoffeeadventure.main? Is my manifest wrong?
as a slight by-the-way, jar puns are funny to me if you guys have any. :)
In my experience, the following has worked, but if you utilize it, you may need to adapt your directory structure.
First, your folder structure needs to be of the form 'containing_folder.com.example.package', where your classes are in the 'package' folder. You need to then place your manifest.mf file in the uppermost directory ('folder'). The manifest file should be as follows:
Manifest-Version: 1.0
Main-Class: com/example/package/javacoffeeadventure
including a carriage return after the second line.
From the initial folder compile with the following command:
jar cmvf manifest.mf javacoffeeadventure.jar com/example/package/*.class
making sure that beforehand you've compiled the classes in your package (use *.java)
Hope this helps.

while creating JAR from eclipse?How to set class path in manifest file ,

I am done trying with all the solutions provided. Please help with this:
I am trying to create an executable jar for my project with manifest file. But I keep on get the error no class found.
My manifest file looks like below and it is in project level. I create a jar from eclipse through export.
Manifest-Version: 1.0
Main-Class: com.tn.gov.runParser.RunParser
Class-Path: commons-logging-1.1.1.jar s.jar t.jar 3.jar j.jar o.jar s.jar util.jar xml.jar xml.jar
When you export your project into a JAR, on the prefrences/config page, under "Launch configuration" would be all the possible Classes to put in Main-Class: Also, you could edit MANIFEST.MF on the Main-Class: line manually.

Manifest classpath is not working

I have created one manifest.jar which contains the jars that needs to be added in classpath for some other Jar. I tried using relative classpath as well in my manifest.mf but still these jars are not getting added in classpath or that jar which needs these jars is not picking the jars from manifest.
the manifest looks like :-
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Class-Path: abc.jar adc1.jar ../abc2.jar ../abc3.jar ../../lib/abc4.jar
So if my jar say "My.jar" needs these these jars in classpath. And i have created a manifest.jar from above manifest.mf.But still it is not picking these jars.
A possible reason is described in http://docs.oracle.com/javase/tutorial/deployment/jar/modman.html
Warning: The text file from which you are creating the manifest must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.
That's not allowed.... a jar can't contain other jars (if not exploded) look at: ClassPath in manifest does not work

Categories