Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a good deployment directory structure for java console apps

Tags:

java

unix

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

I plan to put my shell scripts in one folder, my application jar and dependent jars (spring, etc.) into a different folder and properties files (those that need to be maintained 'live') in a separate folder again. I would then have my shell script iterate through the files in the 'jars' and 'properties' folders, appending them to the classpath, before finally calling java ...

Is this a 'good' deployment structure? Are there any guidelines for how to arrange files to maximise maintainability and stability? Are there obvious 'wrong' ways to do this that are best avoided?

I should add that, for a previous project, I put all shell scripts (those that start java processes and those that don't) into a scripts folder, my application jar into a folder with the library jars in a library subfolder and external resources into a config subfolder. I then wrote a script that explicitly loads all the files. It was long winded to write and needs to be maintained whenever I upgrade a library jar. This time around I'd like to do it better. Also, it feels unnecessary to separate my application JAR from the libraries.

like image 754
Sarah Phillips Avatar asked Dec 03 '12 15:12

Sarah Phillips


2 Answers

For what it's worth, this 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 for building, often have a src folder for the source tree if necessary. This way you just add /class and /lib to your classpath, and that never changes.

like image 99
lynks Avatar answered Oct 11 '22 14:10

lynks


Good structure for your case is so called uberJar or oneJar, that can be made with number of utils, just google it. Also I can recommend such a nice piece of code as http://www.jdotsoft.com/JarClassLoader.php

like image 28
xeye Avatar answered Oct 11 '22 14:10

xeye