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?
Related
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.
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.
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.
I am trying to run jar file through
java -jar jts.jar
but it is unable to run because it's Manifest.mf do not contain 'Main-Class' attribute, which is necessary for a jar file to run.
I am have same problem with 9-10 .jar files.
Help me with how to find those mainclass in jar files, there is no any directly defined mainclass in jar file.
How should I find the correct mainclass and how should I add it to manifest.mf
On command line you can use following command to generate jar having existing manifest.
jar cvfm MyJarName.jar manifest.txt *.class
Refer this page for more details.
Alternatively, if you are using eclipse. Please follow steps mentioned here to export jar.
if you have your Main-Class attribute on the last line of your manifest.txt, it vanishes if you do not have a new line at the end. Very annoying, but always make sure you have a new line at the end of your manifest file.
1. You can open the jar file with winzip or winrar.
2. Open manifest file in notepad.
3. Add main-class: ClassNameContianingMainMethod.
4. Save the file and then run it
I am trying to convert my java application to an executable jar.
I have been able to package it into a jar with all my class files, but still am not able to include the jmf.jar file.
This is my directory structure,
Main dir
src/ //A dir
--a.java
--b.java
jmf.jar
Manifest.txt
Content of my Manifest.txt file,
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Main-Class: src/a
Class-Path: .;jmf.jar //also tried ./jmf.jar
By double clicking the .jar file, I am able to run the main function, but the second function uses the jmf.jar throws exception when I tried running the jar file in debug mode, that javax.media not found. This class is in the jmf.jar file, which makes me conclude the jmf.jar file is not being included in the class path or so. So what am I doing wrong? How do I make this executable file?
The command I used to convert it to jar was,
jar cvfm myJar.jar Manifest.txt src\*.class jmf.jar
The jar files referred to by the Class-Path entry in the manifest must not be inside the jar, but outside of it, as explained in the jar tutorial.
If you are using JMF you’ll need to include jmf.jar and jmf.properties in the same directory as the executable jar