开发者

Deploying Java Files

开发者 https://www.devze.com 2023-01-08 07:37 出处:网络
What are the best practices (and enabling tools) to deploy Java standalone applications along with any required jar dependencies, config files, and launch scripts?

What are the best practices (and enabling tools) to deploy Java standalone applications along with any required jar dependencies, config files, and launch scripts?

Are there开发者_JAVA百科 any Maven plugins that easies publishing binary releases, so that users don't need to use maven for example?


Are there any Maven plugins that easies publishing binary releases, so that users don't need to use maven for example?

Use the Maven Assembly Plugin to create a binary distribution as zip/tar.gz/tar.bz2 of your project. This plugin is extremely flexible - at the price of some complexity - and you can do almost anything you want. Then deploy (in the maven sense) the produced artifact, upload it somewhere, etc.


As for dependency, I just use maven dependency copy plugin and copy all dependencies into a ./lib folder, and supply a launch script that uses the class path wildcard (that way you can change your dependencies as much as you want and don't have to change the launch script). As for configuration files, I put it in a ./config folder and again include it in my app's classpath in the launch script (The former admittedly only works for > java 1.6).

So in the end almost all my app has the following structure:

mystuff.jar launch.sh
./lib
./config

Then I'll just zip up the whole thing and give it to my users. The whole process is probably easy to automate using maven, but I confess that I do it by hand :p

If you prefer and the licenses permit, you could also just bundle all dependencies into a single jar (with expanded dependencies inside) using the assembly plugin. This tends to make the jar bulky and giving the users an updated app. more difficult. Also I had issues with it several time because of class files getting overwritten or something so I personally stick to the ./lib folder.


There's launch4j, which, if you can get it to work, will bundle up a Java app into an executable for your platform.


If your deployment target supports RPM files, I strongly suggest you investigate the rpm-maven-plugin. It allows you to easily map your project artifacts , including dependencies, to a RPM package.

I've been using it with great success to medium-scale application deployment.


You can use Oracle's ant or maven scripts:

http://docs.oracle.com/javafx/2/deployment/jfxpub-deployment.htm

The above will not only compile your code and create jar files, but it will also create binary executable (windows exe file or Mac app file). It can also create native installers. In addition it lets you include JVM with your distribution so the end use doesn't need to install Java.


Take a look at the Appassembler Maven Plugin. You may also want to combine it with the Assembly Maven Plugin.

Use the appassembler plugin to generate a set of "programs" by specifying executable names and main classes. You can also have it prepend and create an etc directory in which you can add configuration files.

If generating the directory with the start-up scripts and directory of binary files isn't enough, you can use the assembly plugin to copy over additional files (say your configuration files) into the appropriate directory and/or package your application into an archive.

0

精彩评论

暂无评论...
验证码 换一张
取 消