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.

Similar Messages

  • 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

  • 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.
    Thanks

    i 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

  • 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
    Oliver

    Three 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

  • Create Executable Jar file

    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 you

    thank 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

  • 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?
    Cheers

    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?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
    -Ron

    Rony,
    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!

  • 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...

  • Jar File Problem Using External Packages

    I am having problems creating an Executable jar file that imports classes from my own package.
    I can create an exe jar no problem without using any external packages, but when I use an external package the jar will not execute.
    I am using WindowsXP, my package is in,
    C:/MyClasses/Database
    the class files are stored loose, not in a jar file
    I have tried altering the class-path in the manifest file, but to no joy - I may have not changed the classpath correctly!
    Please help
    Magic

    This is a mine field of "correct programming style."
    External jars, if very general, could be placed in the directory jre/lib/ext.
    In some cases you can unzip the external jars and add them to your own jar.
    The manifest.mf migth be looked into, and of course you need to communicate your patching!
    As you remarked, it might be a problem of class path usage.
    For that the jar tool documentation might explain it better than I.

  • Including a jar file inside an executable jar file

    Is it possible to include a jar file inside another (executable) jar file such that the included file is part of the class path for the outer file? If so, how do you specify this in the classpath in the manifest?

    Russ_Bjork wrote:
    Is it possible to include a jar file inside another (executable) jar file such that the included file is part of the class path for the outer file?No. Actually, I suppose it would be possible if you do all the 'heavy lifting', but Java is not designed to handle Jars within Jars.
    What do you see as the advantage of doing that?
    Is your app. a rich client (e.g. Swing, AWT, SWT..)?
    Can you distribute the app. from a server or the internet?

  • 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

  • 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
    AE

    java 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

  • 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

  • My iTunes library is on a 2T ex. hard drive. I want to install on new PC w/o losing playlists,

    My current iTunes library is on a 2T external hard drive, using a PC with Vista. I am wanting to move the entire library HD to a new PC running Windows 8 without losing my playlists, date added, last played, # of plays, etc. However, when connected t

  • I am using IFrame and displayed Html page

    Hi Friends                     I am using IFrame and displayed Html page in flex4                     In this page open to Firefox But not IE please help me.                       Thanks                        V.ChandraSekhar

  • Adobe FC crashes on startup

    Hi all, I'm new to this forum, so please forgive me if I make any noobish mistakes. When I subscribed to Creative Cloud, I noticed that FC was automatically installed, which I didn't mind because I was planning to start using it. Yesterday when I boo

  • Reporting based on master data

    Hi, I have loaded master data from sap-r/3 to sap-bw. now  i want to make report on that , how to make report ? Thanks.

  • Extracting Colors in Motion

    Hi there, I'm currently working on a new project where I did an interview with a guy who has a lot of tattoos on his arms and what I'm trying to achieve is to get all the footage in black and white expect all of his tattoos kept the original colors.