Netbeans 5.0 Executable Jar Problem--One Solution

Hi all.
This issue seems to constantly come up with all the Netbeans IDEs. I managed to solve the problem I was having so I felt obligated to post my solution since it can be mind-numbingly frustrating to deal with.
This may not work for you, but it worked for me in my situation so you may want to give it a shot.
This is what I did to solve the problem:
a) make sure a file called manifest.mf is in the root of your project folder. The manifest file should contain the following text (do not include the lines with ----------- on them of course):
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
To be safe:
Note the trailing carriage return after the X-COMMENT line--LEAVE THIS IN.
Note the case of the file name manifest.mf--MAKE SURE YOU DO NOT ADD CAPITAL LETTERS.
b) In the nbprojects folder of your main project folder, open the file project.properties and add the line:
manifest.file=manifest.mf
Clean and build your project. If you check the manifest in the main jar file, you'll see (hopefully) it has the Main-Class attribute set, as well as the class path to any other jar files you've put in your project classpath.
BTW1:
Make sure you don't have any files open in the directories that will need to be deleted by the 'clean' step or you'll get an error.
BTW2:
Also, make sure you've set your main class in your project by right-clicking the project node, click Properties, select Run from the tree on the left side, and fill in the 'Main-Class' text field.
This worked for me. I hope it helps others with the overly-confusing executable jar issues the Netbeans series of IDEs always seem to have. I think the complexity lies in its use of Ant in the build process. While Ant adds a ton of flexibility--it also a ton of complexity.
For example, this jar issue has been very annoying, but I wouldn't have been able to add a hook into my build process that signs my jar files (for use with Java Web Start) without the Ant system.
Netbeans 5.0 is still currently my favourite Java IDE though.
Cheers!
Michael N. Christoff

Genius! thank.

