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
Related
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?
I have a java file simpleMail.java and a jar file java-mail-1.4.jar (which is used in simpleMail.java). What I want to do is make an executable jar file out of these files and run on cmd.
Step 1. create manifest.txt file as
Main-Class: Main-Class-Name
Step2. compile all classes.
Step 3. run JDK's jar.exe utility like:
jar cvfm JarName.jar manifest.txt .class
cvfm is create a jar; show verbose output; specify the output jar file name; specify the manifest file name. (.class means all class files in the current directory.)
Step 4. specify jar dependency on classpath.
For detail refer http://www.skylit.com/javamethods/faqs/createjar.html
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.
I have created my JAR on Windows 2000 having java version 1.5 which contains following directories/files:
manifest.txt
com
lib
lib contains all JARS which I want to make part of my JAR. com contains my class files and below is manfiest.txt file
Main-Class: com.as.qst.result.ResultTriggerSchedular
Class-Path: lib/axis.jar lib/c3p0-0.9.1.1.jar lib/commons-discovery-0.2.jar lib/commons-logging-1.0.4.jar lib/jaxrpc.jar lib/log4j-1.2.16.jar lib/medplus-hub-8.2-wsclients.jar lib/medplus-hub-13.1-jaxws-clients.jar lib/quartz-2.2.1.jar lib/quartz-jobs-2.2.1.jar lib/saaj.jar lib/slf4j-api-1.6.6.jar lib/slf4j-log4j12-1.6.6.jar lib/ wsdl4j-1.5.1.jar lib/xercesImpl.jar com\as\qst\result
I used following command to generate my JAR
jar cvfm test.jar manifest.txt com lib
It has successfully created a JAR file but when I try to run it with
java -jar test.jar
it does not execute and throws above exception. I used the same process for Windows 7 which has version 1.7 and it did work out even without class files path in manifest.txt com\as\qst\result. Is something more to do with class-path besides defining in manifest? and why is it working in Windows 7?
You do not need the class file path in your class path entry. So instead of adding com\as\qst\result to your class-path.
More over you must not package other jar files in your runnable jar.
Other required jars must be provided in the same folder as your jar file (may be in separate folder) and Add current directory "." (without quotes) to your class-path.
Hope this helps.
EDIT
Just found this Stackoverflow Link. This might give you more insight. Please read through it.
I am trying to run my jar file on a Mac (Haven't yet tried on any other platform). When I run using java -jar MyApp.jar I get the following error
Stacktrace:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at tabalchi.MyLogger.getLogger(MyLogger.java:51)
at tabalchiApp.TabalchiApp.printSystemProps(TabalchiApp.java:117)
at tabalchiApp.TabalchiApp.main(TabalchiApp.java:37)
So, as you can see the main class is recognized.
This is the manifest file.
--->
Manifest-Version: 1.0
Class-Path: . jars/log4j-1.2.16.jar jars/jfugue-4.1.0-20120125.jar jars/gervill.jar jars/AppleJavaExtensions.jar
Main-Class: tabalchiApp.TabalchiApp
SplashScreen-Image: tabalchiApp/resources/splash.png
<---
And the folder structure in the jar file as follows.
--->
META-INF/MANIFEST.MF
jars/AppleJavaExtensions.jar
jars/gervill.jar
jars/jfugue-4.1.0-20120125.jar
jars/log4j-1.2.16.jar
tabalchiApp/TabalchiApp.class <-- this is the main class
tabalchiApp/otherClasses.....class
<---
I have read many posts about running .jar file but none of the solutions have worked for me. I would really appreciate your help on this one.
I am creating the jar file by exporting from eclipse. If I export to a runnable jar file then I cannot control the making of the manifest file. I need to add the splash image in the manifest file. And I am having some other issues with the runnable jar export. Hence this path.
It seems that log4j is missing.it is expecting jars/log4j-1.2.16.jar in class path .
jars/log4j-1.2.16
should be under folder structure.
jars/log4j-1.2.16.jar
In which directory are you trying to use:
java -jar MyApp.jar
You can specify the packages/directories in the classpath to be sure they are found.
Ok, so according to this link,
http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html
The Class-Path header points to classes or JAR files on the local network, not JAR files within the JAR file or classes accessible over internet protocols. To load classes in JAR files within a JAR file into the class path, you must write custom code to load those classes. For example, if MyJar.jar contains another JAR file called MyUtils.jar, you cannot use the Class-Path header in MyJar.jar's manifest to load classes in MyUtils.jar into the class path.
So, it seems I cannot include other jar files in my jar file.