Results 1 to 16 of 16
  1. #1
    NotTooOld is offline Hostage
    Join Date
    Apr 2013
    Location
    China
    Posts
    128
    Rep Power
    0

    Default Help with runnable jar

    I am trying to export a runnable jar file, but all the art and sound files are not showing up. the file works great after landing on my desktop, but when I send it to another computer... major fail. Is this because I use absolute paths in my code, or am I doing(not doing) something else wrong?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,086
    Rep Power
    20

    Default Re: Help with runnable jar

    I was going to move this to the proper Eclipse forum, but that seems to be broken.

    Anyway, if you are using absolute paths then yes, that is why it doesn't load your resource.
    You need to be using getResource or getResourceAsStream, which are methods on Class.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    NotTooOld is offline Hostage
    Join Date
    Apr 2013
    Location
    China
    Posts
    128
    Rep Power
    0

    Default Re: Help with runnable jar

    Quote Originally Posted by Tolls View Post
    I was going to move this to the proper Eclipse forum, but that seems to be broken.

    Anyway, if you are using absolute paths then yes, that is why it doesn't load your resource.
    You need to be using getResource or getResourceAsStream, which are methods on Class.
    Thank you!
    I put this in the eclipse forum... or thought I did. The link for your reply looks like eclipse forum...
    http://www.java-forums.org/eclipse/7...-new-post.html
    I tried with both absolute and relative paths, as I said, but I'll try these two get methods and see what happens.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,086
    Rep Power
    20

    Default Re: Help with runnable jar

    Yeah, we've been having problems with some of the forum groups.
    I'll move this to the New To Java (hopefully) since it's not really an eclipse thing, but is down to how you are accessing your resources.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    NotTooOld is offline Hostage
    Join Date
    Apr 2013
    Location
    China
    Posts
    128
    Rep Power
    0

    Default Re: Help with runnable jar

    Quote Originally Posted by Tolls View Post
    Yeah, we've been having problems with some of the forum groups.
    I'll move this to the New To Java (hopefully) since it's not really an eclipse thing, but is down to how you are accessing your resources.
    @Tolls

    Since you are the one that originally told me to use getResource and getResourceAsStream, wanna help me figure out how to make em work in my project? If so, where? Back in this thread?
    This very simple code throws exception... and I can't understand why

  6. #6
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Help with runnable jar

    Eclipse will consider any non-Java files as resources and copy them into the project's bin/ folder as well as into any jar you export. I like to create an additional source folder called res/ and put my resources in there. If one of your Eclipse source folders contains a file named "foo", you can open it with getResourceAsStream using the file name "/foo".
    Get in the habit of using standard Java naming conventions!

  7. #7
    NotTooOld is offline Hostage
    Join Date
    Apr 2013
    Location
    China
    Posts
    128
    Rep Power
    0

    Default Re: Help with runnable jar

    Help!!! I have exported two runnable jar files. The first was a simple project that (I thought) just needed the resources correctly pointed to. The second uses nothing external at all, other than the jar files I imported in the single class file. It is the simplest of apps. I open the jar files on my desktop. No problems. I send it to my laptop via email. Still no problems. I send either of them to any of 4 friends, and they don't work. The first, a small project will open on my friend's computer, but one of the wav files doesn't play. (Odd becuase all the wav files are in the same location, and called by the same method.) The second, a super simple Jframe with nothing but text and a few radio buttons won't open?? I've asked, and everyone is up to date with Java 7 update 17. I can't understand this strangeness.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,086
    Rep Power
    20

    Default Re: Help with runnable jar

    Do the jar files contain all the bits needed to run them?
    Look in the manifest of each and check the values in there.
    Look in the jar files (eg the first on) for resources the app uses.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Help with runnable jar

    Post the error messages.
    Get in the habit of using standard Java naming conventions!

  10. #10
    NotTooOld is offline Hostage
    Join Date
    Apr 2013
    Location
    China
    Posts
    128
    Rep Power
    0

    Default Re: Help with runnable jar

    Quote Originally Posted by Tolls View Post
    Do the jar files contain all the bits needed to run them?
    Look in the manifest of each and check the values in there.
    Look in the jar files (eg the first on) for resources the app uses.
    Well, I don't know if they contain all the bits needed. The second one uses no other files, just the class I wrote. It is a JFrame, and imports some things, but calls on no other files. I assume the import statements are taken care of. There should be nothing else needed. The jar does indeed have the class file inside. Also inside are MyClass$1.class - MyClass$24.class, the META-INF folder with MANIFEST.MF inside, and org folder/eclipse folder/jdt folder/internal folder/jarinjarloader folder/containing: JIJConstants.class, JarRsrcLoader$ManifestInfo.class, JarRsrcLoader.class, RsrcURLConnection.class, RsrcURLStreamHandler.class, and RsrcURLStreamHandlerFactory.class.
    Some of these I don't understand being here since I don't import or use URL, any connection or input/output streams. Perhaps these are here to interact with the JRE?

    Again, this jar opens and runs great on the PC it was written on, AND on My laptop when I email it to myself. What could cause it not to work when emailed to other computers?

  11. #11
    NotTooOld is offline Hostage
    Join Date
    Apr 2013
    Location
    China
    Posts
    128
    Rep Power
    0

    Default Re: Help with runnable jar

    Quote Originally Posted by kjkrum View Post
    Post the error messages.
    I should have though of running this from the command line. from there I do get an error. "Cound not find or load main class AlphaPattern.class.
    Last edited by NotTooOld; 04-17-2013 at 05:38 AM.

  12. #12
    NotTooOld is offline Hostage
    Join Date
    Apr 2013
    Location
    China
    Posts
    128
    Rep Power
    0

    Default Re: Help with runnable jar

    Oh oh! I see that I too have a problem if trying to open from the command line.
    I enter java -jar AlphaPattern
    I get this error: Unable to access jarfile AlphaPattern.
    Enter: java -jar AlphaPattern.jar works though.

    The other errors were due to the file not being where I thought it was. Double clicking on it should eliminate those errors. When a .jar file is double clicked, what system call is made? I would expect {java -jar + the filename.jar of the file being double clicked}
    Last edited by NotTooOld; 04-17-2013 at 06:36 AM.

  13. #13
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default Re: Help with runnable jar

    Quote Originally Posted by NotTooOld View Post
    Oh oh! I see that I too have a problem if trying to open from the command line.
    I enter java -jar AlphaPattern
    I get this error: Unable to access jarfile AlphaPattern.
    Enter: java -jar AlphaPattern.jar works though.
    That's because the name of that .jar file isn't 'AlphaPattern'; it is 'AplhaPattern.jar'. The manifest entry in that file tells the jvm to look for the class name it is supposed to start.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  14. #14
    NotTooOld is offline Hostage
    Join Date
    Apr 2013
    Location
    China
    Posts
    128
    Rep Power
    0

    Default Re: Help with runnable jar

    Quote Originally Posted by JosAH View Post
    That's because the name of that .jar file isn't 'AlphaPattern'; it is 'AplhaPattern.jar'. The manifest entry in that file tells the jvm to look for the class name it is supposed to start.

    kind regards,

    Jos
    Not sure, but I don't think you read the last line you quoted. I got the file to work fine calling [java -jar AlphaPattern.jar] Question is: Why does this jar not open when I email it to another computer?

  15. #15
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,086
    Rep Power
    20

    Default Re: Help with runnable jar

    You'll need to launch the application from the command line on that other computer...or any other computer if it always fails.
    That way you might see an exception.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  16. #16
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default Re: Help with runnable jar

    Quote Originally Posted by NotTooOld View Post
    Not sure, but I don't think you read the last line you quoted. I got the file to work fine calling [java -jar AlphaPattern.jar] Question is: Why does this jar not open when I email it to another computer?
    I only explained to you why the last line is working while the previous line isn't; I don't know why your .jar file doesn't work after you've emailed it to somewhere else; you probably try to open a resource as a file (outside of the .jar file) that happens to be present on your computer but itsn't on the other computer(s).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Having problems making a runnable jar
    By Xainey in forum Eclipse
    Replies: 5
    Last Post: 12-27-2011, 05:21 AM
  2. Runnable JAR files on different platforms.
    By DiamondSoul in forum New To Java
    Replies: 2
    Last Post: 10-11-2011, 07:42 PM
  3. debug runnable jar
    By Levian in forum New To Java
    Replies: 0
    Last Post: 08-11-2011, 05:38 AM
  4. Running runnable jar AS
    By sashaxiv in forum Eclipse
    Replies: 0
    Last Post: 03-16-2011, 12:14 PM
  5. how to return a value from runnable method
    By udinulis in forum AWT / Swing
    Replies: 10
    Last Post: 07-20-2010, 05:06 AM

Posting Permissions

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