Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Package and run a Java application with spring dependencies

I built a stand-alone Java application that has a bunch of dependencies (Apache Commons libs, etc) as well as a dependency on the Spring framework, which in turn has a bunch of dependencies.

I built this in Eclipse, where it runs fine. Now I need to deploy it to production and so I'm trying to figure out the best way to package it with all dependencies and also how to even invoke the thing (it will be invoked from the command line).

The brute-force way would be to export my project as a jar, find all the dependent jars (and their dependencies!), copy them to a common directory, write a shell script that includes every one on the classpath and run it. Obviously that seems stupid and tedious.

Should I use Ant, Maven? Should I package all of the dependent Spring jars into one big file? Any tips on dealing with this would be helpful.

like image 521
Ish Avatar asked Feb 19 '09 09:02

Ish


1 Answers

Java deployment is still stupid and tedious in 2009. So the usual option is to write this small script. If you put all your JARs into one directory (say, lib\), you can use a common script which builds the classpath automatically (see this blog entry). I suggest to add a cd /d %~dp0 at the beginning to cd into the script's directory.

Maven 2 has a plugin which can assemble your application in one "super JAR" (mvn assembly:assembly). This works unless you use the DB2 JCC driver (which contains "COM.ibm." packages which get converted to com.ibm. -> ClassNotFoundException).

The last solution, if you have already an ANT build.xml which works, is to unpack all the dependent JARs and create a "super JAR" yourself.

like image 170
Aaron Digulla Avatar answered Nov 14 '22 23:11

Aaron Digulla