简体   繁体   中英

custom file types in jar

I am developing a Java project in Netbeans which contains multiple files with custom types (like .rml .mod and ...)

The netbeans does not show these files in project, and when I build the project I need to copy them manually so the project can load them.

Is it possible to automatically include these files into output Jar file in build time?

If yes, then how and how can I access them in code?
If no, then how can I manage these files (automatically copy them to desired place and etc.)?

create a package inside java application and add files to this package.

for access to this files use of following code:

getClass().getResource("/Images/imgedit.png")

Package name instead of "Images" and file name instead of "imgeit.png".

You can use Ant for building the project

You can take basic reference from here and here .

If your data files are in the source folder they should be copied automatically to the bin folder along with the generated class files. To read a data file from within a jar you could use getResourceAsStream(String) available in Class class.

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