How do you execute a JAR file?

I'm sorry this is so basic, but I honestly do not know how to do this nor can I find anything online here or anywhere via Google to help me with this one.
I have a JAR file that I created on another machine using JDK 1.6.0 and NetBeans 5.5 on WinXP.
I copied and pasted that JAR file over to my machine at home also using JDK 1.6.0 and NetBeans 5.5 on WinXP
I put the exact directory name where the JAR file resides, "C:\Program Files\Java\jdk1.6.0\classes", in CLASSPATH and rebooted my machine.
However, upon CD'ing to that directory and doing "java -classpath . GUI.jar", I get a "NoClassDefFoundError" when trying to do so.
Furthermore, I was not sure how to use NetBeans to run the JAR file to execute the classes within.
What did I do wrong? I'm so sorry this is so basic.
Thanx
Phil

You are using netbeans to build your jar. Go to your project properties (right click on the project name and choose properties). Then select "Run" from the tree. You will find a text box "Main Class" there, put the name of the class in there that has your main() method, including full package if you have one. That is WITHOUT the .class extension.
Build your jar, it will be placed in the dist directory of your netbeans project. You can now run it from netbeans itself if you want. If ever you want to run the jar from the command line on your home machine, just navigate to the directory with the jar file and execute this:
java -jar yourjar.jarand you're off. If your runtime environment is propertly setup you can even execute the jar by simply double clicking on it from the windows explorer. No need to change the CLASSPATH variable at all, in fact it is ignored when executing a jarred application.
Also a note: you do not need to reboot your machine when you change an environment property. Simply change them using my computer -> properties -> advanced tab -> environmental variables. If you have any command prompts open, close and reopen them so the properties are updated properly.

