Some Misc Notes
← prev | next →     Top-level ToC     /java/apps-and-env/projects.html     (printable version)

Create and manage a small Java app (here we assume that your app depends upon an external lib you’ve got in ~/jars/some-lib.jar):

mkdir my-proj
cd my-proj
touch README.md LICENSE.txt my-proj.sh
chmod +x my-proj.sh
mkdir classes    # Your compiled .class files will end up here.
mkdir -p src/my_pkg
# Edit source files in src/my_pkg (make one of them Main.java ...
touch src/my_pkg/Main.java
# ... and have it contain the `public static void main` method).

# Work, work, work.

# Build:
javac -sourcepath src         \
      -d classes              \
      -cp ~/jars/some-lib.jar \
      src/my_pkg/Main.java

# Trial run:
java -cp classes:/home/you/jars/some-lib.jar my_pkg.Main

# Make your jar:
jar cvf my-proj.jar -C classes my_pkg

Put the following into my-proj.sh:

#!/bin/bash

java -cp /home/YOU/jars/some-lib.jar:/home/YOU/bin/my-proj.jar \
    my_pkg.Main "$@"

replacing YOU with your username, then install your app:

cp my-proj.jar ~/bin
cp my-proj.sh ~/bin