Page 1 of 2 12 LastLast
Results 1 to 20 of 29
  1. #1
    pranav13's Avatar
    pranav13 is offline Member
    Join Date
    Oct 2008
    Location
    Greater Hyderabad
    Posts
    37
    Rep Power
    0

    Default [SOLVED] problem in building jar

    hi all
    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

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  3. #3
    pranav13's Avatar
    pranav13 is offline Member
    Join Date
    Oct 2008
    Location
    Greater Hyderabad
    Posts
    37
    Rep Power
    0

    Default

    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).

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Which jar file you use, jar inside dist folder of the project? Can you run it in the same location?

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

    Default

    See #13 below
    Last edited by Norm; 10-13-2008 at 05:43 PM.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Rather using the full path, try it with reference path. I mean something like,

    ./resources/License.txt
    Actually it's depends on where your folders are located, or from where you those resources are used.

  7. #7
    sameh_ammar is offline Member
    Join Date
    Jul 2008
    Posts
    2
    Rep Power
    0

    Default

    gooood thanks for all

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  9. #9
    pranav13's Avatar
    pranav13 is offline Member
    Join Date
    Oct 2008
    Location
    Greater Hyderabad
    Posts
    37
    Rep Power
    0

    Default

    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. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    im gettin sm path err. i came 2 kno abt this err
    Could you translate this to normal English?
    If you get errors, copy and paste the FULL TEXT without edits.

  11. #11
    pranav13's Avatar
    pranav13 is offline Member
    Join Date
    Oct 2008
    Location
    Greater Hyderabad
    Posts
    37
    Rep Power
    0

    Unhappy 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
    Documents\NetBeansProjects\MySetupWizard\dist\MySe tupWizard.jar!\mysetupwizard\
    resources\License.txt (The filename, directory name, or volume label syntax is i
    ncorrect)
    Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: bad p
    osition: 1
    at javax.swing.text.JTextComponent.setCaretPosition(J TextComponent.java:
    1398)
    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
    49)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.jav
    a:2169)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel
    .java:420)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:258
    )
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonL
    istener.java:236)
    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
    read.java:242)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThre
    ad.java:163)
    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!

  12. #12
    pranav13's Avatar
    pranav13 is offline Member
    Join Date
    Oct 2008
    Location
    Greater Hyderabad
    Posts
    37
    Rep Power
    0

    Default

    please tell me the correct way to get the path of files in the project.

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

    Default

    ...MySetupWizard.jar!\mysetupwizard\resources\Lice nse.txt
    This shows the path to the file in the jar file on a windows system.

    When you added this file to the jar file, did you preserve its path?
    mysetupwizard/resources/License.txt

    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.

  14. #14
    pranav13's Avatar
    pranav13 is offline Member
    Join Date
    Oct 2008
    Location
    Greater Hyderabad
    Posts
    37
    Rep Power
    0

    Question 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?

  15. #15
    pranav13's Avatar
    pranav13 is offline Member
    Join Date
    Oct 2008
    Location
    Greater Hyderabad
    Posts
    37
    Rep Power
    0

    Thumbs up I got the solution!

    hi

    i got the solution. as i told, its path problem. To access a resource(like txt file), I have used the following code...

    int chr;
    InputStream is = this.getClass().getResourceAsStream("myTextFile.tx t");
    while((chr = is.read()) != -1)
    str+=((char) chr);
    is.close();
    jTextPane1.setText(str);
    Thanks and Regards,
    Pranav

  16. #16
    pranav13's Avatar
    pranav13 is offline Member
    Join Date
    Oct 2008
    Location
    Greater Hyderabad
    Posts
    37
    Rep Power
    0

    Default

    hi,
    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,
    Pranav

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

    Default

    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/
    What program did you use to see the path to the License.txt in the jar file?
    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.

  18. #18
    pranav13's Avatar
    pranav13 is offline Member
    Join Date
    Oct 2008
    Location
    Greater Hyderabad
    Posts
    37
    Rep Power
    0

    Default

    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.getClass().getResourceAsStream("myTextFile.tx t");

    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,
    Pranav

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

    Default

    Copy and post the FULL text of the error messages including the command line.

    i havent used any path
    There is ALWAYS a path. It may be empty.

  20. #20
    pranav13's Avatar
    pranav13 is offline Member
    Join Date
    Oct 2008
    Location
    Greater Hyderabad
    Posts
    37
    Rep Power
    0

    Default

    in shell prompt (in linux)
    java -jar mysetupwizard.jar
    Null Peer?! Exception

    (and an empty form is displayed)

    thats it. nothing is happening.
    it is not displaying any other error message.
    Thanks and Regards,
    Pranav

Page 1 of 2 12 LastLast

Similar Threads

  1. Problem with String Building
    By Albert in forum New To Java
    Replies: 2
    Last Post: 04-30-2012, 12:49 AM
  2. JAR Building Problem
    By GhosT in forum New To Java
    Replies: 12
    Last Post: 09-27-2008, 03:21 PM
  3. help needed regarding tree building
    By invincible_me in forum New To Java
    Replies: 2
    Last Post: 08-12-2008, 01:44 PM
  4. building a house
    By dc2acgsr99 in forum Java Applets
    Replies: 4
    Last Post: 03-07-2008, 11:18 PM
  5. Building a document from a DOM
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-03-2008, 09:22 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
  •