• 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

Failure in using getResource()

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please take a look at the following code:

This is a piece of code in the seranova.jar. This jar is used in another java file. and javaApplication.properties is bundled in seranova.jar. How come the java file couldn't find this property file?
Any clue?
Thanks,
Jenny
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't use "getFile" to get a java.io.File reference inside a jar, but you can get a URL reference to it.
Try:

(this may still not work, but we'll work on that)
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I should have also said is that what you most likely want to do it get the properties file into a java.util.Properties instance. If you look at URL, it has a method 'openStream' that returns an InputStream, and Properties has a method 'load' that accepts an InputStream.
Like they were made for each other, and you don't have to worry about pesky Files.
 
Jian Yi
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The whole error message:
java.io.FileNotFoundException: file:/C:/Program Files/IBM/Application Developer/workspace_ports/musicpillar/webApplication/WEB-INF/lib/seranova.jar!/com/seranova/core/javaApplication.properties (The filename, directory name, or volume label syntax is incorrect)
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Was that with your code or my code? I'm guessing yours, since the file:/... is a valid URL refering to the properties file in the JAR, but is not a valid java.io.File refering to the properties file in the JAR.
(note the exclaimation mark after the jar name in the file:/... bit - this is the bit that means it's not a valid File)
file:/C:/Program Files/IBM/Application Developer/workspace_ports/musicpillar/webApplication/WEB-INF/lib/seranova.jar -->!<-- /com/seranova/core/javaApplication.properties
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a piece of code in the seranova.jar. This jar is used in another java file. and javaApplication.properties is bundled in seranova.jar. How come the java file couldn't find this property file?
If the problem is that code inside the seranova.jar can't find the properties file in the same jar, the easiest solution is to unjar the code and place it in the web-inf/classes directory and delete the jar from the web-inf/lib directory. That should solve the problem since the file is now valid on the web application classpath.
If the seranova.jar is yours, make the change I mentioned above.
Dave
 
Jian Yi
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your advice. The problem is solved by using the inputstream.
Thanks again!!!
Jenny
 
reply
    Bookmark Topic Watch Topic
  • New Topic