Similar Messages

  • Executable JAR Problems

    I made an executable JAR file (With the Manifest file). When I double click it, it just sits there. (Note: Im using XP and i did assosiate the file).
    Please help

    I had a similar problem running an executable Jar file on the XP platform. I was constantly getting the ClassNotFound error when I ran the program outside of the JBuilder 9 environment. I finally resorted to the newsgroups for help and found this suggestion. Including the classpath in the manifest file! This worked for me and hopefully it will help you.
    Main-Class: ewc.DocumentManager
    Class-Path: file:///C:\ewc\classes
    file:///C:\ewc\classes12\ojdbc14.jar

  • Spry Menu Bar transparency problem - one solution

    Like many other people I have spent several frustrating days trying to solve the problem of Spry Menu Bar sub-menus appearing to be transparent (text, etc. underneath the sub-menus shows above/through the sub-menu items). This problem manifested itself in IE7, but not in Netscape, Safari or Firefox.
    I thought it must be the dreaded IE z-index problem.
    I have been through most other people's questions and replies on the Adobe forums, tried all kinds of z-index changes and various other mods to my own CSS and/or the Spry CSS's - all to no avail.
    My situation:
    I have a Spry Menu Bar above a clicktrail and a text block. Both the clicktrail and the text block showed through the sub-menu items, which drop-down over them.
    All three items are located in relative-positioned divs, necessary because the whole page design is contained in a self-centralizing container div and absolute-positioned divs screw up the whole page layout when the screen size or browser window size changes.
    (Sorry, I can't upload the files to a website at the moment.)
    The solution that works for me in Dreamweaver CS4:
    I selected the divs for the clicktrail and the text block, one at a time, and selected Modify > Arrange > Send to Back in Dreamweaver CS4.
    I then selected these two items again and selected Modify > Arrange > Bring to Front.
    Finally I selected the div containing the Spry Menu Bar and selected Modify > Arrange > Bring to Front. The thought behind this was that this would put the Spry Menu Bar on top of everything else - and it works!
    This solution works in all four browsers, but don't ask me how! I can't see any change in any CSS, nor in my template code. All I can see is a strange, flashing vertical line (like an enormous cursor - about 10 cm [3"] high) in the middle of the template page only (and only in Dreamweaver) if I click on the page background. I can neither find an explanation for this nor anything in the coding which might cause it. By the way; the z-index for the menu div =2, the z-index for the clicktrail div is not defined and the z-index for the div for the text block is set to auto. I haven't tried other values and to be honest I'm not sure what they were set to before I applied the above 'solution'.
    But hey - who the hell cares - my site works!
    I hope this helps someone else out of an absolute hell-hole...if someone out there can explain where to find the code that had been changed or added by doing this I'd like to know. I don't like things I can't explain - even if they do work!

    This is where the browser is told to supply a white background
    ul.MenuBarHorizontal a
         display: block;
         cursor: pointer;
         background-color: #fff;
         padding: 0.5em 0.75em;
         color: #333;
         text-decoration: none;
    Vhange the value to transparent.
    Also the last line int the CSS should be removed as in
    filter: "alpha(opacity=60)";
    Gramps

  • Zen Micro "Firmware Problem" - One solution and what to do BEFORE it happ

    My Zen Micro 6GB recently croaked with the dreaded "firmware problem" message. After a call to support, I was told to send it in, however I was later able to connect to the unit and download new firmware.
    Here's what happened:
    In the middle of a playlist, the unit froze, displaying "firmware problem."
    - I took the battery out and powered up in recovery mode, then tried both reboot and reforomat. No luck; Still got "firmware problem."
    - I downloaded firmware updates, thn connected the unit to my laptop, which does not have MTP media explorer installed. The laptop does have Yahoo Music Engine and Windows Media 0, both of which are used regularly to copy music to device.
    - The computer recognized the Zen Micro, but the firmware update did not run, saying it could not connect to the device.
    - Retried several times, after reformatting, etc.
    Now, here's what seemed to fix it
    - Let the battery drain completely while in the unit
    - Connected the Zen Micro to a computer with the MTP media explorer already installed. This is a system that is also used to regularly download music to the device.
    - Allowed the battery to charge for an hour
    - Started MTP media explorer, noticed that device went into "Recovery Mode"
    - Ran the firmware upgrade and it installed.
    This is conjecture, but it seems that the MTP media explorer must be running to launch the firmware upgrade, but you can't install MTP without a valid device connected. I don't know why this is - maybe some kind of copy protection scheme. I only had it installed on one of my computers because it seemed unnecessary and I hate loading software that I'm not going to actually use.
    This is what worked for me. Hope it works for you.
    I'm still really disappointed with Creative's warranty terms, lack of phone support past 60 days and failure of tech support to recognize the problem and offer a solution, but my unit is working again and I didn't have to send it back!

    By "MTP media explorer", do you mean the MTP/PlaysForSure version of Zen Micro Media Explorer? The earlier versions say "(for MTP devices)"; the latest ones say "(for PlaysForSure devices)". Or do you mean the Microsoft "MTP icon" in My Computer, which should appear on all MTP-capable systems (including your laptop)?
    I don't really think it's a DRM or copy protection issue; I think the "firmware problem" is wiping out the hardware code the firmware installer uses to confirm that the device is indeed a Micro instead of, say, an iRi'ver. I suspect ZMME is one of the alternate means it uses to confirm that a Micro is connected. (An issue for further testing is whether ZMME should be launched or just installed.) Firmware fails on all kinds of devices; I suspect this is just a peculiarity of Creative's MTP/Janus firmware installer.
    This is likely to be a significant issue for the FAQs and/or Creative knowledge base. With a growing number of MTP/Janus players in the Creative lineup (Sleek, MicroPhoto, and shortly Touch & Xtra), it probably won't be just a Micro issue in the future.
    Edit: I just read the other thread, and they seem to solve it by going to a system without Creative software and installing the ..0 firmware. So there seems to be two solutions for now:
    If you don't have any Creative software installed, reload firmware and run the ..0 upgrade. (If you need 2.x firmware, then install the Creative jukebox driver and run the 2.20.05 upgrade; you can uninstall the driver afterwards. Sorry, but some of us need 2.x firmware.)</LI>
    If you have the 2.x ZMME installed, open it, then reload firmware and run the 2.20.05 upgrade.</LI>
    Message Edited by RBBrittain on 0-9-2005 0:06 PM

  • IMac FW 800 Port Problem & One Solution

    I recently had a problem with my 2010 iMac's FW 800 port. I searched these discussions and found a solution that worked for me. I want to pass on the tip. I knew there was a problem with the port because I could access my FW 800 drive using the same cable when attached to another Mac.
    This was confirmed when I displayed the "More info..." window from "About This Mac". I am running Mac OS X 10.7.1 Lion and the "More info..." button starts up a System Information app. Click on "System Report". Choose "Firewire" in the Hardware section. If your FW 800 port is not recognized there's be a message in red (I forget the exact wording).
    Following directions in this message by den.thred, I reset the SMC > http://support.apple.com/kb/HT3964
    That worked for me and I hope it works for others. Thank you, Dennis!
    Charles

    How curious, in Sytem Profiler or System Informatio>Firewire, what does it report like this...
    Maximum Speed:          Up to 800 Mb/sec
    OEM ATA Device 00:
      Manufacturer:          NewerTech
      Model:          0x0
      GUID:          0x30E002E0002156
      Maximum Speed:          Up to 800 Mb/sec
      Connection Speed:          Up to 400 Mb/sec
      Sub-units:
    OEM ATA Device 00 Unit:
      Unit Software Version:          0x10483
      Unit Spec ID:          0x609E
      Firmware Revision:          0x110
      Product Revision Level:
      Sub-units:

  • Problem with running the app outside NetBeans (loading fxml from jar)

    Hello.
    this problem occurs only when NOT using NetBeans (becouse NB may use this normal file sctructure, without jars)
    here is part of my main class, start method
            //load FXMLs
            FXMLLoader primaryLoader = new FXMLLoader();
            URL primaryLocation = getClass().getResource("PrimaryStage.fxml");
            primaryLoader.setLocation(primaryLocation);
            Parent root = (Parent) primaryLoader.load();
            Scene primaryScene = new Scene(root);
            FXMLLoader secondaryLoader = new FXMLLoader();
            URL secondaryLocation = getClass().getResource("SecondaryStage.fxml");
            secondaryLoader.setLocation(secondaryLocation);
            System.out.println("sec loader = " +secondaryLoader.toString()
                    +"\n sec loc from loader = "+secondaryLoader.getLocation()
                    +"\n sec loc url = " + secondaryLocation
                    +"\n pri loc url = " + primaryLocation);
            Parent secondaryRoot = (Parent) secondaryLoader.load();
            Scene secondaryScene = new Scene(secondaryRoot);and the thing is the 1st url (primaryLocation) is loaded properly, and the secondLocation aint.
    those 2 files are both in the same jar, same folder (packege) as main class.
    the outcome looks like this
    sec loader = javafx.fxml.FXMLLoader@5bde2a20
    sec loc from loader = null
    sec loc url = null
    pri loc url = jar:file:/C:/test_workspace/NetBeans/MZlike/dist/MoreAdvStuff.jar!/moreadvstuff/PrimaryStage.fxml
    Exception in Application start method
    java.lang.reflect.InvocationTargetException
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at com.javafx.main.Main.launchApp(Main.java:486)
            at com.javafx.main.Main.main(Main.java:638)
    Caused by: java.lang.RuntimeException: Exception in Application start method
            at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
            at com.sun.javafx.application.LauncherImpl.access$000(Unknown Source)
            at com.sun.javafx.application.LauncherImpl$1.run(Unknown Source)
            at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.IllegalStateException: Location is not set.
            at javafx.fxml.FXMLLoader.load(Unknown Source)
            at moreadvstuff.MoreAdvStuff.start(MoreAdvStuff.java:55)
            at com.sun.javafx.application.LauncherImpl$5.run(Unknown Source)
            at com.sun.javafx.application.PlatformImpl$4.run(Unknown Source)
            at com.sun.javafx.application.PlatformImpl$3.run(Unknown Source)
            at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
            at com.sun.glass.ui.win.WinApplication.access$100(Unknown Source)
            at com.sun.glass.ui.win.WinApplication$2$1.run(Unknown Source)
            ... 1 morewhere 55 line is
    Parent secondaryRoot = (Parent) secondaryLoader.load();any ideas how to fix it? loading the file manually from the jar may be a way, but its a workaround, not a solution
    Edited by: Radosław on 2012-05-17 07:55

    Hi,
    The root cause of the exception appears is here:
    sec loc url = nullThis means that the URL returned here by getResource() was null:
            URL secondaryLocation = getClass().getResource("SecondaryStage.fxml");So the only thing you have to do is figure out why this call returned null. Usually it returns null if the resource is not found in the jar/classpath.
    Last time it happened to me it was because I had misspelled the file name.
    Check that your file is not named SecondaryStage,fxml instead of SecondaryStage.fxml or something like that. Also check that it's actually present in the jar - or in the build/ directory and at the expected place (next to the class that loads it).
    Hope this helps,
    -- daniel

  • Problem in loading applet from non executable jar file

    hello ,
    I am new to jar concept plz help.. I am trying to call an applet from another applet through frame it is working fine but its download time is much more. now i want to store all my images , sound files and class files of other applets in a jar file and want to access these inner applets from this jar file so that it will make only one http connection with the server for this jar file only and can reduce the download time of applet.
    Can anyone can give me suggestion plz..
    Thanx

    You have to download what you have to download. You
    probably can't easily share images between 2 separate
    Jar files. Unless you can expose them through the
    other applet via a method that can be known once you
    have the reference to the other applet.Thanx but i think i have to elaborate the problem :
    my project structure is just like this ::
    on the top is ::
    Applet A---> from this applet i am callling Applet B & Applet C in frame
    and communication is established between these 3 applets successfully .
    now i have made a single non executable jar file which contains images , sound and class files of these applets .
    so i am referencing images and sound files in applets through this jar.
    but i wanted to load Applet B & C through this jar file only.
    How can i do this ??
    Thanx .. I hope now the problem is clear

  • [b]Simple Deploy problem- making an Executable JAR File ...PLEASE HELP [/b]

    Hi all,
    I Trying to deploy a simple J2SE app by making an Executable JAR File, however I don'r understand how to add a valid value to the Main Class field.
    I followed the following description within Jdev, after creating a Deployment Profile:
    Deploying an Executable JAR File
    You can make your simple archive or J2EE Client Module into an executable JAR file that you can launch with the java command.
    To deploy an executable JAR file:
    1) Select and right-click the simple archive or client icon in the Navigator to display the context menu.
    2) Choose Properties.
    3) Click JAR Options in the tree.
    4) Select Include Manifest File (META-INF/MANIFEST.MF).
    5) In the Main Class field, enter the fully qualified name of the application class that is to be invoked.
    7) Click OK.
    8) Launch the executable JAR file from the command line:
    java -jar myapp.jar
    where myapp represents your JAR file name.
    Like I said it's in 5) I'm doing something worng
    My deploy-file (PlotPrint.deploy) looks the following:
    <?xml version = '1.0' encoding = 'windows-1252'?>
    <client-deployment xmlns="http://xmlns.oracle.com/jdeveloper/903/deploy/j2ee-client-jar" nselem="client-deployment" class="oracle.jdeveloper.deploy.jar.ClientProfile">
    <archiveOptions>
    <additionalManifests/>
    <compressed>false</compressed>
    <hasManifest>true</hasManifest>
    <mainClass>PlotPrintClient</mainClass>
    </archiveOptions>
    <archiveTargetPlatform/>
    <cdaSettings>
    <additionalArchives/>
    <afterFilters/>
    <beforeFilters/>
    <duringFilters/>
    <selectedArchives>
    <archives>
    <Item protocol="jar" path="file:/C:/Oracle9i_Jdev/jdevbin/jdbc/lib/classes12.jar!/"/>
    <Item protocol="jar" path="file:/C:/Oracle9i_Jdev/jdevbin/jdbc/lib/nls_charset12.jar!/"/>
    <Item protocol="jar" path="file:/C:/Oracle9i_Jdev/jdevbin/jdev/lib/jdev-rt.jar!/"/>
    <Item protocol="jar" path="file:/C:/Oracle9i_Jdev/jdevbin/soap/lib/soap.jar!/"/>
    <Item protocol="jar" path="file:/C:/Oracle9i_Jdev/jdevbin/lib/xmlparserv2.jar!/"/>
    <Item protocol="jar" path="file:/C:/Oracle9i_Jdev/jdevbin/jlib/javax-ssl-1_2.jar!/"/>
    <Item protocol="jar" path="file:/C:/Oracle9i_Jdev/jdevbin/jlib/jssl-1_2.jar!/"/>
    <Item protocol="jar" path="file:/C:/Oracle9i_Jdev/jdevbin/j2ee/home/lib/activation.jar!/"/>
    <Item protocol="jar" path="file:/C:/Oracle9i_Jdev/jdevbin/j2ee/home/lib/mail.jar!/"/>
    <Item protocol="jar" path="file:/C:/Oracle9i_Jdev/jdevbin/j2ee/home/lib/http_client.jar!/"/>
    <Item protocol="jar" path="file:/C:/Oracle9i_Jdev/jdevbin/webservices/lib/wsdl.jar!/"/>
    <Item protocol="jar" path="file:/C:/Oracle9i_Jdev/jdevbin/lib/xmlparserv2.jar!/"/>
    <Item protocol="jar" path="file:/C:/Oracle9i_Jdev/jdevbin/lib/xmlcomp.jar!/"/>
    </archives>
    <selectionMode>0</selectionMode>
    </selectedArchives>
    </cdaSettings>
    <defaultConnection class="java.lang.String"/>
    <deployClientMaxHeapSize/>
    <earURL path="deploy/PlotPrint.ear"/>
    <enterpriseAppName/>
    <jarURL path="deploy/PlotPrint.jar"/>
    <profileDeps/>
    <properties/>
    <selectedProjectFiles>
    <autoInclude>true</autoInclude>
    <deploySourceAs>0</deploySourceAs>
    <files class="[Ljava.net.URL;"/>
    <selectionFilters/>
    </selectedProjectFiles>
    </client-deployment>
    I using Oracle9i Jdev, but have also tried it un the new Jdev 10g version, but the same problem everytime:
    Error message: Could not find the main class: program will exit.
    Please help I really need this to work
    Message was edited by:
    MHCI
    Message was edited by:
    MHCI

    Yes that was the problem so I have changed the element mainClass to
    <mainClass>xxPlotPrint.MHCI.PlotPrintClient</mainClass>
    But now another probem has occured, since I get the following error when run the jar-file (When I run the app from within Jdev there are no warnings or errors).
    ----Batch-file-----
    @echo off
    java -jar PlotPrint.jar
    echo Test Plot and Print Batch-file!
    pause
    ---- out to cmd ----
    Exception in thread "Thread-0" java.lang.ClassCastException: com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl
    at xxPlotPrint.MHCI.NNE35_worker.run(NNE35_worker.java:42)
    at java.lang.Thread.run(Unknown Source)
    Exception in thread "Thread-2" java.lang.ClassCastException: com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl
    at xxPlotPrint.MHCI.OCEJobDB_worker.run(OCEJobDB_worker.java:41)
    at java.lang.Thread.run(Unknown Source)
    Exception in thread "Thread-1" java.lang.ClassCastException: com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl
    at xxPlotPrint.MHCI.NNE27_worker.run(NNE27_worker.java:42)
    at java.lang.Thread.run(Unknown Source)
    It's the same problem in all three exceptions (the exactly the same code), however I was a bit to quick this is the line (the line before I process the xml doc :-)
    import org.w3c.dom.Element;
    responseData = new Vector();
    responseData = test_NNE35_SOAP.getXSDdoc();
    Element elements = ( (org.w3c.dom.Element)responseData.elementAt(0) ); (line 42)
    Please help I don't understad why I receive this exception, since I included the xmlparserv2.jar file, and don't even have a workaround :-(

  • 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

  • Problem with executable jar file

    Hi,
    I wrote a simple little xml based app in eclipse, it had xalan and xerces in build path. I created an executuable jar that ran fine on my machine; I was able to move it to different directories and launch it successfully, but when I put the jar file on a network directory and asked a coworker to try running it, they got a message that said it couldn't find the main class.
    how do you deal with that?
    thanks,
    bp

    they got a message that said it couldn't find the main class.
    Are you sure?
    If you are sure then none of the other responses will help.
    That error suggests one of the following
    1. The jar you moved is not the jar that you are running.
    2. Your co-workers did not execute it correctly.
    3. You do not have an executable jar (and you are not testing it correctly on your box.)
    How exectly did they run it?
    The standard double click will give an error about "Main-Class" with that specific text when you attempt to run a jar that is not in fact an executable jar.
    That error is NOT the same as the standard class not found error.

  • Problem running my program only after making an executable jar...

    Hi everyone,
    I am having trouble running my program after creating an executable jar. The program runs fine until
    it is supposed to open a specific JFrame. I get the following error message as soon as the frame tries
    to open:
    Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: org.apache.xerces.parsers.SAXParser.<init>(Lorg/apache/xerces/xni/parser/XMLParserConfigurat
    ion;
    Has anyone ever seen this before?
    The strange thing is, this does not happen when I build and run the project under Eclipse.
    Any help or tips would be appreciated!
    Chris

    Roosh wrote:
    The strange thing is, this does not happen when I build and run the project under Eclipse.
    Any help or tips would be appreciated!Make sure you are using the same version of Java as you use with Eclipse.

  • Getting problem while executing JAR on MAC os

    Hello All,
    I have created an executable JAR file for my project. My Project uses third party jars also like "bcprov-jdk15-136.jar", "BrowserLauncher2-1_3.jar".
    So I have added these jars in MANIFEST file as below
    Class-Path: lib\bcprov-jdk15-136.jar lib\BrowserLauncher2-1_3.jar lib\ log4j-1.2.13.jar lib\swing-layout-1.0.1.jar
    When I execute my JAR on windows it works fine.
    But when I run the same JAR on Apple MAC. It gives me below exception
    2/25/09 2:53:40 PM [0x0-0x215215].com.apple.JarLauncher[5595] Exception in thread "main"
    2/25/09 2:53:40 PM [0x0-0x215215].com.apple.JarLauncher[5595] java.lang.NoClassDefFoundError: edu/stanford/ejalbert/BrowserLauncher
    Can anybody please guide me what changes are required to run this JAR file on MAC?
    Thanks in Advance,
    Jenish

    Hello All,
    I have created an executable JAR file for my project. My Project uses third party jars also like "bcprov-jdk15-136.jar", "BrowserLauncher2-1_3.jar".
    So I have added these jars in MANIFEST file as below
    Class-Path: lib\bcprov-jdk15-136.jar lib\BrowserLauncher2-1_3.jar lib\ log4j-1.2.13.jar lib\swing-layout-1.0.1.jar
    When I execute my JAR on windows it works fine.
    But when I run the same JAR on Apple MAC. It gives me below exception
    2/25/09 2:53:40 PM [0x0-0x215215].com.apple.JarLauncher[5595] Exception in thread "main"
    2/25/09 2:53:40 PM [0x0-0x215215].com.apple.JarLauncher[5595] java.lang.NoClassDefFoundError: edu/stanford/ejalbert/BrowserLauncher
    Can anybody please guide me what changes are required to run this JAR file on MAC?
    Thanks in Advance,
    Jenish

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

  • Vm arg in executable jar

    Hi,
    I do this to run my java class (because it uses a lot of memory):
    java -Xmx128M Crossword
    and this works fine.
    Now I've made an executable jar to run my class just by double clicking on the jar file. The problem is that I dont know how to make the jar use this VM parameter. I dont want anything external to my jar to have to change. I want to just be able to drop my jar on a different PC (with a JRE installed on it of course) and be able to run the jar just be double clicking it.
    Anyone know how to do this?
    Thanks,
    Jim

    There are of course other solutions.
    For example you write a simple application that starts a VM using Runtime.exec(). That is OS specific (and requires some work for each system.) It exits once it starts the other VM.
    You could even wrap it in a single jar by having passing in a command line parameter that specifies "run real' or 'start with correct memory'.
    I believe one of the properties in System.getProperites() has the VM path.

  • 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

Maybe you are looking for