Using resource files in Java

☆樱花仙子☆ 提交于 2019-12-02 03:58:24
MadProgrammer

"Converting to EXE" is just a fancy way of saying "wrapping the Jar files into an executable container"

"I'm assuming JAR file isn't the best way" not really. It's nice to provide a OS specific means for launching the program at times, but it's not always the best solution.

"what are the limitations?". Well, to start with, you're limiting your self to a single platform. For Mac's you need to bundle the application into a "app" bundle. For linux, I think most people provide scripts to launch their code.

You could also be limiting your self to particular bit depth. If all you supply is a x32 bit executable, then you'll only ever run within a x32 bit environment. This may not be an issue, but you're limiting the available memory to start with...

So yes, generally, your resource files will be safe.

A resource file is generally embedded. What you're describing in part 3 is more akin to a configuration file. This file needs to be stored on the file system (out side of your exe/jar) so it can easily be updated.

"how do you reference the resource file in the code itself?"

For embedded resources you will need to start by using getClass().getResource(...). For you configuration file, I'd say just like any other file...

I would also have a look at Deployment some ideas on the suggest mechanisms for deploying Java programs,

Jar is a perfect format for distribution. You can convert to exe , but the user will still need the JVM installed to run it. Jars are executed with a doubleclick if the JVM is installed AND the jar has a properly formed manifest file.

You can open any file from the JVM, text, binary, XML, property file etc.

To save user settings a good choice is a property file - see http://www.mkyong.com/java/java-properties-file-examples/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!