0

I have a project where I open some XML files to read and edit information. This works fine when running in the IDE (Netbeans) but fails when I am building the project and running the .jar file. Is there a reason why this might not work? The path of the project in Netbeans is

NetBeansProjects\project\src\data

but when I am running the jar file, this path is

NetBeansProjects\project\build\classes

However, when I create the files in this folder, they still cannot be opened.

  • 2
    The reason is probably that the code is incorrect and should be fixed. I don't have any crystal ball, so I can't find the bug in your code, unless you post it. – JB Nizet Sep 20 '15 at 17:06
  • This might help : http://stackoverflow.com/questions/4359876/how-to-load-reference-a-file-as-a-file-instance-from-the-classpath – Viktor K. Sep 20 '15 at 17:07
  • It should be a classpath issue, make sure to have all the dependencies that you need in the jar. If you are a newbie, I advise to start from [Classpath](https://en.wikipedia.org/wiki/Classpath_%28Java%29) and then googling. – vimterd Sep 20 '15 at 17:09

1 Answers1

0

The XML files need to be in the classpath when the jar file is executed.

You can give the classpath using -cp option when executing the jar file. Similar question was answered here as well - Run a JAR file from the command line and specify classpath

Community
  • 1
  • 1
Dhruv Rai Puri
  • 1,335
  • 11
  • 20