Results 1 to 20 of 60
- 05-21-2011, 12:18 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 54
- Rep Power
- 0
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.
- 05-21-2011, 01:06 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
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.I double click nothing happens.
- 05-21-2011, 01:33 AM #3
Member
- Join Date
- Nov 2010
- Posts
- 54
- Rep Power
- 0
What do you mean by by package?The solution in such cases is to package such resources within the jar archive and access them using instances of URL rather than File
- 05-21-2011, 01:52 AM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
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.
- 05-21-2011, 01:58 AM #5
Member
- Join Date
- Nov 2010
- Posts
- 54
- Rep Power
- 0
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?
- 05-21-2011, 02:08 AM #6
Member
- Join Date
- Nov 2010
- Posts
- 54
- Rep Power
- 0
I get the images from the same folder that i run my classes from. is that why?
- 05-21-2011, 02:10 AM #7
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
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.
- 05-21-2011, 02:42 AM #8
how are you executing the jar file? What is the command line when you execute it? What OS are you on?it works fine while the jar file is inside the folder
Do you get any error messages?
- 05-21-2011, 03:20 AM #9
Member
- Join Date
- Nov 2010
- Posts
- 54
- Rep Power
- 0
my command line is
jar cfm name.jar manifest.txt *
- 05-21-2011, 03:21 AM #10
Member
- Join Date
- Nov 2010
- Posts
- 54
- Rep Power
- 0
How do i do that? and put to archive
- 05-21-2011, 03:22 AM #11
Member
- Join Date
- Nov 2010
- Posts
- 54
- Rep Power
- 0
- 05-21-2011, 03:26 AM #12
Here's are sample jar command:
jar -cmf SlideShow.mnf SlideShowApp.jar ImgIdxEditor.html
jar -uf SlideShowApp.jar SlideShow\*.class NormsTools\GetInput*.class
Your trailing * would put all the files into the jar file.jar cfm name.jar manifest.txt *
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.
- 05-21-2011, 06:16 AM #13
Member
- Join Date
- Nov 2010
- Posts
- 54
- Rep Power
- 0
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.
- 05-21-2011, 06:50 AM #14
- 05-21-2011, 07:18 AM #15
Member
- Join Date
- Nov 2010
- Posts
- 54
- Rep Power
- 0
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
- 05-21-2011, 07:22 AM #16
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.
- 05-21-2011, 08:47 AM #17
Member
- Join Date
- Nov 2010
- Posts
- 54
- Rep Power
- 0
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.
- 05-21-2011, 08:52 AM #18
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.
- 05-21-2011, 09:32 AM #19
Member
- Join Date
- Nov 2010
- Posts
- 54
- Rep Power
- 0
I don't think so sir.
How exactly do i do so? How do i put in the JAR file?
- 05-21-2011, 09:38 AM #20
Similar Threads
-
Why isnt this working?
By GoingThroAPhase in forum New To JavaReplies: 4Last Post: 04-03-2010, 02:36 AM -
My rotate 2d pos method isnt working correctly..
By Addez in forum New To JavaReplies: 5Last Post: 12-01-2009, 09:04 AM -
The code isnt working unless I add print statements at diffrent points!:confused:
By Addez in forum New To JavaReplies: 6Last Post: 11-12-2009, 10:50 AM -
BlueJ arrow missing betwen two classes
By jboy in forum New To JavaReplies: 2Last Post: 10-29-2009, 12:42 PM -
Help with testing methods and classes in JUnit, using BlueJ
By Jonasse in forum New To JavaReplies: 1Last Post: 04-17-2008, 02:30 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks