Mark Watson’s Artificial Intelligence Books and Blog

Share this post

One of my favorite things about Java: packaging both code and data in JAR files

markwatson.com

One of my favorite things about Java: packaging both code and data in JAR files

Mark Watson
Sep 22, 2004
Share
Share this post

One of my favorite things about Java: packaging both code and data in JAR files

markwatson.com

Sure, other programming languages like Python, Lisp, and Smalltalk as faster to develop in (for the usual reasons: late binding, more interactive development, etc.). However, one feature of the Java platform that I really like is being able to easily package both compiled code and required data in a JAR file.

Typically, I serialize required runtime data to a binary file and when I create a JAR file I add the binary serialized data file as a top level entry. To read the data into memory, I use something like this:


InputStream ins =

  this.getClass().getClassLoader().getResourceAsStream("my_data.ser");

ObjectInputStream p = new ObjectInputStream(ins);

Vector my_vector = (Vector) p.readObject();

// etc.


Then, I can just use the JAR file in other applications and I have both code and required data.

Share
Share this post

One of my favorite things about Java: packaging both code and data in JAR files

markwatson.com
Comments
Top
New

No posts

Ready for more?

© 2023 Mark Watson
Privacy ∙ Terms ∙ Collection notice
Start WritingGet the app
Substack is the home for great writing