Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: File not found in class path

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Location
    Tucson, AZ
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default File not found in class path

    Got a strange problem here. I have a pdf file, Readme.pdf that I stuck in the source folder and pull it as a resource. I know the file does in fact exist in the .jar file as I have looked at the file with an archiver and it is physical inside the .jar. The code works fine on a windows machine and launches the appropriate Adobe viewer. On my Linux machine I get the following error:

    Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: The file: file:/home/jeff/TenDataManager/TenDataManager.jar!/com/n7yg/datamanager/Readme.pdf doesn't exist.
    at java.awt.Desktop.checkFileValidation(Desktop.java: 209)
    at java.awt.Desktop.open(Desktop.java:270)
    at com.n7yg.datamanager.MainForm$12.mouseReleased(Mai nForm.java:395)
    at java.awt.AWTEventMulticaster.mouseReleased(AWTEven tMulticaster.java:290)

    What is interesting is that it will run and find the file when it is run inside of the Eclipse IDE.

    public static final URL readme = MainForm.class.getResource("/com/n7yg/datamanager/Readme.pdf");
     
    mntmReadme.addMouseListener(new MouseAdapter() {
    			@Override
    			public void mouseReleased(MouseEvent e) {
    				if (Desktop.isDesktopSupported()) {
    				    try {
    				        File myFile = new File(readme.getFile());
    				        Desktop.getDesktop().open(myFile);
    				    } catch (IOException ex) {
    				        // no application registered for PDFs
    				    }
    				}
    			}
    		});

    Any ideas why this might be happening?


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    939
    Thanks
    6
    Thanked 202 Times in 178 Posts

    Default Re: File not found in class path

    You seem to be getting an exception from open() because you are supplying a reference to a File instance, but there is no actual file with the name specified by that instance.

    A collection of bytes within a .jar archive is not a file. The .jar archive is a file, its contents considered individually are not. I guess if you want to have the desktop manager launch the default browser - ie use open() - you will have to extract the jar entry to some temporary folder. If the pdf contains links they may have to be extracted as well.

    [Edit] And to see what is going on under different circumstances (different OSs, executing the jar or running from the class files, within Eclipse or not, etc) print the full name of the file before you call open() and check whether there is a file of that name on your disk.

  3. The Following User Says Thank You to pbrockway2 For This Useful Post:

    Jeff.Steinkamp (January 1st, 2013)

  4. #3
    Junior Member
    Join Date
    Dec 2012
    Location
    Tucson, AZ
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: File not found in class path

    Then why does it work correctly under Windows when run as a jar? It seems to find the file without any difficulty and sends it to Adobe. Why does it run correctly inside of the Eclipse IDE on both windows and Linux? The declaration for readme, will resolve to /home/jeff/TenDataManager/TenDataManager.jar!/com/n7yg/datamanager/Readme.pdf. Under windows I can pull that file as a FileStrem and write it to an OutPutStream to another location on the disk. That fails in Linux also.

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,619
    Thanks
    45
    Thanked 1,958 Times in 1,932 Posts

    Default Re: File not found in class path

    the file does in fact exist in the .jar file as I have looked at the file with an archiver and it is physical inside the .jar.
    Make sure there isn't a copy of the file outside the jar file that is being read.
    If you don't understand my answer, don't ignore it, ask a question.

  6. The Following User Says Thank You to Norm For This Useful Post:

    Jeff.Steinkamp (January 1st, 2013)

  7. #5
    Junior Member
    Join Date
    Dec 2012
    Location
    Tucson, AZ
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: File not found in class path

    Well gents, I stand corrected. After a couple of hours searching on my Winders box, I did find that a copy(outdated of course) of Readme.pdf was in a folder that was on the windows path statement. Removing that file now makes Windows behave as does Linux. So, to solve the original problem, I created a /doc folder under the folder where the jar file will reside and created a path to that in the code and all is now well.

    Something rather strange I noticed, but it does not seem to affect anything is when I launch the following code:

    Desktop.getDesktop().open(myFile);

    I get this in the standard error: fatal : Not a git repository (or any of the parent directories): git

    I see this only on Windows.

  8. #6
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    939
    Thanks
    6
    Thanked 202 Times in 178 Posts

    Default Re: File not found in class path

    fatal : Not a git repository (or any of the parent directories): git
    Again, the place I'd start to look is the full path reported when you print myFile. Although now the problem "feels" a little different.

    Perhaps you could construct a small example of the error occurring. (Ie without all the Swing stuff, just giving myFile a value and calling open()). That way we can all see it. Describe the circumstances under which the program behaviour can be repeated - you said Windows, but is Eclipse involved?

  9. #7
    Junior Member
    Join Date
    Dec 2012
    Location
    Tucson, AZ
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Thumbs up Re: File not found in class path

    Quote Originally Posted by pbrockway2 View Post
    Again, the place I'd start to look is the full path reported when you print myFile. Although now the problem "feels" a little different.

    Perhaps you could construct a small example of the error occurring. (Ie without all the Swing stuff, just giving myFile a value and calling open()). That way we can all see it. Describe the circumstances under which the program behavior can be repeated - you said Windows, but is Eclipse involved?
    Problem solved!! I wrote a small program to demonstrate opening of not only the PDF file, but also a text files as my first though was an issue with rendering the PDF file to Acrobat. But that was not the case as the text file threw the same error. Yes Eclipse is involved, but the error does present itself when the code is run outside of Eclipse. I happed to catch out of the corner of my eye a Git Repository windows open then immediately closed. So that got me to looking and I discovered that about a year ago or so the Git Repository System got installed on this machine, for some reason that I no longer remember. Since I have no use for a Revision Control System at the house, POOF, that puppy is in the bit bucket. Problem solved .

    It might be interesting to note, this solved a few other lingering issues I've had with this Windows box for quite some time also. So, my venture into the World of Java has started out quite well in 2013. Thanks for all the pointers.

  10. #8
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    939
    Thanks
    6
    Thanked 202 Times in 178 Posts

    Default Re: File not found in class path

    Great, I'm glad you've got it sorted out.

Similar Threads

  1. class not found
    By aki in forum Java Applets
    Replies: 1
    Last Post: May 23rd, 2012, 06:50 AM
  2. How to load class path for .properties file
    By kewlkeny in forum Web Frameworks
    Replies: 1
    Last Post: January 23rd, 2012, 07:40 AM
  3. how to get value path file from jsp form- input type file
    By meeGoreng in forum JavaServer Pages: JSP & JSTL
    Replies: 4
    Last Post: October 4th, 2011, 12:05 AM
  4. What is wrong with this code class not found
    By newbieJava in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 19th, 2011, 05:39 PM
  5. Main Class Not Found Problem
    By shadow in forum Java Theory & Questions
    Replies: 3
    Last Post: September 29th, 2009, 09:42 AM