简体   繁体   中英

How to open a file from jar?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM