Jump to content


Executable Jar File


  • Please log in to reply
16 replies to this topic

#1 Phil^

Phil^

    Advanced Member

  • Members
  • PipPipPip
  • 175 posts

Posted 19 March 2005 - 09:47 PM

It would be rather nice if there was a simple way to export to an executable jar file.
Perhaps a button when clicked , asks which is the main class to execute ( if this cant be auto-detected ) , and packages it up.
I realise there is a usertool for making it into a normal jar file, but this doesnt make it executable unfortunately.

a feature to allow jar file signing would also be appreciated

#2 E-E-R

E-E-R

    Advanced Member

  • Members
  • PipPipPip
  • 1,367 posts
  • Gender:Male
  • Location:The Netherlands
  • Interests:Programming, Gaming, DC

Posted 19 March 2005 - 10:10 PM

Actually it is quite easy:

click:
Configure>Options>Tools>New>Create JAR File

this creates an user tool to create a JAR file, this does not yet include the manifest, you will have to manually add the manifest.

OR you can configure the command line switches to incorporate the manifest, try this for example:
cvmf $[PrjDir]\MANIFEST.MF $[PrjName].jar .

this should include the manifest 'MANIFEST.MF' in your project directory as a manifest. You will have to create that yourself though.

NOTE: this has NOT been tested


Though I do agree that an automated way of creating executable JAR files are a good improvement on the current feature set.
"Many are persistently in pursuit of the way they have chosen; few in pursuit of the goal"

#3 Maephisto

Maephisto

    Member

  • Members
  • PipPip
  • 10 posts

Posted 21 March 2005 - 10:57 AM

interesting suggestion... it's up for me!


#4 mebreek

mebreek

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 05 April 2005 - 04:32 PM

QUOTE(E-E-R @ Mar 19 2005, 10:10 PM)

cvmf $[PrjDir]\MANIFEST.MF $[PrjName].jar .

View Post



I tested it, it worked with just a minor modification though:
cvmf "$[PrjDir]\MANIFEST.MF" $[PrjName].jar .

before I added the quotes, the $[PrjDir]\MAINFEST.MF turned to be c:\documents;
after adding the quotes, the full path was included.

Thanks


#5 el_Killer_Rifa

el_Killer_Rifa

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 05 April 2005 - 04:50 PM

I think the way: "Configure>Options>Tools>New>Create JAR File" is very hidden. IMHO better to a user to have the option configured by default.

#6 Phil^

Phil^

    Advanced Member

  • Members
  • PipPipPip
  • 175 posts

Posted 05 April 2005 - 05:21 PM

QUOTE(el_Killer_Rifa @ Apr 5 2005, 04:50 PM)
I think the way: "Configure>Options>Tools>New>Create JAR File" is very hidden. IMHO better to a user to have the option configured by default.

View Post



unfortunately that doesnt make an executable jar file though

#7 ceallachan

ceallachan

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 06 April 2005 - 03:22 PM

Has anyone heard if there is a timeline for getting the Manifest-Class piece added to the jar automatically?

#8 lordSauron

lordSauron

    Advanced Member

  • Members
  • PipPipPip
  • 192 posts
  • Gender:Male
  • Location:California, United States
  • Interests:Dominating Middle-earth, enslaving all the free peoples and keeping my Silmaril stones nice and shiny.

Posted 06 April 2005 - 07:42 PM

It shouldn't be that hard for Xinox to create a jar-maker...  Borland JBuilder has had it since version 4 (that I know of...)

I'm sure Xinox is going to include this in JCreator v. 4.0 - I'd be very concerned if it turned out otherwise.
Lord Sauron the Great
lordSaurontheGreat@gmail.com
JDK 6 Documentation - READ IT!  LOVE IT!  LIVE IT!
THOU SHALT GOOGLE BEFORE POSING THY QUERY!
If you're reading this you have given me control of your mind.
Why do accesses to your mind throw a "null pointer exception?"

#9 Phil^

Phil^

    Advanced Member

  • Members
  • PipPipPip
  • 175 posts

Posted 06 April 2005 - 08:47 PM

QUOTE(lordSauron @ Apr 6 2005, 07:42 PM)
It shouldn't be that hard for Xinox to create a jar-maker...  Borland JBuilder has had it since version 4 (that I know of...)

I'm sure Xinox is going to include this in JCreator v. 4.0 - I'd be very concerned if it turned out otherwise.

View Post


