Results 1 to 14 of 14
- 05-31-2010, 03:23 AM #1
Couple more questions on JAR Files :S
Many apologies if it seems like I'm spamming the forums. I just seem to stumble upon many questions and there are always some questions that google cannot answer (or I suck at googl'ing). Anyhow, these are my questions:
1. Signing JAR files ( Signing JAR Files (The Java™ Tutorials > Deployment > Packaging Programs in JAR Files) ) What type of extension does the .keystore file need? What format is used to store the storepass and keypass in the .keystore file? Does it need headers like the manifest file? An example would suffice ;)
2. So I made my package into a JAR file. The container (JFrame) has an image instead of the JAVA coffee symbol by the title (used BufferedImage). Think it would be better explained by displaying the code:
When I do java -jar SudokuJar.jar in cmd, the custom icon is displayed! But, when I make a project in Eclipse, go to properties (for that project) > Java Build Path > Add External Jars > SudokuJar.jar, make a driver program with the following content:Java Code:package sudoku; public class SudokuFrame extends JFrame { .... public SudokuFrame() { this.setIcon(getIcon()); .... } public BufferedImage getIcon() { BufferedImage sudokuIcon = null; try { sudokuIcon = ImageIO.read(new File("sudoku\\aziz_icon.png")); } catch (IOException e) {} return sudokuIcon; } .....
THE ICON IS GONE! (Application is still displayed btw) I'm thinking the location of the image changed. If so, where to? And how can I make the icon display in the eclipse driver program? If not, I would still like to know what's wrong lol.Java Code:import sudoku.SudokuWorld; public class test { public static void main (String[] args) { SudokuWorld test = new SudokuWorld(); test.display(); } }
Thanks in advance.Last edited by Lil_Aziz1; 05-31-2010 at 04:05 AM.
"Experience is what you get when you don't get what you want" (Dan Stanford)
"Rise and rise again until lambs become lions" (Robin Hood)
- 05-31-2010, 05:54 AM #2
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
You cannot use java.io.File lib with unsigned applet ;)
the code shouldn't actually work in your browser sandbox ;)
I mean this code block
P.S> I dearly hope I understood the question...Java Code:public BufferedImage getIcon() { BufferedImage sudokuIcon = null; try { sudokuIcon = ImageIO.read(new File("sudoku\\aziz_icon.png")); } catch (IOException e) {} return sudokuIcon; }Last edited by Webuser; 05-31-2010 at 05:57 AM.
- 05-31-2010, 04:40 PM #3
Sorry about any ambiguity in question #2. Let me try again:
My java application has one package, called sudoku. I converted my package into a JAR file (it is unsigned at the moment) called SudokuJar.jar. The JAR file also has a Main-Class called DriverProgram. The manifest file DOES contain this header:
Now when I run the jar file in CMD with the following command:Java Code:Main-Class: sudoku.DriverProgram
The getIcon() method returns aziz_icon.png. I can tell because the JAVA symbol on the top left corner was replaced by aziz_icon.png.Java Code:java -jar SudokuJar.jar
Next, I made a new java project called TestProject in Eclipse. I added the JAR file SudokuJar.jar by doing the following:
Then, I made a driver program in TestProject called test. The content of test is in the first post. When I run test, the java symbol on the top left corner is still there; consequently aziz_icon.png is not there.Java Code:Right click on TestProject > Properties > Java Build Path (on the left side) > Add External JARs.. (on the ride side) > Locate SudokuJar.jar > Open > OK
What's wrong?
Thanks in advance."Experience is what you get when you don't get what you want" (Dan Stanford)
"Rise and rise again until lambs become lions" (Robin Hood)
- 06-01-2010, 04:40 AM #4
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
to add any images you have to use an anchor class. As a rule it is a.class and place it into images project package
So then you can simply ref your app with this image as
I recommend to readJava Code:import images; ... Image image=ImageIO.read(a.class.getResourceAsStream("image.PNG"));
this How to Use Icons (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
this ImageIO (Java Platform SE 6)
and this Reading/Loading an Image (The Java™ Tutorials > 2D Graphics > Working with Images)
P.S. Study to use Google, pal ;)If my answer helped you. Please click my "REP" button and add a comment
Have a Good Java Coding :)
- 06-01-2010, 09:37 AM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 06-01-2010, 03:27 PM #6
SO the program works ok outside of Eclipse when you execute it from a command prompt but fails when in Eclipse? Recommendation: Don't use Eclipse to execute it.in Eclipse
Can you add some debug code to the app to see where it is looking for the image. I'm sure Eclipse uses directories differently than you expect.
BTW Java applications don't need permission to access things on a system. Signing is for browser loaded applets that want to access things.
- 06-04-2010, 06:52 PM #7
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
If my answer helped you. Please click my "REP" button and add a comment
Have a Good Java Coding :)
- 06-04-2010, 07:56 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 06-04-2010, 08:19 PM #9
Senior Member
- Join Date
- Feb 2009
- Posts
- 303
- Rep Power
- 5
Why do you even need the a.class? I've always used this.getClass().getResourceAsStream(path) where path is the path to the file in the jar file.
- 06-04-2010, 08:25 PM #10
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
- 06-04-2010, 08:28 PM #11
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
- 06-04-2010, 08:29 PM #12
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 06-04-2010, 08:34 PM #13
Senior Member
- Join Date
- Feb 2009
- Posts
- 303
- Rep Power
- 5
I guess I could see how it could be useful if the image folder is moved somewhere as you wouldn't need to update all the paths to the Images, but rather just the import statement to the a.class, however I usually just have a folder dubbed images which I dump them all into.
- 06-05-2010, 08:44 AM #14
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Couple questions about Java
By theadolescent in forum New To JavaReplies: 3Last Post: 05-19-2010, 02:13 AM -
Couple Questions on Thread
By Lil_Aziz1 in forum Threads and SynchronizationReplies: 5Last Post: 01-06-2010, 02:02 PM -
Couple of questions regarding threading
By exernet in forum New To JavaReplies: 1Last Post: 12-15-2009, 12:23 PM -
Couple of newbie questions
By ananasman in forum New To JavaReplies: 11Last Post: 11-20-2008, 11:54 PM -
a couple of questions about Software Engineering plz
By pheonix in forum New To JavaReplies: 9Last Post: 10-18-2008, 04:31 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks