Results 1 to 20 of 29
Thread: [SOLVED] problem in building jar
- 10-08-2008, 08:44 AM #1
[SOLVED] problem in building jar
recently i started working with java. i have developed a desktop app using swings in NetBeans IDE. It has 5 classes, a text file and an image. It is working fine in the IDE. but when i create a jar and double click it or run it from console it is giving an error saying that FileNotFoundException.
Actually, im reading License info from the txt file in the proj.
pls help me out!
thanks in advance
- 10-08-2008, 09:14 AM #2
- 10-08-2008, 09:31 AM #3
im using a text file wch consists of some text(like license agreement). im reading it from my class n fill uit in a textarea.
i 've used the following code to access the file. but invain.
String myFile = getClass().getResource("/myproj/resources/License.txt");
it is working fine in the NetBeans IDE. But after building jar file, i cud nt run it( both from console and windows, by dbl clicking).
- 10-08-2008, 09:44 AM #4
- 10-08-2008, 03:06 PM #5
See #13 below
Last edited by Norm; 10-13-2008 at 05:43 PM.
- 10-09-2008, 04:11 AM #6
Rather using the full path, try it with reference path. I mean something like,
- 10-10-2008, 07:58 PM #7Member
- Join Date
- Jul 2008
- Rep Power
gooood thanks for all
- 10-11-2008, 05:22 AM #8
- 10-13-2008, 07:03 AM #9
im using the reference path, like /setup/resources/license.txt
while i was trying to run the jar file in dist folder im gettin sm path err. i came 2 kno abt this err when i run it from cmd prompt.
- 10-13-2008, 02:13 PM #10im gettin sm path err. i came 2 kno abt this err
If you get errors, copy and paste the FULL TEXT without edits.
- 10-13-2008, 02:47 PM #11
here is the error message
sorry! please don't mind. I am habituated to that kind. thats why i have typed like that.
Thank you very much for your quick reply to my query.
i think this is because of path error.
I have used the following for getting the file name.
this.getClass().getResource("/mysetupwizard/resources/License.txt").toString().replace("%20", " ").substring(6);
I am not sure about this is the correct way to use files in the project or not? Please let me know the correct method to get file.
The error message is as follows. please go through it and tell me a solution.
java -jar "C:\Documents and Settings\trapranav\My Documents\NetBeansProjects\MySetupWizard\dist\MySe tupWizard.jar"
ERROR: java.io.FileNotFoundException: le:\C:\Documents and Settings\trapranav\My
resources\License.txt (The filename, directory name, or volume label syntax is i
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: bad p
at javax.swing.text.JTextComponent.setCaretPosition(J TextComponent.java:
at mysetupwizard.resources.Step2.<init>(Step2.java:23 )
at mysetupwizard.resources.Step1.jButton2ActionPerfor med(Step1.java:110)
at mysetupwizard.resources.Step1.access$100(Step1.jav a:16)
at mysetupwizard.resources.Step1$2.actionPerformed(St ep1.java:53)
at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:18
at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.jav
at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel
at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:258
at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonL
at java.awt.Component.processMouseEvent(Component.jav a:5517)
at javax.swing.JComponent.processMouseEvent(JComponen t.java:3135)
at java.awt.Component.processEvent(Component.java:528 2)
at java.awt.Container.processEvent(Container.java:196 6)
at java.awt.Component.dispatchEventImpl(Component.jav a:3984)
at java.awt.Container.dispatchEventImpl(Container.jav a:2024)
at java.awt.Component.dispatchEvent(Component.java:38 19)
at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4212
at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:3822)
at java.awt.Container.dispatchEventImpl(Container.jav a:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1791 )
at java.awt.Component.dispatchEvent(Component.java:38 19)
at java.awt.EventQueue.dispatchEvent(EventQueue.java: 463)
at java.awt.EventDispatchThread.pumpOneEventForHierar chy(EventDispatchTh
at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThre
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:110)
Thanks in advance!
- 10-13-2008, 02:48 PM #12
please tell me the correct way to get the path of files in the project.
- 10-13-2008, 04:11 PM #13...MySetupWizard.jar!\mysetupwizard\resources\Lice nse.txt
When you added this file to the jar file, did you preserve its path?
Look at the contents of the jar file to see if you have the correct path.
You can use WinZip to display it. Or rename it to .zip and open it.
Last edited by Norm; 10-13-2008 at 05:44 PM.
- 10-14-2008, 06:22 AM #14
txt file is there in the jar file
ya... License.txt is there in the jar file in /mysetupwizard/resources/
can u please tell why it is not coming?
- 10-14-2008, 11:12 AM #15
I got the solution!
i got the solution. as i told, its path problem. To access a resource(like txt file), I have used the following code...
InputStream is = this.getClass().getResourceAsStream("myTextFile.tx t");
while((chr = is.read()) != -1)
jTextPane1.setText(str);Thanks and Regards,
- 10-14-2008, 12:04 PM #16
as said, i got the solution and it is working fine in windows.
but when im trying to execute my jar file in linux, it is giving an error as
Null Peer?! Exception
and the form is empty.
i copied the jar file and lib folder to linux and executed.
pls gimme a solution for this!Thanks and Regards,
- 10-14-2008, 02:34 PM #17
Is your program reading the file from the jar file or from the disk? To be sure which, have the contents of the file be different for the two locations.
License.txt is there in the jar file in /mysetupwizard/resources/
There would NOT be a leading / in that display.
Yes it is definitely a path problem. The path used by getResource is not where the file is located in the jar file.
Last edited by Norm; 10-14-2008 at 02:36 PM.
- 10-14-2008, 02:44 PM #18
first of all, Thankyou very much for ur interest in solving my problem.
i havent used any path. i directly gave the file name.
at first, i gave the path relative to root. but now i gave it relative to the class.
this solved my problem.
But now, i got a new problem. I cudnt execute this jar in Linux.
It is giving Null Peer?! Exception and displaying an empty form.
pls tell me a solution for this!Thanks and Regards,
- 10-14-2008, 02:57 PM #19
Copy and post the FULL text of the error messages including the command line.
i havent used any path
- 10-14-2008, 03:09 PM #20
- By Albert in forum New To JavaReplies: 2Last Post: 04-30-2012, 12:49 AM
- By GhosT in forum New To JavaReplies: 12Last Post: 09-27-2008, 03:21 PM
- By invincible_me in forum New To JavaReplies: 2Last Post: 08-12-2008, 01:44 PM
- By dc2acgsr99 in forum Java AppletsReplies: 4Last Post: 03-07-2008, 11:18 PM
- By Java Tip in forum Java TipReplies: 0Last Post: 01-03-2008, 09:22 AM