i hope they do it in a 3.x release or i`ll have to buy it again :(
im only a poor lil student you know! :)

#10 amdmatt

amdmatt

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 20 September 2005 - 01:10 AM

sorry for the bump

but what is actially in the manifest file?


#11 E-E-R

E-E-R

    Advanced Member

  • Members
  • PipPipPip
  • 1,367 posts
  • Gender:Male
  • Location:The Netherlands
  • Interests:Programming, Gaming, DC

Posted 20 September 2005 - 06:52 AM

usually something like this:
CODE
Manifest-Version: 1.0
Created-By: 1.5.0_04 (Sun Microsystems Inc.)
Main-Class: RC5Gui.RC5StatsFrame



for more info, read this: http://java.sun.com/j2se/1.5.0/docs/guide/...#JAR%20Manifest
"Many are persistently in pursuit of the way they have chosen; few in pursuit of the goal"

#12 randomballoon

randomballoon

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 01 October 2007 - 09:40 PM

I'm still having some problems getting the jar to run. When run, it gives an error:
"Could not find the main class. Program will now exit."
I think it deals with the manifest but i am confused on how to fix it.

edit: Ok, i got it to work but i am having a new problem now. My program uses pictures and I would like those to be included in the jar file instead of the pictures having to be in the folder with the jar. Is there a way to do this?

#13 ham90mack

ham90mack

    Advanced Member

  • Members
  • PipPipPip
  • 937 posts

Posted 01 October 2007 - 10:20 PM

Yes, there is.  To keep things simple, use the method in this class.  You might be able to understand how it works by reading it, along with the comments.

CODE
package images;

import java.awt.Image;
import java.awt.MediaTracker;
import java.net.URL;
import javax.swing.ImageIcon;

/**
   This is a utility class that allows images to be loaded from file, from a URL, or
   from a JAR file.<p>
   COPYRIGHT (C) 2007 ham90mack. All Rights Reserved.
  
   @author ham90mack
   @version 1.20 2007-06-22
*/
public class ImageRetriever
{
  /**
     This class is a utility and should never be constructed.
  */
  private ImageRetriever(){}
  
  /**
     Retrieves an ImageIcon from file. This method first tries to get the image from
     the base folder that is defines when starting the JVM. If the image is not found,
     then this attempts to get the image from a folder named "images". If the image is
     not found, then this attempts to load the image from a URL. If the image is not
     found or if the String is not a valid URL, then this attempts to load the image from
     the JAR file this may be in. Note that if an image is expected to be in a folder within
     the jar file named images, "/images/" does not need to be provided. Otherwise, make sure
     to put "/" at the beginning of the filename. If the image is not found, a RuntimeException
     is thrown.
     @param filename the image file to retrieve
     @return the ImageIcon created from the file
     @throws RuntimeException if the icon does not exist
     @see #getImage(String)
  */
  public static ImageIcon getImageIcon(String filename)
  {
    // to read from file
    ImageIcon icon = new ImageIcon(filename);
    
    //checks if the icon is in a folder named images
    if ((icon == null) || (icon.getImageLoadStatus() != MediaTracker.COMPLETE)){
        icon = new ImageIcon("images/" + filename);
    }
    
    // try to read from URL
    if ((icon == null) || (icon.getImageLoadStatus() != MediaTracker.COMPLETE)) {
        try {
            URL url = new URL(filename);
            icon = new ImageIcon(url);
        } catch (Exception e) { /* not a url */ }
    }

    // in case file is inside a .jar
    if ((icon == null) || (icon.getImageLoadStatus() != MediaTracker.COMPLETE)) {
        URL url = ImageRetriever.class.getResource(filename);
        if (url == null) throw new RuntimeException("image " + filename + " not found");
        icon = new ImageIcon(url);
    }
    
    return icon;
  }
  
  /**
     Retrieves an Image from a file. Calls getImageIcon to get the image and returns the
     Image within the ImageIcon.
     @param filename the image file to retrieve
     @return the Image created from the file
     @throws RuntimeException if the icon does not exist
     @see #getImageIcon(String)
  */
  public static Image getImage(String filename)
  {
    ImageIcon icon = getImageIcon(filename);

    return icon.getImage();
  }
}


NOTE: when adding this class to your project, make sure to import the package "images" in whatever java files need to use these methods.


ham90mack
http://ham90mack.googlepages.com
Resistance may be futile,
But capacitance has potential.
BLAH!

#14 randomballoon

randomballoon

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 02 October 2007 - 12:25 AM

Ok, I think i'll be able to figure that code out, but when I say "package images" at the top of my GUI file (with the main method) it won't compile because it messes up my other files I call there.

#15 ham90mack

ham90mack

    Advanced Member

  • Members
  • PipPipPip
  • 937 posts

Posted 02 October 2007 - 12:57 AM

Whoa there! I did not say you had to change your package structure! All you need to do is say:
"import images.*;"
and you will be fine! That is what package structure is for; it allows related libraries to be grouped together, but you do not need to adapt to their structure.
ham90mack
http://ham90mack.googlepages.com
Resistance may be futile,
But capacitance has potential.
BLAH!

#16 randomballoon

randomballoon

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 02 October 2007 - 01:48 AM

Yeah, thanks for the heads up there...I dont have too much experience with imports, but I did get it working, thanks a ton for the help. I'll be sure to give you credit in the program.

#17 Igor Pejasinovic

Igor Pejasinovic

    Newbie

  • Members
  • Pip
  • 1 posts
  • Gender:Male
  • Location:Republic of Srpska

Posted 08 April 2008 - 09:23 PM

I've done some small tool and corrections to JCreator Tools and now I can with simple click make manifest and create executable Jar.

Download Create Manifest Batch File and install it to JCreator dir.

Here it is how it look: