Page 1 of 3 123 LastLast
Results 1 to 20 of 60
  1. #1
    rajkobie is offline Member
    Join Date
    Nov 2010
    Posts
    54
    Rep Power
    0

    Default Why isnt my JAR file not working outside of the main folder with bluej classes?

    I made a jar file and it works fine while the jar file is inside the folder with the bluej classes.

    But when i drag to to the desktop for example, the program doesnt run anymore. I double click nothing happens.

    i googled the problem and i could not find anything. Please help resolve my issue.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    In the absence of runnable (brief!) code it is hard to say.

    But a common cause of this sort of thing is where your program accesses resources - like image files and the like. It might run in one location (where the files exist) but fail in another (because the files do not exist there). The solution in such cases is to package such resources within the jar archive and access them using instances of URL rather than File.

    I double click nothing happens.
    It is quite possible that something - a useful runtime error message - occurs but you don't see it. Try running your program in the jar archive at the new location, but from the command line. That way any runtime messages will be visible in the console.

  3. #3
    rajkobie is offline Member
    Join Date
    Nov 2010
    Posts
    54
    Rep Power
    0

    Default

    The solution in such cases is to package such resources within the jar archive and access them using instances of URL rather than File
    What do you mean by by package?

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    I mean that the resources should be placed within the jar archive the same way classes are. I have no idea how this is done with BlueJ, but the process is described in some detail in the Packaging Programs in JAR Files section of Oracle's Tutorial.

  5. #5
    rajkobie is offline Member
    Join Date
    Nov 2010
    Posts
    54
    Rep Power
    0

    Default

    I think it is something wrong with the graphics

    i take in images as

    imgMyImage = new ImageIcon ( "filename" ).getImage( );
    image is right in the folder where the program is run from. Is that the issue?

  6. #6
    rajkobie is offline Member
    Join Date
    Nov 2010
    Posts
    54
    Rep Power
    0

    Default

    I get the images from the same folder that i run my classes from. is that why?

  7. #7
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Quote Originally Posted by rajkobie View Post
    imgMyImage = new ImageIcon ( "filename" ).getImage( );
    In addition to the need to put the filename resource into the jar archive, that code creates an ImageIcon based on a File rather than a URL. Once you have the resource inside the archive you should use it with the other (URL) ImageIcon constructor.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,564
    Rep Power
    23

    Default

    it works fine while the jar file is inside the folder
    how are you executing the jar file? What is the command line when you execute it? What OS are you on?

    Do you get any error messages?

  9. #9
    rajkobie is offline Member
    Join Date
    Nov 2010
    Posts
    54
    Rep Power
    0

    Default

    my command line is

    jar cfm name.jar manifest.txt *

  10. #10
    rajkobie is offline Member
    Join Date
    Nov 2010
    Posts
    54
    Rep Power
    0

    Default

    How do i do that? and put to archive

  11. #11
    rajkobie is offline Member
    Join Date
    Nov 2010
    Posts
    54
    Rep Power
    0

    Default

    Quote Originally Posted by pbrockway2 View Post
    In addition to the need to put the filename resource into the jar archive, that code creates an ImageIcon based on a File rather than a URL. Once you have the resource inside the archive you should use it with the other (URL) ImageIcon constructor.
    How do i do that? and put to archive

    I am not really tech smart

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,564
    Rep Power
    23

    Default

    Here's are sample jar command:

    jar -cmf SlideShow.mnf SlideShowApp.jar ImgIdxEditor.html
    jar -uf SlideShowApp.jar SlideShow\*.class NormsTools\GetInput*.class

    jar cfm name.jar manifest.txt *
    Your trailing * would put all the files into the jar file.
    Look in the jar file and check if everything you need is there. You can rename the file by adding .zip to the filename and use a standard utility to read the jar file as a zip.

  13. #13
    rajkobie is offline Member
    Join Date
    Nov 2010
    Posts
    54
    Rep Power
    0

    Default

    no man none of those work. I have been trying for 6 hours now. it just works in the bluej folder but breaks down when i put in the outside.

  14. #14
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Quote Originally Posted by pbrockway2 View Post
    In the absence of runnable (brief!) code it is hard to say.

    But a common cause of this sort of thing is where your program accesses resources - like image files and the like. It might run in one location (where the files exist) but fail in another (because the files do not exist there). The solution in such cases is to package such resources within the jar archive and access them using instances of URL rather than File.



    It is quite possible that something - a useful runtime error message - occurs but you don't see it. Try running your program in the jar archive at the new location, but from the command line. That way any runtime messages will be visible in the console.
    Have you done that yet? I don't see a post saying the results of such a test.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  15. #15
    rajkobie is offline Member
    Join Date
    Nov 2010
    Posts
    54
    Rep Power
    0

    Default

    Yes I tried that way. For example, i have my jar file dragged to the desktop and i went to command panel and ran through it. It does execute. but nothing happens. i tried it multiple times. it executes nothing happens

  16. #16
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    BTW a jar file is a Java Archive.

    What I'm seeing in this thread is a lack of communication on your part. People are offering advice and things to try, however you are not giving us good descriptions of the problem.

    How are you loading the files? Try posting a SSCCE of that code, that way we can see how its supposed to read your files. Once we know what you're trying to accomplish with your code, we can offer better help.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  17. #17
    rajkobie is offline Member
    Join Date
    Nov 2010
    Posts
    54
    Rep Power
    0

    Default

    ok thank you. I am not really tech smart. I do not know anything about java really. I mostly learn my stuff off tutorial etc.

    Since this is a school project I cannot post the whole code but i can post how i load files.

    For images

    Image myImage = new ImageIcon ( "filename and extension" ).getImage( );

    Filename and extension - they are in the same folder as i run bluej files so i just write something like riverImage.jpg. I dont give any directions where it is.

    For audio

    File myFile = new File ( "file name and extention" );
    AudioInputStream in = AudioSystem.getAudioInputSteam ( myFile );
    Clip mySound = AudioSystem.getClip ( );
    mySound.open ( in );

    This is how i load files to my project. Other ways its only code. Again here to the filename is just written as ex. breeze.wav. No other directions to folder or anything. I only use wav files for sound.

    I am sorry if this isnt enough. This is for the best of my ability.

    oh yea one more part

    for images,

    if i say

    Image myImage = new ImageIcon ( getClass( ).getResource("filename and extension" ) ).getImage( );

    They project wont even work in the folder that has bluej files. I am like 80% its something wrong with how i load materials.
    Last edited by rajkobie; 05-21-2011 at 08:50 AM.

  18. #18
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    If you put your code in [code][/code] tags it would be easier to see what is code and what is not.

    Have you put all of your resources inside your JAR file?
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  19. #19
    rajkobie is offline Member
    Join Date
    Nov 2010
    Posts
    54
    Rep Power
    0

    Default

    I don't think so sir.

    How exactly do i do so? How do i put in the JAR file?

  20. #20
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    I'm not sure how you would do it with BlueJ, perhaps someone else will be able to help you. In the meantime I will scour google for you.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

Page 1 of 3 123 LastLast

Similar Threads

  1. Why isnt this working?
    By GoingThroAPhase in forum New To Java
    Replies: 4
    Last Post: 04-03-2010, 02:36 AM
  2. My rotate 2d pos method isnt working correctly..
    By Addez in forum New To Java
    Replies: 5
    Last Post: 12-01-2009, 09:04 AM
  3. Replies: 6
    Last Post: 11-12-2009, 10:50 AM
  4. BlueJ arrow missing betwen two classes
    By jboy in forum New To Java
    Replies: 2
    Last Post: 10-29-2009, 12:42 PM
  5. Replies: 1
    Last Post: 04-17-2008, 02:30 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
  •