• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is there a best practice for packaging external text files with a Java app?  RSS feed

 
Jon Swanson
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have my project setup with the following directories



The .class files obviously go in the jar file. The images directory contains images used by the GUI, again, into the jar file. The data directory contains information used by the methods in the java app, again into the jar file. The scripts directory contains files not used by the Java app directly. I start another program and then pass a command to that program ('source scripts/myscript') which defines a function in that program, I can then send commands to run the function I created.

I originally was not using a jar file, so I could just source the scripts files. It seems I have two options when using a jar file:

1. Put all the files in the jar file, then when I run, copy out the scripts files to a tmp directory and source them from there

2. Leave the scripts directory out of the jar file and define an environment variable so that I can find them.

I'm leaning toward (1), the scripts files only total about 40K.

Would anyone have comments about the advantages and disadvantages of one method over the other? Or a better approach in general?

Thanks.
 
Junilu Lacar
Sheriff
Posts: 11476
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My approach is to have everything that goes together stay together. If the scripts don't get used directly by anything in the jar file, they don't go together. For easier distribution, I would put everything in a zip or tar.gz file, with the contents structured so that when everything is extracted, they go in the right place and the end user would simply need to read the included README file and/or run a setup script or something like that to get going.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!