Similar Messages

  • How do you create a jar file in JDeveloper 11.1.2.0.0

    How do you create a jar file in JDeveloper 11.1.2.0.0

    1) Select the project for which you would like to generate the jar.
    2) Right Click the selected right and select 'Project Properties'
    3) Select the 'Deployment' in the left tab.
    4) Click on 'New' to create a new deployment profile and in the popup dialog, select 'Jar File' profile type and provide the name.
    5) Press 'ok' to save the changes.
    6) Select the project and right click and select 'Deploy to' and select the jar profile name you have specified.
    The Jar library is generated and the full path to the library jar is shown in the log window.
    Thanks,
    Navaneeth

  • How do you convert a jar file into a java file,  ?

    how do you convert a jar file into a java file ?
    I am new to Java ,but have a little experience in C++ and Visual Basic.
    I want to edit and maybe create my own mobile games that are written or converted into jar files.
    At the moment I am using Java NetBeans , and Easy Java( the java pad).
    However the only solution I tried was to open the JAR file in winrar and see that its made up of png picture files,
    midi music files and class files. Unfortunately when I uncompressed the JAR file , there was NO java file to be seen and the JAVA editors Do not show the class file like a Java file. So why is there no extension Java file in the mobile JAR game ?

    801283 wrote:
    how do you convert a jar file into a java file ?You generally don't. There exist decompilers, but if you're meant to have the source, you should either have it because you are the author, or you should be able to get it from the author.
    I am new to Java ,but have a little experience in C++ and Visual Basic.Does that experience include turning .exe files into C++ code? Because that's the equivalent of what you're asking
    I want to edit and maybe create my own mobile games that are written or converted into jar files.Eh?
    Are you saying you want to take existing games and modify them? If the creators allow you to modify their source, then they'll provide you with that source (the .java files). If you're allowed to add things but not modify, you don't need .java files. Just documentation, which, again, the creators should be providing.
    Or are you saying you want to create your own games and distribute them in jar files? If so, there's no need to turn jars into .java.
    However the only solution I tried was to open the JAR file in winrar and see that its made up of png picture files,
    midi music files and class files. Unfortunately when I uncompressed the JAR file , there was NO java file to be seen and the JAVA editors Do not show the class file like a Java file. So why is there no extension Java file in the mobile JAR game ?Why would you expect there to be one?

  • How do you make a jar file for your program?

    Title says it all - I don't have software that automatically does it for me.
    Using text pad :O

    Everything you always wanted to know about JAR files, but were afraid to ask:
    http://java.sun.com/docs/books/tutorial/deployment/jar/index.html

  • How do you create a jar file with txt and classes?

    Hey, I'm trying to create code to create a jar file with a text file, but I can't figure out how to add the text file. Here is what I have so far:
    try {
                // Name of jar file to write
                String archiveFile = "test.jar";
                Manifest jman = new Manifest();
                try {
                    // Create a manifest from a file
                    //InputStream fis = new FileInputStream("manifestfile");
                    //Manifest manifest = new Manifest(fis);
                    // Construct a string version of a manifest
                    StringBuffer sbuf = new StringBuffer();
                    sbuf.append("Manifest-Version: 1.0\n");
                    sbuf.append("Ant-Version: Apache Ant 1.7.1\n");
                    sbuf.append("Created-By: 1.5.0_19-137 (Apple Inc.)\n");
                    sbuf.append("Main-Class: Main\n");
                    sbuf.append("Class-Path: lib/swing-layout-1.0.3.jar\n");
                    sbuf.append("X-COMMENT: Main-Class will be added automatically by build\n");
                    // Convert the string to a input stream
                    InputStream is = new ByteArrayInputStream(sbuf.toString().getBytes("UTF-8"));
                    // Create the manifest
                    jman = new Manifest(is);
                } catch (IOException e) {
                FileOutputStream stream = new FileOutputStream(archiveFile, true);// archive file is jar file name
                JarOutputStream out = new JarOutputStream(stream, jman);
                out.putNextEntry(new JarEntry("test.txt"));
                out.closeEntry();
                out.close();
            } catch (Exception ex) {
            }It creates the .jar file with the correct manifest but I can't get it to write the test.txt or anything else into the jar file.
    -Gandolf
    Edited by: GanMatt on Jun 18, 2009 8:18 AM
    Edited by: GanMatt on Jun 18, 2009 8:19 AM

    Alright, my question has changed. Here's the code:
    try {
                // Name of jar file to write
                String archiveFile = "test.jar";
                Manifest jman = new Manifest();
                try {
                    // Create a manifest from a file
                    //InputStream fis = new FileInputStream("manifestfile");
                    //Manifest manifest = new Manifest(fis);
                    // Construct a string version of a manifest
                    StringBuffer sbuf = new StringBuffer();
                    sbuf.append("Manifest-Version: 1.0\n");
                    sbuf.append("Ant-Version: Apache Ant 1.7.1\n");
                    sbuf.append("Created-By: 1.5.0_19-137 (Apple Inc.)\n");
                    sbuf.append("Main-Class: Main\n");
                    sbuf.append("Class-Path: lib/swing-layout-1.0.3.jar\n");
                    sbuf.append("X-COMMENT: Main-Class will be added automatically by build\n");
                    // Convert the string to a input stream
                    InputStream is = new ByteArrayInputStream(sbuf.toString().getBytes("UTF-8"));
                    // Create the manifest
                    jman = new Manifest(is);
                } catch (IOException e) {
                FileOutputStream stream = new FileOutputStream(archiveFile, true);// archive file is jar file name
                JarOutputStream out = new JarOutputStream(stream, jman);
                out.putNextEntry(new JarEntry("test.txt"));
                out.write("Hi".getBytes());
                out.flush();
                out.closeEntry();
                out.close();
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this,ex.toString(),"BUG!",JOptionPane.INFORMATION_MESSAGE);
            }It creates the jar file with the txt file inside it, but I can't write "Hi" inside of the text file. Any ideas?
    -Gandolf

  • How to execute a jar file which has an applet, without using a html file ?

    I have a jar file which contains a set of class files. iam able to execute the jar file by using this html code
    <html>
    <applet code="file.class" archive="file.jar" width="500" height="300">
    <param name="name" value="value">
    </applet>
    </html>
    I want to know how to execute this class file without using the html tags.
    pls help me out in this.
    Anki

    Hi,
    You can make an executable jar file such that when you double click on that it starts running. Just follow the steps.
    1. Open a notepad and write the following
    Main-Class: XXXXXXXX
    XXXXXXX means Your Main Class name. Don't forget to press Enter after you write your class name.
    2. Save the file as Mani.mf
    3. In the commant prompt ( your directory ) type following lines.
    jar cmf Mani.mf Demo.jar *.*
    4. This will make a jar file which is executable jar file
    Hope this will help you.
    Deepak

  • How to execute a jar file in other machine?

    Hi all,
    I am working with java. and my machine is connected to LAN.I would like to execute a jar file in my machine from a remote machine that is also connected to LAN.how should i go about doing this.Help me if somebody have a solution as i am badly in need of this.
    Regards,
    Mohan

    Hi Mohan.tkm,
    If you want it to be done in pure Java and independently of the OS of both computers, you may build a RMI server that will launch your JAR by request of a remote RMI client.
    There's an example of RMI here .

  • How to execute a jar file in a java application

    Hi,
    I've already try to execute a jar file by this way :
    Runtime.getRuntime().exec(java -jar myJarFile.jar);
    But the problem is that the display doesn't launch. Normally a "JFrame" display.
    however the corresponding process is launched.
    So i would to know if there is a way to execute a Jar File without using the Runtime class.
    Is there a specific class for the Jar File?
    Thank you.
    Richard

    Create a 'manifest' file pointing to the 'main' class, jar it into the .jar file, place it onto your desktop - or whereever you can click on it, and click on it.

  • How can I create a jar file

    Hello!
    How can a create a jar file?
    I want to run an application just clicking in a icon.
    How can I do this?
    Thanks a lot.
    K�tia.

    Get to the command prompt
    change directories to the directory where the main class resides.
    Open your text editor and type the following in it:
    Manifest-Version: 1.0
    Main-Class: NameOfMainClass //Just name without ".class"!!!
    Created-By: Your Name Here
    Save this file as whatever you want to name it with ".mf" as the extension.
    Then go back into the command prompt and type the following:
    jar cfm "NameOfJarFile".jar "NameOfManifestFile".mf *.class
    (without the quote marks of course)
    Hit "Enter"
    This will jar it up and make it executable.
    If you have any images associated with the program you can add them in the same way as above. Just add *.gif or *.jpg after the *.class portion.
    Good luck!
    LEEMAX I. T.

  • How can i run a jar file as EXE on mouse click..

    *{color:#0000ff}how can i run a jar file as EXE on mouse click..is it possible in any way?????????{color}*

    amrit_j2ee wrote:
    *{color:#0000ff}how can i run a jar file as EXE on mouse click..is it possible in any way?????????{color}*Do you mean converting it from a jar file to an EXE file or do you mean that you would like to run the application by just double clicking it?
    If it's the latter then you need to make the jar file including a manifest.
    The manifest can be just a txt file with its content to be something like this:
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.7.1
    Created-By: Somebody
    Main-Class: NameOfTheMainClass
    Class-Path:
    X-COMMENT: Main-Class will be added automatically by buildTo make the jar file including the manifest, use something like this in your command prompt (of course you must have compiled your java file(s) first):
    jar cfm test.jar MANIFEST.txt NameOfTheMainClass.classAfter that you'd be able to run your application just by double clicking it.
    If you're a NetBeans user, you can build your standalone application by right-clicking your project and then going to properties => run => and choosing a Main class. After that right click on that project and "Clean and Build", locate the jar file in the "dist" folder and double click it =]
    Hope it helps,
    LD

  • How to access classes in jar files

    hi I have added a jar file to my project in eclipse.How to access the classes in that jar file?

    cu is right.
    classloader returns the URL of your resource. You can the jar using something like the following...
    ClassLoader classloader = this.getClassLoader();
    url = classloader.getResource("your_resouces...");
    if(url == null)
    System.out.println("cannot find resource ");
    return null;
    String jar = url.getFile();
    jar = jar.substring(jar.indexOf("/")+1, jar.lastIndexOf("!")).replace('/', '\\');
    obviously, this code snippet works on windows only. Now you have the jar file path. I use Jar file classes to access the jar file. (e.g. you can search for each class files)
    Ming

  • How can I create a jar file that will run automatically on double click

    all the jars I created run only from the command-line.
    how can I make it run by double-click on it?

    First you will need to associate .jar files with the javaw.exe program in order to just be able to double click on the jar and run it from within a windows explorer application. Next you will need to set the main class attribute of the manifest file. My understanding is that the value of this attribute is used by the launcher to know which class to load. In other words, which is your main application class. To specify this attribute open your manifest file in a text editor. You will find this file located within the jar at META-INF/MANIFEST.MF. Then, add the line,
    "Main-Class:<relative path to the main class>" However, remember not to add the .class extension to the end of the class name.
    In Windows 2000 you can associate jar files with javaw by finding a jar file in Windows Explorer and right clicking it. This will give you a context menu which should have an Open With... option (if you are not using Windows 2000 and don't see the 'open with' menu item, try holding down the shift button while right click on the file). Select the Open With... option, then, when the dialog appears highlight javaw and select the "Always use this program to open these files" checkbox. When you hit the OK button you should have all your jar files associated with the javaw process.
    Once you've done this, you should be able to double click on your jar file and run your application.
    Regards,
    Daniel Walsh

  • How to call function in jar file?

    First, I can't write english well.(I'm korean.. ) sorry about that.
    I have known function in jar file.
    but I don't know how to call function in jar file.
    how can I this work?
    My project and another project are respectively developing D-project with me and other man.
    so i need it. or I can't do this work.
    I will paste other's source code in my source code.
    and then recomplie , build it.. but it is not my wish!
    thanks for reading my sentence.

    If you have a jar file with a class that you wish to use, then you must add the jar file to your class path ($CLASSPATH on unix, linux, etc. and %CLASSPATH% on Windows).
    Then you can use the class normally, just as you would if it were not in the jar.
    If you meant something else, you'll need to explain what you meant.

  • How to add the mail.jar file to my CLASSPATH ?

    Hi;
    I wish to Instal JavaMail 1.2
    To use the JavaMail 1.2 API, i unbundle the javamail-1_3_1-upd.zip file.....and now, i would like to add the mail.jar file to your CLASSPATH.
    My question is: how do you do this ?
    - ok i did that for CATALINA_HOME & JAVA_HOME but how to add the mail.jar file to my CLASSPATH ??
    1000 thanks.

    I think you're looking for "developer support", not packaged application support. different server, different batch of groups. . .
    Since I have very little contact with devopers, I don't truly know.

  • Exception is thrown only while executing the jar file

    java.lang.NoClassDefFoundError: javax/mail/Address Exception is thrown only while executing the jar file. But the program compiles and executes good when executed for command prompt through the class files.
    I used javamail API in my program. Classpath and every others are set to the right one's. Executed fine when used java Random.class. But the problem is only with the jar file.
    Please help me out in this regard. Why the exception is thrown only in jar but not at class level.

    Assuming you're running your program using "java -jar", your jar file needs a Class-Path entry
    in the manifest file that references mail.jar.

Maybe you are looking for

  • How to eliminate unwanted text in Form

    hi,   How to eliminate unwanted text in Form. Regrds, bbr.

  • JSF own component

    Hi. I am developing own JSF component, something like Switch compoennt which have oracle - ADF Faces Components. On JSF page will be this tag: <s:switch value="facet2"> <facet name "facet1">..... </facet> <facet name "facet2">.....</facet> </s:switch

  • Forget to run depreciation in last year

    Hi all, We forget to run depreciation for Dec 2008 after the GR was reversed that month. We want to post the depr. in this month (Jul 2009). If it must be posted in 2008, what adjustment we can do? [http://www.markpeak.com/temp/asset1.jpg] Thanks you

  • Execution times of SQL Queries

    Hello everybody, I have a strange behaviour on my Sun. PHP 4.2.2, solaris 2.8, Oracle 9iR2. I have a bunch of statements, executed in SQL-Plus they take about two seconds. Executed via PHP, the time the OCIexecutes take are more than twelve seconds.

  • Mac Mini will NOT Load

    Hello Happy Mac People. I am currently having issues with my Mac Mini. Currently, in it's Superdrive Slot rests a disc that was meant to install a Microsoft Keyboard and Mouse combo that was wireless. I know what you are going to say. Microsoft equip