Results 1 to 6 of 6
  1. #1
    Xainey is offline Member
    Join Date
    Dec 2011
    Posts
    4
    Rep Power
    0

    Default Having problems making a runnable jar

    I'm new to eclipse and fairly new to java. I'm going to explain this as best as possible.

    I'm having problems making a runnable jar file.

    I've selected my project > export > runnable jar file > packaged required libraries to create my runnable jar.

    When I launch my jar with Java SE Platform binary nothing happens. When I run my program in eclipse it works as intended.

    It is a GUI program, its using JFrames, they are set to visible true.

    I've also noticed that the jar doesn't seem to include any of the source images. Ive tried using
    Java Code:
    ImageIcon icon = new ImageIcon(getClass().getResource("/image.png"));
    and placing my images in the bin folder as well to try to get it to package them.

    I'm at a loss, if anyone can help or needs to know any other information please let me know.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Having problems making a runnable jar

    Are you setting the "Main" class in the Jar export wizard? If you don't do this, the created manifest file won't have the information necessary to tell the JVM which class's main method should be the starting point of the program.

  3. #3
    Xainey is offline Member
    Join Date
    Dec 2011
    Posts
    4
    Rep Power
    0

    Default Re: Having problems making a runnable jar

    Yes the only option in the drop down box is my main class. Even with it selected the jar will not run. I look at the jar with 7Zip and it seems to have all of the class files and manifest but none of the source images.

    Java Code:
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    
    public class GameFrame {
    
    	@SuppressWarnings("unused")
    	public void loadImages(){
    		ImageIcon icon = new ImageIcon(getClass().getResource("/level.png"));
    		ImageIcon icon2 = new ImageIcon(getClass().getResource("/Man.png"));
    	}
    	
    	public static void main(String args[]){
    		
    		int FWidth = 800;
    		int FHeight = 600;
    		
    		JFrame frame = new JFrame ("Title");
    		
    		frame.setIgnoreRepaint(true);
    		frame.setBounds(0, 0, FWidth, FHeight);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		
    		GameCanvas game = new GameCanvas();
    		
    		frame.add(game);
    		
    		frame.setVisible(true);
    		
    		GameFrame lim = new GameFrame();
    		lim.loadImages();
    
    		
    	}
    	
    	
    }
    Its very basic just simple jframes program so far and I tried the loadImages method because I was trying to get the exporter to package the source images in the jar as well.

    As it currently stands the Runnable Jar does nothing when ran nor are the images included in the jar as far as I can tell.

  4. #4
    Xainey is offline Member
    Join Date
    Dec 2011
    Posts
    4
    Rep Power
    0

    Default Re: Having problems making a runnable jar

    Yes Ive set the main class in the wizard. I think everything is being caused by the images not being packaged with the jar.

    here is what happens if I run it using command line java

    Unable to Load: Man.pngException in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoa der.main(JarRsrcLoader.java:58)
    Caused by: java.lang.NullPointerException
    at ImageLoader.getSprite(ImageLoader.java:40)
    at Entity.<init>(Entity.java:33)
    at ManEntity.<init>(ManEntity.java:7)
    at GameCanvas.<init>(GameCanvas.java:32)
    at GameFrame.main(GameFrame.java:23)
    ... 5 more

  5. #5
    Xainey is offline Member
    Join Date
    Dec 2011
    Posts
    4
    Rep Power
    0

    Default Re: Having problems making a runnable jar

    Ok I figured out what the problem was. Here is a quick overview in case anyone else might have a similar problem.

    I've selected my project > export > runnable jar file > selected the main class to use > packaged required libraries to create my runnable jar.

    When I tried to run my jar nothing happened. I opened a command line and ran java -jar myprogram.jar and it returned the errors in the previous post.

    I ended up manually right clicking on my project source folder and adding a new file named after my jpg and png pictures. I then replaced the image files using windows explorer.

    After that I had to refresh the project files in eclipse. I exported again and checked the jar with 7Zip to make sure it packed my images as well, but I still had the same error not finding my images.

    I opened my imageloader class and changed

    Java Code:
    sourceImage = ImageIO.read(new File (ref));
    TO

    Java Code:
    sourceImage = ImageIO.read(ImageLoader.class.getResource(ref));
    After a final export everything worked great. If anyone knows a better way to add images to their source folder using eclipse than how I mentioned above I would really like to know.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Having problems making a runnable jar

    Files don't exist inside of jars, only resources, so yes you must get all images (and anything else that you'd get as a file) as resources.

Similar Threads

  1. Problems Making a "POST" to a Socket
    By haroldjclements in forum Networking
    Replies: 3
    Last Post: 10-16-2011, 06:15 AM
  2. debug runnable jar
    By Levian in forum New To Java
    Replies: 0
    Last Post: 08-11-2011, 06:38 AM
  3. Problems with making a class. New to Java.
    By zendavis in forum New To Java
    Replies: 9
    Last Post: 07-24-2011, 12:39 PM
  4. problems with threads in my program (runnable)
    By runn81 in forum Threads and Synchronization
    Replies: 12
    Last Post: 05-09-2011, 06:26 PM
  5. Problems making a JTable's cells transparent
    By Muskar in forum New To Java
    Replies: 5
    Last Post: 12-09-2010, 10:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •