0

I am trying to build an installer for a Java application and would like to build a JAR which extracts itself. The JAR will be built using Maven assembly and will have a main class specified in the manifest. I want the main class to extract the rest of the JAR into a specified directory. The JAR will contain other JARs and some docs. I have found other questions, for example, (How to copy file inside jar to outside the jar?) but they don't address a self extracting JAR. I would like to know how to 1) obtain the location and name of the JAR from which the main is being executed, 2) copy the contents of the JAR into a specified directory.

UPDATE: I would also appreciate answers which address how to build an installer for a Maven Java application (using Eclipse) in general.

Community
  • 1
  • 1

2 Answers2

1

If you have configurations that you want the user to update then don't include them in your jar file. You have a couple of options.

One is to write out default config files if they don't already exist.

The second one is to use IzPack to provide a installer jar that will copy default configs that the user can then edit.

If you want an example of how IzPack works you can download Squirrel, which is an SQL tool, that uses IzPack to install itself.

markbernard
  • 1,412
  • 9
  • 18
0

Actually this answer works for me: How to write a Java program which can extract a JAR file and store its data in specified directory (location)? except I want to skip over copying the main class file as well as skip creating the folders on its path, so if the main class resides in a package that begins with say, "com", then just add

if(file.getName().startsWith("com"))
    continue;

below

java.io.File f = new java.io.File(destDir + java.io.File.separator + file.getName());
Community
  • 1
  • 1