forked from fedora-java/howto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generic_java_build.txt
69 lines (57 loc) · 2.7 KB
/
generic_java_build.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
== Generic Java Builds
Handling of basic build steps in Java
* javac
* usage of build-claspath, build-jar-repository to prepare for build
* ...
=== Generating Application Shell Scripts
As mentioned in section about <<XFor_Packagers, Java packaging basics>>,
all Java applications need wrapper shell scripts to setup the environment before
running JVM and associated Java code.
The javapackages-tools package contains a convenience `%jpackage_script` macro that
can be used to create scripts that work for the majority of packages. See its
definition and documentation in `/usr/lib/rpm/macros.d/macros.jpackage`. One
thing to pay attention to is the 6th argument to it - whether to prefer a JRE
over a full SDK when looking up a JVM to invoke - most packages that don't
require the full Java SDK will want to set that to `true` to avoid unexpected
results when looking up a JVM when some of the installed JRE's don't have the
corresponding SDK (*-devel package) installed.
[source,spec]
--------
%install
...
%jpackage_script msv.textui.Driver "" "" msv-msv:msv-xsdlib:relaxngDatatype:isorelax msv true
...
--------
The previous example installs the "msv" script (5th argument) with main class
being msv.textui.Driver (1st argument). No optional flags (2nd argument) or
options (3rd argument) are used. This script will add several libraries to
classpath before executing main class (4th argument, JAR files separated with
":"). `build-classpath` is run on every part of 4th argument to create full
classpaths.
=== Replacing JARs with symlinks using xmvn-subst
Sometimes it may be needed to replace all JAR files in current directory with
symlinks to the system JARs located in `%{_javadir}`. This task can be achieved
using tool called `xmvn-subst`.
[source,shell]
--------
$ ls -l
-rw-r--r--. 1 msrb msrb 40817 Oct 22 09:16 cli.jar
-rw-r--r--. 1 msrb msrb 289983 Oct 22 09:17 junit4.jar
-rw-r--r--. 1 msrb msrb 474276 Oct 22 09:14 log4j.jar
$ xmvn-subst .
[INFO] Linked ./cli.jar to /usr/share/java/commons-cli.jar
[INFO] Linked ./log4j.jar to /usr/share/java/log4j.jar
[INFO] Linked ./junit4.jar to /usr/share/java/junit.jar
$ ls -la
lrwxrwxrwx. 1 msrb msrb 22 Oct 22 10:08 cli.jar -> /usr/share/java/commons-cli.jar
lrwxrwxrwx. 1 msrb msrb 22 Oct 22 10:08 junit4.jar -> /usr/share/java/junit.jar
lrwxrwxrwx. 1 msrb msrb 22 Oct 22 10:08 log4j.jar -> /usr/share/java/log4j.jar
--------
The example above shows how easy the symlinking can be. However, there are some
limitations. Original JAR files need to carry metadata which tell xmvn-subst
for what artifact given file should be substituted. Otherwise `xmvn-subst` won't
be able to identify the Maven artifact from JAR file.
[TIP]
======
See `xmvn-subst -h` for all available options.
======