forked from fedora-java/howto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfedora_java_specifics.txt
127 lines (95 loc) · 4.5 KB
/
fedora_java_specifics.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
== Java Specifics in Fedora for Users and Developers
This section contains information about default Java implementation in
Fedora, switching between different Java runtime environments and about
few useful tools which can be used during packaging/development.
[[openjdk]]
=== Java implementation in Fedora
Fedora ships with an open-source reference implementation of Java
Standard Edition called http://openjdk.java.net/[OpenJDK]. OpenJDK
provides Java Runtime Environment for Java applications and set of
development tools for Java developers.
From users point of view, `java` command is probably most interesting.
It's a Java application launcher which spawns Java Virtual Machine
(JVM), loads specified `.class` file and executes its main method.
Here is an example how to run sample Java project from section 1.1.1:
[source,shell]
--------
$ java org/fedoraproject/helloworld/HelloWorld.class
--------
OpenJDK provides a lot of interesting tools for Java developers:
- `javac` is a Java compiler which translates source files
to Java bytecode, which can be later interpreted by JVM.
- `jdb` is a simple command-line debugger for Java applications.
- `javadoc` is a tool for generating Javadoc documentation.
- `javap` can be used for disassembling Java class files.
==== Switching between different Java implementations
Users and developers may want to have multiple Java environments
installed at the same time. It is possible in Fedora, but only one of
them can be default Java environment in system. Fedora uses
`alternatives` for switching between different installed JREs/JDKs.
--------
# alternatives --config java
There are 3 programs which provide 'java'.
Selection Command
-----------------------------------------------
1 java-17-openjdk.x86_64 (/usr/lib/jvm/java-17-openjdk-17.0.2.0.8-1.fc35.x86_64/bin/java)
*+ 2 java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.14.1.1-5.fc35.x86_64/bin/java)
3 java-latest-openjdk.x86_64 (/usr/lib/jvm/java-18-openjdk-18.0.1.0.10-1.rolling.fc35.x86_64/bin/java)
Enter to keep the current selection[+], or type selection number:
--------
Example above shows how to chose default Java environment. `java`
command will then point to the Java implementation provided by given
JRE.
[TIP]
========
See `man alternatives` for more information on how to use
`alternatives`.
========
Developers may want to use Java compiler from different JDK. This can be
achieved with `alternatives --config javac`.
=== Building classpath with `build-classpath`
Most of the Java application needs to specify classpath in order to work
correctly. Fedora contains several tools which make working with
classpaths easier.
`build-classpath` - this tool takes JAR filenames or artifact
coordinates as arguments and translates them to classpath-like string.
See following example:
[source,shell]
--------
$ build-classpath log4j junit org.ow2.asm:asm
/usr/share/java/log4j.jar:/usr/share/java/junit.jar:/usr/share/java/objectweb-asm4/asm.jar
--------
`log4j` corresponds to `log4j.jar` stored in `%{_javadir}`. If the JAR
file is stored in subdirectory under `%{_javadir}`, it's neccessary to
pass `subdirectory/jarname` as an argument to `build-classpath`.
Example:
[source,shell]
--------
$ build-classpath httpcomponents/httpclient.jar
/usr/share/java/httpcomponents/httpclient.jar
--------
=== Building JAR repository with `build-jar-repository`
Another tool is `build-jar-repository`. It can fill specified directory
with symbolic/hard links to specified JAR files.Similarly to
`build-classpath`, JARs can be identified by their names or artifact
coordintes.
[source,shell]
--------
$ build-jar-repository my-repo log4j httpcomponents/httpclient junit:junit
$ ls -l my-repo/
total 0
lrwxrwxrwx. 1 msrb msrb 45 Oct 29 10:39 [httpcomponents][httpclient].jar -> /usr/share/java/httpcomponents/httpclient.jar
lrwxrwxrwx. 1 msrb msrb 25 Oct 29 10:39 [junit:junit].jar -> /usr/share/java/junit.jar
lrwxrwxrwx. 1 msrb msrb 25 Oct 29 10:39 [log4j].jar -> /usr/share/java/log4j.jar
--------
Similar command `rebuild-jar-repository` can be used to rebuild JAR
repository previously built by `build-jar-repository`. See `man
rebuild-jar-repository` for more information.
`build-classpath-directory` is a small tool which can be used to build
classpath string from specified directory.
[source,shell]
--------
$ build-classpath-directory /usr/share/java/xstream
/usr/share/java/xstream/xstream-benchmark.jar:/usr/share/java/xstream/xstream.jar
:/usr/share/java/xstream/xstream-hibernate.jar
--------