Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

JAR File cant read file path within Jar

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks in Advance,
I dont know where my problem exactly coming from, i am using netbeans to develop desktop application. if i run in the netbeans IDE fine, everything is running smoothly?
but when i run the application in a Jar it throws an exception;


Point to Note : I have imported entire Maths folder content.

String xmlFile =getClass().getResource("/Maths/answer.xml").getPath();


this line of code runs fine in netbeans IDE but not in the JAR outside the IDE;

i found couple of answers but all that didnt work for me please help me.
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

nasir ali wrote:Point to Note : I have imported entire Maths folder content.


When you say imported, do you mean the folder is archived (contained) in the jar file?

What is the Exception that's thrown? Read TellTheDetails

And welcome to the ranch, nasir ali
 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would also be useful if you could post the structure of your jar file.
 
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

nasir ali wrote:Thanks in Advance,
I dont know where my problem exactly coming from, i am using netbeans to develop desktop application. if i run in the netbeans IDE fine, everything is running smoothly?
but when i run the application in a Jar it throws an exception;


Point to Note : I have imported entire Maths folder content.

String xmlFile =getClass().getResource("/Maths/answer.xml").getPath();


this line of code runs fine in netbeans IDE but not in the JAR outside the IDE;

i found couple of answers but all that didnt work for me please help me.


Tell me one thing is Maths in the next immediate directory after src ?
 
nasir ali
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Jai wrote:

nasir ali wrote:Point to Note : I have imported entire Maths folder content.


When you say imported, do you mean the folder is archived (contained) in the jar file?

What is the Exception that's thrown? Read TellTheDetails

And welcome to the ranch, nasir ali



Yes indeed, i drag the Maths folder in the Netbeans source.. and it throws this exception

when i run through command prompt or double click it this is the location of my jar
C:\Users\nasir>java -jar "C:\Users\nasir\Documents\NetBeansProjects\Mathamatics\dist\Mathamatics.jar"

unfor seen error file:\C:\Users\nasir\Documents\NetBeansProjects\Mathamatics\dist\Mathamatics.jar!\maths\answer.xml (The filename, directory name, or volu
me label syntax is incorrect)

but only this occurs if i run the JAr file outside netbeans.

the Structure of my project is as follows..
- Mathamatics
-source packages
-images
-maths ( here is my problem when i build the jar) it wont excute
-library


 
James Boswell
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the structure of your jar file, not your project.
 
nasir ali
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

James Boswell wrote:What is the structure of your jar file, not your project.



the Structure of my project is as follows..
- Mathamatics
-source packages
-images
-maths ( here is my problem when i build the jar)
-library

and this are what is inside the Jar file

Mathamatics.jar
Images
META-INF
maths- ( this is the folder which is present inside the JAR )
Maths(Java class files)

this all what is inside my Jar file
 
James Boswell
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming the file you are after is in the Maths folder (not maths), try removing the leading '/' from the string being passed to the getResource method.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

nasir ali wrote:and this are what is inside the Jar file

Mathamatics.jar


Hold it right there. Java doesn't support nesting of jars inside a jar. Read the NetBeans help for the correct way to include dependencies. (Project Properties => Libraries)
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

nasir ali wrote:Point to Note : I have imported entire Maths folder content.


No, you haven't. Classes, not folders, are imported. You may have an import-on-demand declaration.
reply
    Bookmark Topic Watch Topic
  • New Topic