• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jar package unable to find file

 
Ranch Hand
Posts: 42
1
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Please advise if you can I am having a small issue when packaging the java project into a jar....

1) In Eclipse or command line this works...



2) Once I package it on a jar I am getting the following error

IOException: java.io.FileNotFoundException: /license-uk.html (No such file or directory)

3) check the package and it's in the root of the package as required.

$ jar -tf SmallSecureText.jar | grep license-uk.html
license-uk.html

Please if anyone know why I would be greatly appreciate it.


Many Thanks
 
Ranch Hand
Posts: 74
5
Eclipse IDE Python Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you pack your jar? Ant? Jardesc? To answer your question I assume it will be necessary to post your build file here. If you build your jar file via mouse clicks in Eclipse you can check the box to save your build configuration as a file and post the file here.
 
Ricardo Wagemaker
Ranch Hand
Posts: 42
1
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christian Pflugradt wrote:How do you pack your jar? Ant? Jardesc? To answer your question I assume it will be necessary to post your build file here. If you build your jar file via mouse clicks in Eclipse you can check the box to save your build configuration as a file and post the file here.



Hi Christian,

I am using clicking on Eclipse and it seem to save a xml file but that does not provide any useful information that I can see. Is that what you are referring too?

Many Thanks
 
Peter Muster
Ranch Hand
Posts: 74
5
Eclipse IDE Python Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The xml file should provide information what is included in the jar file. However it just came to my mind that getResource might not work. I think it works only with physical files. Instead of getResource try getResourceAsStream.

See official documentation here. The method will return an InputStream which you have to read, not a file. I don't know what you intended to do with the file object so I don't know how much conversion / processing you have to do to get the desired result out of the InputStream.

You should check the return value from getResourceAsStream in your Eclipse debugger. If it is null the resource is not included in your jar (that's why I asked about the build xml file), otherwise you should be able to read it.

Update:

Your code should then look like this (plus the respective import statement).

 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Christian is correct. The "files" and "directories" inside a ZIP or JAR file are not actually filesystem objects (despite some GUI desktops that can make them look like they are). So anything relating to the java.io.File classes isn't likely to work on them.
 
Ricardo Wagemaker
Ranch Hand
Posts: 42
1
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So been playing with the code and managed to get it to load even when running it from within a executable JAR but there is a small catch now...

In Eclipse the file is presented in HTML format.

In the JAR file the file is presented in plain text..

BEFORE: ONLY WORKED IN ECLIPSE




AFTER: IN ECLIPSE AS HTML BUT IN JAR AS PLAIN TEXT




So the only thing left is for me to see the page in Eclipse & JAR as a HTML rather than txt once exported to JAR.
 
Brace yourself while corporate america tries to sell us its things. Some day they will chill and use tiny ads.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic