openSUSE:Java jpackage-utils

Jump to: navigation, search
The project jpackage.org brings the set of the common rules, rpm macros and a scripts, which are be usefull (not only) for the package maintainers.

build-classpath

build-classpath - Small utility to build a Java CLASSPATH with the named JARs. The CLASSPATH is returned to standard output. This script should be used in a %pre, %build section of spec file, or in the pre/post un/install scriplets, or in the wrapper scripts.

The commons forms of usage are:

Setup of the CLASSPATH

$ build-classpath ant
/usr/share/java/ant.jar
$ export CLASSPATH=$(build-classpath ant servletapi5)
$ echo ${CLASSPATH}
/usr/share/java/ant.jar:/usr/share/java/servletapi5.jar

When the jar is located in a subdirectory of a %{_javadir}, you'll need to write

$ build-classpath asm/asm
/usr/share/java/asm/asm.jar

If you need all of the classes in a subdirectory, you should simply write

$ build-classpath asm/
/usr/share/java/asm/asm-1.5.3.jar:/usr/share/java/asm/asm-analysis-1.5.3.jar:
/usr/share/java/asm/asm-attrs-1.5.3.jar:/usr/share/java/asm/asm-tree-1.5.3.jar:
/usr/share/java/asm/asm-util-1.5.3.jar:/usr/share/java/asm/asm-xml-1.5.3.jar:
/usr/share/java/asm/kasm-1.5.3.jar

Note, that build-classpath will return the same output if there's some typo in the aruments, so the output of the build-classpath asm/foo will be the same as the example above!

It's also possible to use the build-classpath to create symbolic links, if the program expects the jars in some external directory.

$ ln -s $(build-classpath ant)
$ readlink ant.jar
/usr/share/java/ant.jar
$ ln -s $(build-classpath ant) libs/expected_jar_name-1.0.9.jar
$ readlink libs/expected_jar_name-1.0.9.jar
/usr/share/java/ant.jar

The combination of build-classpath and ln should produces a bad symlinks in cases, when the build-classpath returns a multiple paths.

build-classpath-directory

Small script to build a classpath from a directory. This script find all the jar files in specified directory(ies) and produce a CLASSPATH.

build-classpath-directory /usr/share/java
/usr/share/java/libgcj-4.3.jar:/usr/share/java/libgcj-tools-4.3.jar:
/usr/share/java/ecj-3.3.jar:/usr/share/java/ecj.jar:
/usr/share/java/tomcat6-servlet-2.5-api-6.0.16.jar:
/usr/share/java/tomcat6-servlet-2.5-api.jar
[snip]

build-jar-repository

Build a JAR repository in the named directory by copying files or creating symbolic links. This script is better solution how to produre a symlinks (or a copy of the jar file), than the combination of the build-classpath and a ln (or cp).

If no option is specified the default action will be to create symbolic links. In other cases, the script has a following arguments:

  • -c, --copy copy files instead linking
  • -h, --hard create hard links
  • -p, --preserve-naming preserve the names of the original JAR files
  • -s, --soft, --symbolic create symbolic links (default)

The common usage is simple

$ mkdir libs
$ build-jar-repository libs ant asm/asm

The build-jar-repository do not produce symlinks like build-classpath, but add a brackets to the name of the file.

$ ls libs
[ant].jar  [asm][asm].jar

The purpose of brackets is to identify the symlinks created by script and is possible to re-run the script on the directory and link them to the new location. This behavior should be supressed by the -p, --preserve-naming argument.

$ build-jar-repository -p libs ant asm/asm
ant.jar asm_asm.jar

In this case, the slash symbol was replaced by underscores and a default action was changed to the copy, so if you'd like to have a symlink of the jars, you've to add a -s argument.