• Post Reply Bookmark Topic Watch Topic
  • New Topic

jar package unable to find file  RSS feed

 
Ranch Hand
Posts: 34
1
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • 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
  • 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: 34
1
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • 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
  • 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: 18800
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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: 34
1
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • 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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!