Including libraries in executable jar

Hi,
jdeveloper 11.1.1.3 here. I have wrote a one-class application, which uses the jdbc oracle driver to connect to a database. I want to make an executable jar of this application. I have succesfully imported the driver in my jar file, but in the manifest file, no classpath entries are added, making the application cast a classnotfound exception on startup.
I followed this tutorial http://blogs.oracle.com/olaf/2008/01/
and this thread jdev and jar file
but they didn't work for me.
what should i look at?
Thanks in advance

You have to make the entries in the manifest file yourself. JDev will not do it automatically. Create a file (e.g. mymanifest.mf) and include it in your deployment profile in the manifest section.
In This file you enter the needed jars like:
Class-Path: ./lib/ojdbc14dms.jar ./lib/dms.jar ./lib/ocrs12.jar ./lib/ojdl.jar ./lib/orai18n.jar
Save the file and deploy the jar.
Timo

Similar Messages

  • Including jars into executable jar

    Hello
    I want to create an application in one application even if this application depends by many other jar libraries.
    So , my development process resulted into one library: myapp.jar
    This application depends by other jars: lib1.jar, lib2.jar, lib3.jar,
    If I'll create one big jar archive with my classes and these libraries doesn't work (even I'll specify in manifest file all tags:
    Class-Path: lib1.jar lib2.jar lib3.jar
    Main-Class: com.snt.xdoc.MyApp
    So, it is possible to create one single JAR archive including all resources (my interesting point is to include jar libraries) and executable class to know where are these resoures (to establish corectly the classpath)?
    Thank you

    Hello Stefan
    Other topics about this problem can be found here:
    http://forum.java.sun.com/thread.jsp?forum=22&thread=405160&tstart=0
    http://forum.java.sun.com/thread.jsp?forum=4&thread=432114&tstart=0
    But you might want to take a look at META JAR UTILITIES : http://www.yagga.net/java/metajar/
    "Three classes with full source code and documentation that allows to extract resources from a file, from inside a JAR file that is currently executing (java -jar foo.jar), from a JAR that is included in the aforementioned executing JAR and to define a classLoader that can work with JARs, even if those JARs are JARred inside the currently executing JAR."
    MetaJarUtilities are being distributed with full source code under GNU's General Public License.
    For the moment being a JAR structured like this works:
    FOO.jar
    +- SuperMetaJarTest.class (uses BootstrapJarClassLoader.class)
    +- net/
    | +- yagga/
    | +- util/
    | +- BootstrapJarClassLoader.class
    |
    +- metatest.jar (content below)
    | +- net/
    | | +- yagga/
    | | +- util/
    | | +- Meta Jar Utilities classes here...
    | +- jars/
    | | +- test.jar
    | +- TestmetaJar.class
    | +- text.txt
    |
    +- jars2/
    +- test2.jar
    Good luck!

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

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

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

  • Including a DLL in JAR file (Comm API)

    Writing a little app that interfaces with serial port device using the communications API and I'd like to bundle it into an executable JAR. JBuilder will create the JAR for me fine, but the issue is with the win32com.dll file thats part of the comms API. I need to include this, I don't think its possible to include as part of the executable, but otherwise the DLL needs to be in the windows\system folder. Could I include the dll as part of the JAR archive and then extract it upon runtime? If so how would I go about this?
    Any help much appreciated.

    There is another option. Native libraries need to reside within the java.library.path location. As it turns out, if you, at runtime, grab this property and ADD your own location to it, then set it back in to the System.setProperty() call, it will NOT work. The only way to do it is the -Djava.library.path value that tjmaven suggested.
    However, if you read up on how a native library is found, it uses the ClassLoader.loadLibrary() which calls the protected findLibrary() method. You can therefore extend ClassLoader to find a path yourself.
    One way is to extend URLClassLoader since it has the protection/security stuff AND the ability to look in .jar files for you. Your custom loader is created by a "launcher" class in your .jar file. First, your luancher uses getClass().getProtectionDomain().getCodeSource().getLocation() to get the absolute location of the .jar file its executing within. From there, you open the jar and look for your native library, extract it using the JAR api to a location of your choosing. Now, you instantiate the custom classloader and using this custom loader instance you load the rest of your classes. The main .jar file contains two classes, the launcher and the custom classloader, and contains the native library if you wish to do it this way. The custom classloader, you specify a URL[] of "classpath" entries. You bundle up the rest of your source in a second .jar file that you pass to the URL[] when creating the custom classloader. It will find all your classes in the 2nd jar no sweat. You can even "reload" these classes on the fly by recreating the custom classloader instance if you so wish to add a sort of "reload" feature.
    Now, in your custom classloader, you override the findLibrary() and return the SAME STRING PATH that you used to unjar your native files to. This way, when the JVM asks your custom loader to load the library at some path, you return the right path to find the native files in.
    I haven't verified that this works just yet, but I will soon. Primarily, my plugin engine over at www.platonos.org will support the ability to place native libraries in plugins, allowing you to effectively wrap a native library use as a plugin. Not yet working, but we'll soon have it in place.

  • SWT Runs in Eclipse - Not after export (NOT executable JAR)

    I have been working on my first SWT application. It will run when using the Eclipse run command. However, when I export the project to a JAR file I can't get the module to run. I am NOT trying to run this as an executable JAR. I will eventually get to that, but for the moment I just want to be able to execute the module via the standard Java command.
    When I try to run the module via:
    java com.myproj.visual.SearchDisplay I get the following result:
    NoClassDefFoundError:  org/eclipse/swt/widgets/LayoutI have tried every variation of running this that I can find. I have the swt.jar as well as the jar containing my project files in the class path. I have extracted the DLL files from swt.jar and put them in the directory from which I am executing the module, i.e. I change directory to there before executing the Java command. I tried including the following in the Java command:
    -Djava.library.path=c:\projects\java\myproj\swt-win32-3139.dllI have also tried including the classpath at the Java command:
    -classpath .;c:\projects\java\myproj\swt.jar;c:\projects\java\myproj\mmstat.jarSo far nothing has helped. I get the same error regardless what I do. Yet this runs fine inside Eclipse.
    In my Eclipse environment I do have swt.jar imported. And have org.eclipse.swt in my Require Projects tab on the Build Path. I also have swt.jar and Standard Widget Toolkit identified in the Libraries tab of the Build Path. And on the Order and Export tab I have tried including all three (Standard Widget Toolkit, swt.jar and org.eclipse.swt) and then each one separately and then in combinations.
    It is obvious that I am not exporting correctly or I don't have the correct configuration at runtime. But I can not figure this out. I have been reading forums for days now. They mostly are concerned with excecutable JARs which is not yet my problem. I first need to get this working before worrying about packaging an executable.
    Can someone please help suggest some solutions for me?
    It would be GREATLY appreciated.
    Glenn Puckett
    Lexington, KY

    Making a jar file from SWT project, in Eclipse:
    1. Create one manifest file in project with following contents:
         Manifest-Version: 1.0
         Class-path: swt.jar
         Main-class: package.MainClass
    2. Export jar file with this manifest file
    a) Right-click on project
    b) Selection Export
    c) Select Java and Jar file
    d) Select the project, classpath and file project
    e) In jar file textbox enter the name for jar file and select options: "Exports generated class files and resources" and "Compress the content of the jar file"
    f) Press Next button
    g) Press Next button
    h) Select "Use existing manifest from workspace" and select the manifest file which you has created
    i) Press Finish button     
    3. Put togheter the jar file and swt.jar
    4. Run jar file

  • Cannot make executable jar file for swt application

    hi to all!!! i have started learning swt library and it seems nice to me, but i have one problem, i cannot run my application. The problem is that i cannot make executable jar for it.
    i'm using ecilpse_3.1.2 and have pluggined the visual editor for swt! yesterday i found one topic where was described the process of making the swt executable jar, i followed the instructions in the topic, but didn't resolve my problem, so if anybody knows how to achieve this , please help!!!!!!
    the instructions in the mentioned topic are :
    1. Make sure the SWT jar file is included in the Eclipse project build path
    a. Download the standalone SWT jar file from eclipse.org even if you already have the ones that come with Eclipse. It is called ?swt.jar? and you will package it with the executable JAR. Make sure it is the same version of SWT that you used to make your program.
    b. In Eclipse, import swt.jar via Project Properties::Java Build Path::Libraries::Add External JARs. (Make sure to include the source .zip file). Also make sure to select the swt package in the ?Order and Export? tab.
    c. At this point, you should be able to compile and run your SWT application in the Eclipse SDK.
    2. Do a standard Eclipse jar file export
    a. Right click on the main .java project file and select ?Export??.
    b. Choose ?JAR File? from the list.
    c. Select the relevant packages and .classpath and .project resource files
    d. Make sure ?Export generated class files and resources? is selected and browse to the location where you want the JAR file to be created.
    e. Specify ?Generate the manifest file? and don?t seal the JAR or any packages. Choose the class containing the main method as the ?Main class?.
    3. Change the manifest file
    a. Navigate to the JAR file you created and open it with WinZip.
    b. Open the MANIFEST.MF file inside and copy the contents.
    c. Create a new file called ?MANIFEST.MF? and paste in the contents of the old manifest file.
    d. Add the line ?Class-Path: <swt jar file path>?. For simplicity, you can just keep a copy of the swt.jar file in the same folder as the executable jar, in which case, the line is ?Class-Path: swt.jar?. Make sure there is a carriage return after the last line in the manifest file, or that line will not be parsed.
    4. Replace the manifest file
    a. Make sure the manifest file and the executable jar are in the same folder.
    b. Open the command prompt and navigate to the containing folder.
    c. Enter the command ?jar umf MANIFEST.MF <executable jar name>? to update the manifest file with the class path information.
    5. Package the JAR with SWT files
    a. Put the updated executable JAR file, swt.jar, and the associate DLL in the same folder. The DLL can be pulled out of swt.jar and should have a name like ?swt-win32-####.dll? on Windows.
    b. The JAR file should now successfully execute. On Windows, you can usually just double click the JAR file in explorer and it will open. If that does not work, the command ?java ?jar <executable jar name>? on the command line has the same effect.
    but a few steps aren't exact for me , for example : first, which jar i have to include in build path : downloaded or from plugins folder, second
    i have to incude source.zip too??? but it is only in downloaded zip file which includes both swt.jar and src.zip, and finally can anyone clarify next :
    "5. Package the JAR with SWT files
    a. Put the updated executable JAR file, swt.jar, and the associate DLL in the same folder. The DLL can be pulled out of swt.jar and should have a name like ?swt-win32-####.dll? on Windows."
    what does this mean, put these in folder or make jar from them????

    wolve634 wrote:
    but a few steps aren't exact for me , for example : first, which jar i have to include in build path : downloaded or from plugins folder, secondTry it both ways. If neither works, then ask again. In a suitable forum, though. An Eclipse forum or an SWT forum or something related to where you got those instructions would make a lot more sense than asking here.
    i have to incude source.zip too???No, of course you don't have to distribute the source code.
    a. Put the updated executable JAR file, swt.jar, and the associate DLL in the same folder. The DLL can be pulled out of swt.jar and should have a name like ?swt-win32-####.dll? on Windows."
    what does this mean, put these in folder or make jar from them????It says "Put (them) in the same folder". You're asking whether that means to put them in a folder? Yes, it does.

  • Question about Executable JAR Files

    Is it possible to make an executable JAR file that has all of the *.class files, all of the *.jar archives used, etc. packaged into one file that doesn't need these external files within the same directory? I've been having a ton of trouble finding the answer to this. (If it's blatantly obvious, please forgive me.)

    Hello,
    I went through the same thing recently. Here is a piece of the build file I use:
    <project name="MyProj" basedir="." default="main">
        <property name="src.dir"     value="src"/>
        <property name="build.dir"   value="build"/>
        <property name="classes.dir" value="${build.dir}/classes"/>
        <property name="jar.dir"     value="${build.dir}/jar"/>
        <property name="main-class"  value="MyProj.Main"/>
        <property name="lib.dir"     value="lib"/>
        <path id="classpath">
            <fileset dir="${lib.dir}" includes="**/*.jar"/>
        </path>
        <target name="compile">
            <mkdir dir="${classes.dir}"/>
            <javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
        </target>
        <target name="jar" depends="compile">
            <mkdir dir="${jar.dir}"/>
            <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
              <zipfileset src="lib/commons-codec-1.3.jar"/>
              <zipfileset src="lib/commons-fileupload-1.1.1.jar"/>
              <zipfileset src="lib/commons-httpclient-3.0.1.jar"/>
                <manifest>
                    <attribute name="Main-Class" value="${main-class}"/>
                </manifest>
            </jar>
        </target>
        <target name="main" depends="clean,run"/>
    </project>Note the <zipfileset> tags that contain the .jars.
    There are, however, many good reasons to not do this. Some were already mentioned, another is in the case of update external libraries, you might not want to rebuild your whole project, replacing a jar may be easier.
    Good luck,
    -Sam

  • Links not working in executable jar

    I have a problem with my java application
    html and images files do not work in executable jar
    though the application works normally
    I tried some suggestion but I received an exception thread indicating problem at
    ImageIcon iChing = new ImageIcon(imageURL);
    Please could you help me thank you so much
    here is the class
    public class Main extends JFrame
    * objects required for the GUI: JFrame,JLabel, JButton, ImageIcon, JPanel,
    * Dimension
    private static final long serialVersionUID = 1L;
    JButton jbEnter;
    ImageIcon iChing, logo;
    JPanel buttonPanel, ImagePanel;
    JLabel jlbIching;
    Dimension dim;
    URL imageURL;
    File fileName;
    // Class constructor to create the GUI
    public Main()
    Container container = getContentPane();
    URL imageURL = this.getClass().getClassLoader().getResource("src/myFiles/iching.gif");
    ImageIcon iChing = new ImageIcon(imageURL);
    jlbIching = new JLabel(iChing);
    // button to go to the Title class
    jbEnter = new JButton("Enter ");
    jbEnter.setBorderPainted(false);
    jbEnter.setFont(new Font("Edwardian Script ITC", Font.BOLD, 42));
    jbEnter.setBackground(new Color(0, 0, 50));
    jbEnter.setForeground(Color.YELLOW);
    jbEnter.addActionListener(new ActionListener() {
    // method to render the current frame invisible and trigger the
    // Welcome Menu
    public void actionPerformed(ActionEvent e)
    setVisible(false);
    // this line does not work...............
    new Title();
    } // close the actionPerformed(ActionEvent e) Method
    }); // close the addActionListener(new ActionListener() method
    // Panel holding the decorative image and Button
    ImagePanel = new JPanel();
    ImagePanel.add(jlbIching);
    ImagePanel.setBackground(new Color(0, 0, 50));
    buttonPanel = new JPanel();
    buttonPanel.add(jbEnter);
    buttonPanel.setBackground(new Color(0, 0, 50));
    // setting up of the panels position
    container.add(ImagePanel, BorderLayout.CENTER);
    container.add(buttonPanel, BorderLayout.SOUTH);
    dim = Toolkit.getDefaultToolkit().getScreenSize();
    dim.width = dim.width / 2 - 300;
    dim.height = dim.height / 2 - 250;
    setBounds(dim.width, dim.height, 400, 400);
    setSize(600, 500);
    setResizable(false);
    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //To set the icon for the application. Top left hand corner.
    //this.setIconImage(Image);
    setIconImage(new ImageIcon("src/myFiles/ichingRose.gif").getImage());
    } // close the Constructor
    * the main method for the program.
    * @param args
    * The command-line arguments.
    public static void main(String[] args)
    new Main();
    } // close the main method
    } // close the Main class

    Thank you very much for your quick reply and really hope you can help me a little more
    it's so frustrating
    I do not really know about the relative path but here is my xml file
    <?xml version="1.0" encoding="UTF-8" ?>
    <project default="jar">
    <!-- Compile and zip the source code into a jar -->
    <target name="jar">
    <!-- Make the folders we'll need -->
    <mkdir dir="ant"/>
    <mkdir dir="work"/>
         <mkdir dir="ant/myFiles"/
    <!--
    Compile all the .java files into .class files
    debug = yes Include debug information in the .class files
    destdir Where to put the .class files
    source and target Use Java version 1.6.0_06
    -->
    <javac
    debug="yes"
    destdir="ant"
    source="1.6"
    target="1.6">
    <!-- Folders that have trees of .java files to compile -->
    <src path="src"/>
    </javac>
         <copy todir="ant/myFiles"><fileset dir="src/myFiles"></fileset></copy>
    <!--
    Zip files together to make a jar
    jarfile Where to make the .jar file, overwrite something there
    basedir Find the files to zip in the jar here
    -->
    <jar
                   jarfile="work/BookOfChanges.jar"
    basedir="ant"
    >
    <!-- Write a manifest inside the jar -->
    <manifest>
    <!-- The class Java will run when the user double-clicks the jar -->
    <attribute name="Main-Class" value="iChing.Main"/>
    </manifest>
    </jar>
    </target>
    </project>

  • Class not found error while executing jar file

    I have written a java code in which i am connecting to database....when i run the class file using......java class_filename it works........
    but when i run the jar file using .......java -jar jar_name ...yi gives me the error as 'Class not found'......
    can anybody help me please......
    Thanks and Regards,
    Siddhesh

    that class is part of jar file.....in classpath i have included zip files for jdbc ...to get databse connection.....and the jar being executed ................still it gives the error ClassDefnotfound which i think is due to database connection problem.....the exception is raised while.....
    Class.ForName("Driver_name").newInstance();/ This driver is present in zip files that i have added in classpath....
    above statement doesn,t giv error while i execute the class file............but exception while executing jar file only..
    Thnaks and regards,
    siddhesh

  • FileWriter in executable jar

    I have a problem to read/write textfiles inside an executable jar.
    The problem exists when the files are included in the jar.
    E.g. writing to files outside the jar is fine and currently my solution is to keep them that way.
    At first I also had a problem pointing to images in the
    jar-file but it worked with something like the following:
    img=java.awt.Toolkit.getDefaultToolkit().getImage(getClass().getResource("example.gif"));
    I tried the same approach to the FileReader like this:
    FileReader fr=new FileReader(getClass().getResource("example.dat").toString());
    The application compiles fine but does not find the file.
    Please share your expertise with me.

    You have to use external files or play with the java.util.jar package - there is not support for writing things directly to a jar in the java.io package.

  • How do i create an executable jar?

    I have built a GUI, and want to make it executable. I have tried compiling it to a jar, but when i double click this nothing happens. I even added Main-Class to the manifest file but still no luck.
    any help would be appreciated, or a link to a good tutorial. I have already tried the sun tutorial, but it still doesnt work.
    Thanks
    Ben

    I got it working :D
    jar -cfm TestJar.jar manifest.txt GUI.class GUI$1.class ./org/gui/*.class ./info/clearthought/layout/*.class
    java -jar TestJar.jar
    This created the .jar. I will experiment with Class-Name: later, atleast i have something to show now.
    Thanks to everyone for their help on this matter
    Ben
    edit:
    just changed the manifest file to include,
    Class-Path: JCalendar4.jar TableLayout.jar
    Worked a dream..... thanks everyone i think i have a pretty good grasp on how to create jars now. Just need to learn now how to create jnlp files :D
    Message was edited by:
    CyborgAvenger

  • How to create executable jar in eclipse using linking in compiler

    Hi,
    I have a project in Eclipse. I wrote already an ant build file for creating an executable jar which includes all project files.
    Now I want to create a second executable jar which is a subset of the project (a limited number of classes are necessary).
    I have a main class and I was looking for a way to generate a jar file which includes the main class and all the depending classes.
    Is there a way to do it? With ant or with another tool?
    Is it possible to compile a project given a main class, and include all depending classes?
    Regards,
    Biebel
    Edited by: biebel1975 on Jan 7, 2009 10:21 AM

    biebel1975 wrote:
    Some more information:
    When I compile all the classes, the jar file is +/- 3.5Mb inclusive the server side logic.
    The subproject I want to build, should be less then 1Mb (Only some screens and beans, no business logic ((only +/- 10% of the projects code) )).
    My question is: How can I create a executable jar with only the necessary class files which depends on the main class. (Linked with the imports).
    Is there a tool to do that? Can it be done with an ANT script? If so, how does the script looks?
    What are you talking about?
    You already said that you are using Ant.
    Ant uses script files.
    Since you have one with X items in it and you want something new with X-Y items in it the obviously it would make sense to construct an ant script that does less than the other ant script.
    The following provides a huge amount of information about Ant.
    [http://ant.apache.org/resources.html]
    Other than that no one can tell you want your Ant script will look like except that it will do less than the one that you already have.

  • Executable JAR containing images doesn't load them

    I'm using Netbeans 4.0 for developping a Java Application. This application is composed of 3 packages:
    - daemonexplorerv10: which contains the main class.
    - GUI: which contains classes I use to create the GUI of the application.
    - images: which contains GIF and PNG images used by the application. It also contains a class named ImageLoader which is used to load the images contained in the package. I will detail this class later.
    My main class, named Main.java, simply lauches the main JFrame of the application GUI. Here is the code of it's main method:
    public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    MainFrame.createAndShowGUI();
        }In the GUI package, I created a class named MainFrame which extends JFrame and is the main frame of my application GUI. Here is the code of it's method createAndShowGUI:
        public static void createAndShowGUI() {
            //Suggest that the L&F (rather than the system)
            //decorate all windows.  This must be invoked before
            //creating the JFrame.  Native look and feels will
            //ignore this hint.
            JFrame.setDefaultLookAndFeelDecorated(true);
            //Create and set up the window.
            MainFrame main_frame = new MainFrame(main_frame_title);
            main_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            //Display the window.
            main_frame.pack();
            main_frame.setVisible(true);
        }And here is the beginning of the code of it's constructor:
        public MainFrame(String title) {
            super(title);
            ImageLoader il = ImageLoader.getSingleton();
            ImageIcon application_icon = il.loadImage("application_icon.png");
            if (application_icon != null) {
                this.setIconImage(application_icon.getImage());
            else {
                System.out.println("Error - application_icon could not be loaded");
    ...As you see, MainFrame uses ImageLoader so as to customize the frame icon. ImageLoader follows the singleton pattern. It has a method called loadImage which returns an IconImage for a given image name. Here is the code of this method:
        public ImageIcon loadImage(String image_name) {
            ClassLoader cldr = this.getClass().getClassLoader();
            URL image_url = cldr.getResource("\\images\\"+image_name);
            if (image_url != null) {
                return new ImageIcon(image_url);
            else {
                return null;
        }For every image I want to use in my application, I use ImageLoader. It fetches the image thanks to the given name, provided that the image is placed in the package called images, or else the method loadImage returns null.
    So the MainFrame uses ImageLoader which fetches the image "application_icon.png" for the frame to set it as it's custom icon.
    My application runs perfectly well :)... as far as I run it through Netbeans launcher. But Netbeans also creates automatically an executable JAR file for each builded application. So I tried to lauch this JAR. Through this way, the application works, but all the images that should be loaded aren't!
    I unpacked the JAR so as to check if all the images are in it. Netbeans includes the images. Netbeans also creates a manifest file which seems perfectly correct.
    So I can't understand why my application runs without any images when I launch it through an executable JAR while it works fine (with all the images) when I lauch it through Netbeans.
    I checked many forums to find a solution. Using ImageIO doesn't or ToolKit doesn't solve the problem. It simply seems that the path of the package called images can't be found by the method getResource when this package is compressed in the JAR.
    P.S: I use J2SE Development Kit 5.0 and J2SE Runtime Environment 5.0.

    So ReinerP, I tried your code today in a little test application which has a single package containing two classes:
    - Main.java
    - JMainFrame.java
    Here is the code of Main.java:
    public class Main {
        /** Creates a new instance of Main */
        public Main() {
         * @param args the command line arguments
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    //Suggest that the L&F (rather than the system)
                    //decorate all windows.  This must be invoked before
                    //creating the JFrame.  Native look and feels will
                    //ignore this hint.
                    JFrame.setDefaultLookAndFeelDecorated(true);
                    //Create and set up the window.
                    JMainFrame main_frame = new JMainFrame();
                    main_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    //Display the window.
                    main_frame.pack();
                    main_frame.setVisible(true);
    }And here is the code of JMainFrame.java:
    public class JMainFrame extends JFrame {
        /** Creates a new instance of JMainFrame */
        public JMainFrame() {
            super();
            //load and set icon
            URL imgURL = JMainFrame.class.getResource("icon.png");
            ImageIcon img = new ImageIcon(imgURL);
            setIconImage(img.getImage());
    }As you said, it works :). It works when I run it through Netbeans launcher, and it also works when I run it through the Executable JAR Netbeans generated during the building of the application.
    So I adapted the code of the application I was talking about in the first post of this topic. I modified the code of the method loadImage in ImageLoader.java:
    public ImageIcon loadImage(String image_name) {
    //not working in JAR:  ClassLoader cldr = this.getClass().getClassLoader();
    //not working in JAR:  URL image_url = cldr.getResource("\\images\\"+image_name);
            URL image_url = ImageLoader.class.getResource(image_name);
            if (image_url != null) {
                return new ImageIcon(image_url);
            else {
                return null;
        }And it works well. Thanks again. However, I still can't explain why the use of class loader isn't undertood by the executable JAR.

Maybe you are looking for

  • Power Mac G4 shows only screensaver image; won't read disks

    My Power Mac G4 will no longer show the finder or any of my folders. It boots beyond the grey and blue screens to show a screensaver I'd chosen earlier, but doesn't show the finder or any of my folders. It will not read any of its original install di

  • UPGRADE  Panther or Tiger on Imac DV 400?

    I am trying to determine which OS would be the better choice for my computer. I have been running 10.2.8 for a few years, but I just bought photoshop elements 4 and now I see I need 10.3 or better. I can use the educator discount from Apple for Tiger

  • HT1349 How do i register a pre-owned ipad in my name

    How do i re-register a pre-owned ipad in my name? An ipad that is registered in another person's name, but its sold to me. How do i register it in my name. NOTE: Am getting this message in my support profile "According to our records, this serial num

  • Issues after making an excel full screen

    Hi, I am using a piece of code to make an excel workbook full screen. Code is working correctly but the problem is when this particular workbook is opened, if I open any other excel workbook that will also opening in full screen. I don't want this. T

  • Iphoto and back up issues

    Can you help please. I have a MBPro and am looking to move my iphoto library from the MBP to a 1 ter bite Mypassport external HD.  I have time machine running from a seperate external HD so this one is merely used to hold everything, freeing up the M