What is a good deployment directory structure for Java console applications

I have a Java console application that I am ready to deploy to a Unix server. I am writing a shell script to run an application.

I plan to put my shell scripts in one folder, my application jar and dependent banks (spring, etc.) in another folder and properties files (those that should be supported live) in a separate folder again. Then I would execute my shell script iterate through the files in the banks and properties folders, adding them to the classpath before finally calling java ...

Is this a β€œgood” deployment structure? Are there any recommendations for organizing files for maximum support and stability? Are there obvious β€œwrong” ways to do this that are best avoided?

I must add that for the previous project I put all shell scripts (those that run Java processes, and those that do not have them) in the scripts folder - the jar application in the library banks folder in the library subfolder and external resources in the config subfolder . Then I wrote a script that explicitly downloads all the files. It has been written for a long time and needs to be supported when I update the library jar. This time I would like to do it better. In addition, there is no need to separate JAR applications from libraries.

+6
source share
4 answers

What it is worth is what we use;

/ /class //package hierarchy here, raw .class files /lib //library jars here, apache commons, gson etc, all .jars /conf //.properties files go here, including ones for libraries /doc //program documentation files, typically .txt /javadocs //java doc html root /sh //shell scripts including execute.sh and compile.sh 

We use ant to build, often if necessary, use the src folder for the source tree. This way you simply add /class and /lib to your classpath, and that never changes.

+2
source

A good structure for your business is called the so-called uberJar or oneJar, which can be done with a number of utils, just Google. I can also recommend such a good piece of code as http://www.jdotsoft.com/JarClassLoader.php

+1
source

Honestly, if this is just a small application, I would put it under /opt/<my_java_app> and have a directory substructure, as in dev.

If you want to be more compatible with your recommended UNIX standards, put your executable file (including your jar ) in /usr/local/bin/<my_java_app> , configuration files in /etc/<my_java_app> , log files and other data files in /var/<my_java_app> .

You can also refer to this document .

+1
source

Create a system package and use the system defaults. If you are using Debian, create .deb directly from your build system (for example, using ant deb task ). If you use rpms, use rpm task . In this way, you can easily deploy, deploy, and update the application just like any other.

The system package must separate the libraries (I use /usr/share/java/AppName for my jars) and the configuration (before /etc/AppName or /home/UserName/.AppName ); startup scripts i are symbolically associated with /usr/bin . Other than this, there is not much complication to make it work. I recommend finding famous Java packages in your distribution kit and copying their startup scripts (in particular, their VM discovery magic).

0
source

All Articles