Unable to create an executable jar file
Hi,
I am unable to create an executable jar file,
I am using the command as follows:
C\> jar cvfm MyJarName.jar manifest.txt Demo.class
where as Demo.class has appropriate main method; manifest.txt contains [ Main-Class: Demo ] and a new line
Please help.
thanks & regards
M K Rayapudi
Edited by: R6i on Apr 30, 2009 5:15 AM
Your jar is perfectly generated, but your machine has a problem with .jar file associations.
You have two options:
1. Play with the registry. Dangereous if you are not used to.
2. Reinstall the jre.
Just to verify my theory, open a command prompt and the command:
reg query HKCR\jarfile\shell\open\command
What does it say? I have executed your command , here is the output
HKEY_CLASSES_ROOT\jarfile\shell\open\command
(Default) REG_SZ "C:\Program Files\Java\jre6\bin\javaw.exe" -jar "%1" %*I am not getting anything from this command, can you please explain clearly.
thanks & regards
M K Rayapudi
Edited by: R6i on May 3, 2009 10:18 PM
Similar Messages
-
Creating an Executable jar file
Hello ! I have a application that has been fully developed and all i want to do is to create an executable file using my own icon so that whenever it is double clicked it opens up the appliation.
Please provide an example fro easy refrence.
Thanksi have the procedure for creating executable jar file in a separate file.
if u r interested then mail me at:
[email protected]
regards
Md. Afroze -
Creating an executable jar-file including a custom package
I am trying to learn how to create executable jar-files. I have managed this with a single class. However having a class which is an extention of another class which in turn belongs to custom package, I can't make it work.Running the program normally is not a problem. I don't think the problem is the actual code, but I will include it here anyway. I create the jar-file using:
jar -cmf Direkt2b.txt Direkt2b.jar *.class
where Direkt2b.txt is just:
Main-Class: Diriekt2b
Only the main class-file is included this way. Copying the other file to the same directory before creation doesn't help either. There is no error messages, the jar-file just refuses to run no matter what.
The main-class:
import java.awt.*;
import extra.*;
class Direkt2b extends ExtendedFrame {
Font f;
Direkt2b() {
f = new Font("SansSerif", Font.BOLD, 24);
setBackground(Color.yellow);
setSize(400,150);
public void paint(Graphics g) {
g.setFont(f);
g.setColor(Color.blue);
g.drawString("V?lkommen till Java Direkt", 45, 100);
public static void main (String[] arg) {
Direkt2b d2 = new Direkt2b();
d2.setVisible(true);
The help-class:
package extra;
import java.awt.*;
import java.awt.event.*;
public class ExtendedFrame extends Frame {
private static boolean first = true;
private boolean isFirst = first;
public ExtendedFrame() {
addWindowListener(theListener);
first=false;
WindowAdapter theListener = new WindowAdapter () {
public void windowClosing(WindowEvent e) {
dispose();
if (isFirst)
System.exit(0);
}My problem wasn't really getting more than one class in a jar-file,
but rather that my jar-file with multiple classes wouldn't execute.
Reading the original post I realized that maybe I was unclear about that.
However I have solved the problem now so for anybody reading this
thread in the future I will tell you how.
The general setting is this: You have a bunch of self-made help-classes
organized in some classdirectory somewhere in the filesystem. You use these
in your programming from time to time. You have set a classpath-varible
in your OS such that Java could find your help-classes.
Now you want to create executable jar-files so that you could publish your work.
My problem was that while I added all needed classes in a jar-file, the main-class
couldn't find the others because they were referenced incorrectly. The solution I
came up with may not be elegant, but it works. I copied the main-class and all directories
(only one in my case) just as they appear in the classpath-directory, to the same temporary
directory. Then I created the jar-file from there, using: jar -cmfv Direkt2b.txt Direkt2b.jar Direkt2b.class extra/*.class
I suspected that incorrect referencing was the problem and I tried several variations on the theme above
before giving up and writing the first post. Part the problem was that I didn't get any error messages,
just an annoying error-sound double-clicking the jar-file. I learned later that you could run jar-files from
the command -prompt using: java -jar myjarfile.jar. This way you get a more useful response.
I guess there is a way to include the classpath instead somehow, but I will use my method for now.
I hope this was helpful to somebody. -
How do I create an executable JAR File ?
Hi,
Let's say I have several Class Files that perform a special task.
How do I bundle them in a JAR file and make it executable, so that the user simply types "prog.jar" and is happy.
I wonder how that works, as I have to tell the starting point for execution.
Does anybody now ?
cu
OliverThree importants things to do :
- don't forget to indicate in your manifest.mf the main class and the pacckage
ex:
Manifest-Version: 1.0
Main-Class: mypackage.MyMainClass
Created-By: 1.3.0 (Sun Microsystems Inc.)
- don't forget to associate the .jar file with the application java.exe -jar -classpath %CLASSPATH%
- don't forget to set the environment CLASSPATH correctly
Hope this help
Jean -
How do I creat a Executable Jar file?
on my WIndows XP jars are automatically "executable".
if its not on yours (you can check) check out this thread:
http://forum.java.sun.com/thread.jspa?threadID=653572&tstart=0 -
Newbie's problem with executable jar file
hello
i create an executable jar file and it seems ok except it fails to locate all of my image files.
when i use
java -jar myproject.jar
it fails to display included pictures and files.
however, when i extract this jar file and run, it works fine (displays everything).
do i need to do add some informations about these included file's information into Manifest file?
thank youthank you for the reply.
i have searched through java, and find "class javax.commerce.cassette.JARCassetteLoader". is this one you referred? i have used file related examples from the java-swing samples.
//post - return the file path
protected static ImageIcon getImageIcon(String path)
java.net.URL imgURL = TestDialog.class.getResource(path);
if (imgURL != null)
return new ImageIcon(imgURL, description);
else
System.out.println("Couldn't find file: " + path);
return null;
then i just use
ImageIcon icon = getImageIcon("images"+File.separator+"simple.gif"); // images\simple.gif
thank you -
Executable JAR file and subdirectories, locale...
Hi:
I have created an executable jar file. In my program, I have to display an icon in which I stored in a subdirectory. This subdirectory is also archived into the jar file. However, as the application runs, it can't find the icon! I have to seperately create a subdirectory (with the same name and structure as the archived directory) for my program to display the icon properly! Does anybody know how I can use the archived subdirectory directly?
Also, the executable jar file has a problem of using the proper locale... Does anyone know how to get around this?
Thanx in advance for helping me out = )Thanx! It worked!
Does anyone know the answer to my second problem, namely, using the correct locale to display characters? When I run the application on the unarchived class file it works fine. However, when I run the application double-clicking the executable jar file icon, the characters are displayed incorrectly, which I assume to be problem with the locale... -
A few questions about executable Jar files
Hi,
I have to make an a tutorial system and was going to make it using applets embedded in webpages. This approach causes certain limitations so decided to make it using JPanels that open up as windows on the users computer.
I intend on compressing all the files (java, images, sound etc) within a Jar file and would like a few questions answering.
1. How would I make an executable Jar file that when clicked on will load the program on the users computer. Is there some software to do it for me or do I have to do it from the command prompt?
2. Is using a Jar file the best approach or is there a better way to get my java program to run on other peoples pc's
3. If I create an executable Jar file on windows xp, will it run on a Linux machine?
Cheers1. How would I make an executable Jar file that when clicked on will load the program on the users computer. Is there some software to do it for me or do I have to do it from the command prompt?The SDK contains all the tools you need. Use the jar command. To make your jar executable, include a manifest file that references your main class.
2. Is using a Jar file the best approach or is there a better way to get my java program to run on other peoples pc'sA jar will work just fine.
3. If I create an executable Jar file on windows xp, will it run on a Linux machine?Yes. -
Executable jar files and manifest file
Hi,
I have the following files in a folder named: Test
a.jar
b.jar
c.jar
Driver.class
Driver.mf
Here, MainClass is the main executable class that uses a,band c.jar files. This is how my MainClass.mf file looks:
Manifest-Version: 1.0
Main-Class: Driver
Class-Path: a.jar b.jar c.jar
Now I use the following command to make one executable jar file:
jar cmf Driver.mf DriverMain.jar *
It creates an executable jar file named : DriverMain.jar
Now I copy the executable jar file (DriverMain.jar) into a different folder named: RunTest
and double click it, doesn't work.
my question is:
what am I doing wrong? Any special characters needed in my Driver.mf file (space/newline/etc)?
What I am trying to get is: One execuatble jar file so I can just double click to run it, and that single executable jar file will have all the necessary jars in it (i.e. a.jar, b.jar, c.jar in this case)
Anyone please help!
Thanks
-RonRony,
Sorry to disappoint, but you can not use embeded jar/zip files within an executable jar. The JDK sadly for some reason decided this was not a useful idea, so developers like me who want to distribute plugins with thier own dependencies have one of two choices. You either have to unzip the jar file that contains the embeded jars to a directory, then run your primary exectuable jar, OR you have to write a custom classloader that your "launcher" creates then loads the embeded jar files.
The best thing to do is either jar up a, b, c and driver into one jar, so that it works, if you can legally do this. A lot of 3rd party libraries may not allow this per their license. Otherwise, another choice is to use a free installer or buy an installer that allows you to distribute a single exectuable installer program that will properly create the dir structure you need.
As for the way it works, if you declare:
Class-Path: a.jar b.jar c.jar
the JAR loader code in the JDK looks in the root dir where your application was started for a/b/c jar files. They have to be on disk.
If you want to place them in /lib, for example, you would havd a jar file like:
Driver.class
Driver.mf
lib/a.jar
lib/b.jar
lib/c.jar
When unzipped, your "root" dir would look exactly like the above, and your manifest would have Class-Path using ./lib/a.jar ./lib/b.jar ./lib/c.jar
Anyway, there thus far isn't any way around this issue of embeding jar files in an executable jar file. You MIGHT be able to not specify any classpath, then in your Driver.class, create a new custom classloader that dervies from URLClassLoader, but in the findClass(), you get a ref to the .jar file that the classloader class is inside of, and from that use it to find the lib/*.jar files and add them to the classpath. For this to work, however, your Driver.class code should ALSO be contained in an embeded jar file that is loaded by this custom loader. The only thing Driver.class would contain (and I would rename it to something like Launcher) is the code to create the custom classloader.
It's fun stuff, but a little bit of work to make it work. You can infact make it work! I may yet one day take our plugin engine custom loader and create a way for this to work! -
Unable to create Executable JAR file
Hi,
I tried to create Executable JAR file for
//JarTest.java
class JarTest
public static void main( String args[] )
System.out.println("i am EXECUTABLE JAR ");
mf is like
Manifest-Version: 1.0
Main-Class: JarTest
used jar cmf JarTest.mf exe.jar *.classIt created a jar file but i can't Execute the file
Help me
Thanks
AEjava is choosy about the actual manifest file format (line ending, trailing empty line, whatever).
This works for me with your example:
posman@proli:~/ivan/aa> cat mf
Manifest-Version: 1.0
Main-Class: JarTest
posman@proli:~/ivan/aa> od -cx mf
0000000 M a n i f e s t - V e r s i o n
614d 696e 6566 7473 562d 7265 6973 6e6f
0000020 : 1 . 0 \n M a i n - C l a s s
203a 2e31 0a30 614d 6e69 432d 616c 7373
0000040 : J a r T e s t \n \n \0
203a 614a 5472 7365 0a74 000a -
I am unable to execute jar files and applets. Also, the Java Web Start and the Java Plugin Control Panel will not load. I have unloaded the JRE and installed other versions. To date I have loaded and unloaded the following:
1.4.1
1.4.2_01, _02, _04
1.4.2_04 SDK
But no change in the outcome.
The javaw application starts but does not load the jar file.
The applets and jar files run fine on other computers with any of those JRE/SDK's installed.
Any suggestions would be helpful.Command line
To create a JAR file >jar cvf filename.jar filename.class(s)
To view the contents of a JAR file >jar tvf filename.jar
To extract the contents of a JAR file >jar xf filename.jar
To extract specific files from a JAR file >jar xf filename.jar archived-file(s)
To run an application packaged as a JAR file
>jar xvf filename.jar META-INF/MANIFEST.MF
The above will place META-INF/MANIFEST.MF file in your working directory. Open this file in text editor. Under Version, type in
Main-Class: filename
example;
Manifest-Version: 1.0
Main-Class: SelectPurchase
Created-By: 1.3.0 (Sun Microsystems Inc.)
save file
update META-INF/MANIFEST.MF file in jar file with;
jar umf META-INF/MANIFEST.MF filename.jarto run jar file from command line;
java -jar filename.jarTo run an application packaged as a JAR file
(version 1.1) jre -cp app.jar MainClass
(version 1.2 -- requires Main-Class
manifest header)
To invoke an applet packaged as a JAR file <applet code=AppletClassName.class
archive="JarFileName.jar"
width=width height=height>
</applet>
Does anyone know how to get the application to run by clicking on a Desktop Icon? -
Create the executable jar's file
Hi guys,
I am working on java desktop's application where a user will be able to run the application by double click the executable jar file. I followed the description of "Creating and Deploying a Simple Archive to Your File System of the help. After creating the jar file and when I double click on jar file to run the application I got this error message "Could not find the main class. Program will exit". I was not also able to run the application on the dos command.
Please help. I don't have any problem when I run from Jdeveloper 9.0.4. I have window XP professional.
Your input will be very welcomed.OK open up your deployed Jar file in something like Winzip and have a look at the Manifest.MF in meta-inf\
I've just created an executable JAR with a main class of mypackage1.Class1 and it all ran ok. Here's the manifest:
Manifest-Version: 1.0
Main-Class: mypackage1.Class1
Created-By: Oracle9i JDeveloper 9.0.2So make sure your's is similar and your Main-class looks the same - e.g. does not say something like:
Main-Class: mypackage1.Class1.class -
How to create executable jar files??
how to create executable jar files??
thx :)Using JAR Files to Deploy
http://developer.java.sun.com/developer/onlineTraining/Programming/BasicJava2/jar.html#jar -
Executable JAR file: Could not find the main class.
Hello,
I have a problem with making an executable JAR file.
I have written a JAVA program that consists of five different classes of which User.java is the main class and I have saved a text document with Main-Class: User and a blank line after that.
If I try:
jar cmf MainClass.txt User.jar User.class Beheerder.class Operator.class Manager.class MaakVisueelSchema.class
it makes a executable jar file which actually works! :)
But when the Operator class trys to open the MaakVisueelSchema class the screen stays blank.
I can run MaakVisueelSchema with java MaakVisueelSchema.
So I tried to make an executable JAR that consists only of MaakVisueelSchema, the same way as I did for User:
Main-Class: MaakVisueelSchema
jar cmf MainClass.txt MaakVisueelSchema.jar MaakVisueelSchema.class
Then I get the error message:
Could not find the main class. Program will exit.
from the Java Virtual Machine Launcher.
The big difference between MaakVisueelSchema and the other classes is that MaakVisueelSchema contains a PaintComponent method and an ComponentListener. Is it possible that one of those creates the error?
Can anyone help me with this problem?
Thanks in advance!
Bye!Yes,
I tried:
jar xvf MaakVisueelSchema.jar
and it returns:
META-INF/
META-INF/MANIFEST.MF
MaakVisueelSchema.classN/G. You need to manually create a manifest file in a text editor, have it point to your main class, and enter it in your jar command as an argument. -
Large project in JBuilder 2007... How do I create an executable JAR?
First, I've googled quite a bit and keep getting thiings about "Jbuilder Application Wizard", etc... Well, I don't see any "wizard" menu in the version of JBuilder I'm using!
I'm using JBuilder 2007 Enterprise edition, however it's a trial version apparently. I'm not sure if that matters, and perhaps the functionality was taken out with the trial version..
Anyway, the issue is that I have a multi class (with one main function) program that I want to run (it's a command line based application) as an executable JAR file. The program uses LOTS of include statements including quite a few custom libraries ("external JARs") that I had to import.
Basically I want the application to do exactly what it does now when I hit the ol' "RUN" button. Except I want to be able to run it from a batch file with "java -jar (or whatever) myProgram".
Anybody have any experience with this type of thing?OK, here's what I've got:
I've got a jar file that contains:
1. a folder "importQD"
2. a folder called META-INF
3. a .classpath file
4. a .project file
Inside the importQD folder are my three .class files that are the classes I created myself.
Inside the META-INF folder is the MANIFEST.MF file which looks like:
Manifest-Version: 1.0
Main-Class: importQD.ImportQDInside the .classpath file we have:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path=""/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="C:\Programs\CMQualityDocumentImport\CMUploadInterface83.jar"/>
<classpathentry kind="lib" path="C:\Programs\CMQualityDocumentImport\DBCon.jar"/>
<classpathentry kind="lib" path="C:\Programs\CMQualityDocumentImport\SENAeMail.jar"/>
<classpathentry kind="lib" path="C:\Programs\CMQualityDocumentImport\SENAFileHandler.jar"/>
<classpathentry kind="output" path=""/>
</classpath>NOTE: All of the paths point at the .jar files as they are located on the machine the final version will be running on.
Inside the .project file we have:
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>importOldQD</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>Now, it would make sense to me that this should be all good to go, and that I should be able to run this via a command line now. When I try
java -jar importQD.jar I get a ton of various errors such as "Exception in thread "main" java.lang.UnsupportedClassVersionError: importQD/importQD (unsupported major.minor version 49.0) + a nice stack trace with a bunch of java.lang and java.net references.
What am I doing wrong?
Maybe you are looking for
-
I have changed my Apple ID in my iPhone 4S and iPad, but when I update my Adds on them, they prompt me to enter the old Apple ID and password. I have already created the new Apple ID. How can I delete the old Apple ID on them?
-
Hi All, Any one know how the system set net value in sales order item? (VBAP-NETWR) I mean, what kind of condition type will be considered in net value calculation. Thank you
-
Creating graphics 720p60 - DVCPRO HD
Hello everyone. I am new to these forums, and Final Cut Pro in general. I have someone who needs me to make some graphic slides for them using either Photoshop, Powerpoint or Illustrator (whatever you users think is best for this job)... When I creat
-
How do I get my iMessage to be Separate from IPhone and MacBook ?
How do I get my iMessage to be Separate from IPhone and MacBook ?
-
HT1688 i forgot my passcode for my iphone 4
I forgot my passcode for my iphone 4