| 1 | <?xml version="1.0" encoding="UTF-8"?> |
1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | <!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/java.xml,v 1.27 2006/07/25 08:13:47 rane Exp $ --> |
2 | <!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/java.xml,v 1.28 2006/08/08 09:51:12 rane Exp $ --> |
| 3 | <!DOCTYPE guide SYSTEM "/dtd/guide.dtd"> |
3 | <!DOCTYPE guide SYSTEM "/dtd/guide.dtd"> |
| 4 | |
4 | |
| 5 | <guide link="/doc/en/java.xml"> |
5 | <guide link="/doc/en/java.xml"> |
| 6 | <title>Gentoo Java Guide</title> |
6 | <title>Gentoo Java Guide</title> |
| 7 | |
7 | |
| 8 | <author title="Author"> |
8 | <author title="Author"> |
| 9 | <mail link="karltk@gentoo.org">Karl Trygve Kalleberg</mail> |
9 | <mail link="nichoj@gentoo.org">Joshua Nichols</mail> |
| 10 | </author> |
10 | </author> |
| 11 | <author title="Author"> |
11 | <author title="Author"> |
| 12 | <mail link="nichoj@gentoo.org">Joshua Nichols</mail> |
12 | <mail link="karltk@gentoo.org">Karl Trygve Kalleberg</mail> |
| 13 | </author> |
13 | </author> |
| 14 | <author title="Editor"> |
14 | <author title="Editor"> |
| 15 | <mail link="nightmorph@gentoo.org">Joshua Saddler</mail> |
15 | <mail link="nightmorph@gentoo.org">Joshua Saddler</mail> |
| 16 | </author> |
16 | </author> |
| 17 | |
17 | |
| 18 | <abstract> |
18 | <abstract> |
| 19 | This guide will introduce you to Java and explain how to use Java with Gentoo |
19 | This guide will introduce you to Java and explain how to use Java with Gentoo |
| 20 | Linux. |
20 | Linux. |
| 21 | </abstract> |
21 | </abstract> |
| 22 | |
22 | |
| 23 | <!-- The content of this document is licensed under the CC-BY-SA license --> |
23 | <!-- The content of this document is licensed under the CC-BY-SA license --> |
| 24 | <!-- See http://creativecommons.org/licenses/by-sa/2.5 --> |
24 | <!-- See http://creativecommons.org/licenses/by-sa/2.5 --> |
| 25 | <license/> |
25 | <license/> |
| 26 | |
26 | |
| 27 | <version>0.5</version> |
27 | <version>0.6</version> |
| 28 | <date>2006-07-24</date> |
28 | <date>2006-08-07</date> |
| 29 | |
29 | |
| 30 | <chapter> |
30 | <chapter> |
| 31 | <title>What is Java?</title> |
31 | <title>What is Java?</title> |
| 32 | <section> |
32 | <section> |
| 33 | <title>Overview</title> |
33 | <title>Overview</title> |
| 34 | <body> |
34 | <body> |
| 35 | |
35 | |
| 36 | <p> |
36 | <p> |
| 37 | Java is a programming language developed by engineers of Sun Microsystems. The |
37 | Java is a programming language developed by engineers of Sun Microsystems. The |
| 38 | language is object-oriented and designed to run on multiple platforms without |
38 | language is object-oriented and designed to run on multiple platforms without |
| 39 | the need of recompiling code for each platform. Although Java can be compiled |
39 | the need of recompiling code for each platform. Although Java can be compiled |
| 40 | as a native program, much of Java's popularity can be attributed to its |
40 | as a native program, much of Java's popularity can be attributed to its |
| 41 | portability, along with other features such as garbage collection. To make |
41 | portability, along with other features such as garbage collection. To make |
| 42 | platform independence possible the Java compiler compiles the Java code to an |
42 | platform independence possible the Java compiler compiles the Java code to an |
| 43 | intermediate representation called "Java bytecode" that runs on a JRE (Java |
43 | intermediate representation called "Java bytecode" that runs on a JRE (Java |
| … | |
… | |
| 45 | </p> |
45 | </p> |
| 46 | |
46 | |
| 47 | <p> |
47 | <p> |
| 48 | In order to run Java bytecode, one needs to have a JRE (Java Runtime |
48 | In order to run Java bytecode, one needs to have a JRE (Java Runtime |
| 49 | Environment) installed. A JRE provides core libraries, a platform dependent |
49 | Environment) installed. A JRE provides core libraries, a platform dependent |
| 50 | Java Virtual Machine, plug-ins for browsers, among other things. A JDK (Java |
50 | Java Virtual Machine, plug-ins for browsers, among other things. A JDK (Java |
| 51 | Development Kit) adds programming tools, such as a bytecode compiler and a |
51 | Development Kit) adds programming tools, such as a bytecode compiler and a |
| 52 | debugger. |
52 | debugger. |
| 53 | </p> |
53 | </p> |
| 54 | |
54 | |
| 55 | </body> |
55 | </body> |
| 56 | </section> |
56 | </section> |
| 57 | </chapter> |
57 | </chapter> |
| 58 | |
58 | |
| 59 | <chapter> |
59 | <chapter> |
| 60 | <title>Installing a JRE/JDK</title> |
60 | <title>New Java System</title> |
|
|
61 | <section> |
|
|
62 | <body> |
|
|
63 | |
|
|
64 | <p> |
|
|
65 | The way Java is handled on Gentoo has recently seen many changes and |
|
|
66 | improvements. This has only happened very recently, and as a result, all the |
|
|
67 | packages related to it are marked with testing keywords, ie ~x86. This |
|
|
68 | document assumes you are using the new system. |
|
|
69 | </p> |
|
|
70 | |
|
|
71 | </body> |
|
|
72 | </section> |
|
|
73 | <section> |
|
|
74 | <title>Keywords</title> |
|
|
75 | <body> |
|
|
76 | |
|
|
77 | <p> |
|
|
78 | If you are using the stable tree, i.e. x86, ppc, or amd64 as opposed to ~x86, |
|
|
79 | ~ppc, or ~amd64, you will need to add some entries to your |
|
|
80 | <path>/etc/portage/package.keywords</path>: |
|
|
81 | </p> |
|
|
82 | |
|
|
83 | <pre caption="package.keywords"> |
|
|
84 | # Core Gentoo/Java Packages |
|
|
85 | dev-java/ant-core |
|
|
86 | dev-java/ant-tasks |
|
|
87 | dev-java/ant |
|
|
88 | dev-java/java-config |
|
|
89 | dev-java/java-config-wrapper |
|
|
90 | dev-java/javatoolkit |
|
|
91 | # JDKs |
|
|
92 | =dev-java/sun-jdk-1.4* |
|
|
93 | =dev-java/sun-jdk-1.5* |
|
|
94 | =dev-java/ibm-jdk-bin-1.4* |
|
|
95 | =dev-java/ibm-jdk-bin-1.5* |
|
|
96 | =dev-java/jrockit-jdk-bin-1.4* |
|
|
97 | =dev-java/jrockit-jdk-bin-1.5* |
|
|
98 | =dev-java/blackdown-jdk-1.4* |
|
|
99 | dev-java/kaffe |
|
|
100 | # JREs |
|
|
101 | =dev-java/sun-jre-bin-1.4* |
|
|
102 | =dev-java/sun-jre-bin-1.5* |
|
|
103 | =dev-java/ibm-jre-bin-1.4* |
|
|
104 | =dev-java/blackdown-jre-1.4* |
|
|
105 | # Virtuals |
|
|
106 | virtual/jdk |
|
|
107 | virtual/jre |
|
|
108 | # Compilers |
|
|
109 | dev-java/eclipse-ecj |
|
|
110 | dev-java/jikes |
|
|
111 | # Documentation |
|
|
112 | dev-java/java-sdk-docs |
|
|
113 | # Misc packages that have been updated to generation-2, |
|
|
114 | # where the generation-1 won't build and/or run properly |
|
|
115 | dev-java/lucene |
|
|
116 | # These have optional Java support, but need ~arch to function properly |
|
|
117 | # with generation-2 |
|
|
118 | dev-util/subversion |
|
|
119 | sys-libs/db |
|
|
120 | </pre> |
|
|
121 | |
|
|
122 | <impo> |
|
|
123 | It is crucial that you keyword ALL packages related to the new Java system, |
|
|
124 | otherwise you will have problems in the later steps of this guide. |
|
|
125 | </impo> |
|
|
126 | |
|
|
127 | <impo> |
|
|
128 | It can't be emphasized enough that you have to have ALL the packages related |
|
|
129 | to the new Java system keyworded for it to function properly. |
|
|
130 | </impo> |
|
|
131 | |
|
|
132 | </body> |
|
|
133 | </section> |
|
|
134 | <section> |
|
|
135 | <title>Existing installs</title> |
|
|
136 | <body> |
|
|
137 | |
|
|
138 | <p> |
|
|
139 | For existing installs, regardless of if you have installed anything Java |
|
|
140 | before, make sure you have followed the <uri |
|
|
141 | link="/proj/en/java/java-upgrade.xml">Java Upgrade Guide</uri>. |
|
|
142 | </p> |
|
|
143 | |
|
|
144 | </body> |
|
|
145 | </section> |
|
|
146 | <section> |
|
|
147 | <title>New installs</title> |
|
|
148 | <body> |
|
|
149 | |
|
|
150 | <p> |
|
|
151 | New installs should require no further preparation. |
|
|
152 | </p> |
|
|
153 | |
|
|
154 | </body> |
|
|
155 | </section> |
|
|
156 | </chapter> |
|
|
157 | |
|
|
158 | <chapter> |
|
|
159 | <title>Installing a Virtual Machine</title> |
| 61 | <section> |
160 | <section> |
| 62 | <title>The choices</title> |
161 | <title>The choices</title> |
| 63 | <body> |
162 | <body> |
| 64 | |
163 | |
| 65 | <p> |
164 | <p> |
| 66 | Gentoo provides numerous JREs and JDKs. Among the current alternatives, we |
165 | Gentoo provides numerous Runtime Environments (JREs) and Development Kits |
| 67 | have: |
166 | (JDKs). Among the current choices, we have: |
| 68 | </p> |
167 | </p> |
| 69 | |
168 | |
| 70 | <table> |
169 | <table> |
| 71 | <tr> |
170 | <tr> |
| 72 | <th>Vendor</th> |
171 | <th>Vendor</th> |
| 73 | <th>JDK</th> |
172 | <th>JDK</th> |
| 74 | <th>JRE</th> |
173 | <th>JRE</th> |
| 75 | </tr> |
174 | </tr> |
| 76 | <tr> |
175 | <tr> |
| 77 | <ti>The Blackdown Java Kit</ti> |
176 | <ti>The Blackdown Java Kit</ti> |
| 78 | <ti>dev-java/blackdown-jdk</ti> |
177 | <ti>dev-java/blackdown-jdk</ti> |
| 79 | <ti>dev-java/blackdown-jre</ti> |
178 | <ti>dev-java/blackdown-jre</ti> |
| 80 | </tr> |
179 | </tr> |
| 81 | <tr> |
180 | <tr> |
| 82 | <ti>Sun's Java Kit</ti> |
181 | <ti>Sun's Java Kit</ti> |
| … | |
… | |
| 99 | </tr> |
198 | </tr> |
| 100 | </table> |
199 | </table> |
| 101 | |
200 | |
| 102 | <!-- |
201 | <!-- |
| 103 | TODO: list free implementations? |
202 | TODO: list free implementations? |
| 104 | note about not drop-in replacements |
203 | note about not drop-in replacements |
| 105 | kaffe/sablevm/gcj/jamvm |
204 | kaffe/sablevm/gcj/jamvm |
| 106 | --> |
205 | --> |
| 107 | |
206 | |
| 108 | <p> |
207 | <p> |
| 109 | The default is Blackdown for both the JRE and the JDK, as it is freely ("free |
208 | The default is Blackdown for both the JRE and the JDK, as it is freely ("free |
| 110 | as in beer") available without any registration fuss. |
209 | as in beer") available without any registration fuss. |
| 111 | </p> |
210 | </p> |
| 112 | |
211 | |
| 113 | <p> |
212 | <p> |
| 114 | Both the Sun and the IBM are generally faster, but getting them is a bit more |
213 | The default for Java 1.4 is the Blackdown JRE/JDK pair, as it is freely |
| 115 | hassle, as you are required to read and accept their license before downloading |
214 | ("free as in beer") available without any registration fuss. |
|
|
215 | </p> |
|
|
216 | |
|
|
217 | <p> |
|
|
218 | JREs and JDKs from Sun, IBM, and BEA are generally faster, but getting them |
|
|
219 | is a bit more work, as you are required to read and accept their license before |
| 116 | (IBM additionally requires you to register). |
220 | downloading (IBM additionally requires you to register). |
| 117 | </p> |
|
|
| 118 | |
|
|
| 119 | <p> |
|
|
| 120 | Our ebuilds for the Sun and IBM JRE/JDKs will inform you how to download the |
|
|
| 121 | appropriate files. |
|
|
| 122 | </p> |
221 | </p> |
| 123 | |
222 | |
| 124 | </body> |
223 | </body> |
| 125 | </section> |
224 | </section> |
| 126 | <section> |
225 | <section> |
| 127 | <title>Installing a JRE/JDKs</title> |
226 | <title>Installing a JRE/JDKs</title> |
| 128 | <body> |
227 | <body> |
| 129 | |
228 | |
| 130 | <p> |
229 | <p> |
| 131 | To install your profile's default JDK, you can run <c>emerge virtual/jdk</c>. |
230 | To install your profile's default JDK, you can run <c>emerge virtual/jdk</c>. |
| 132 | Or to install your profile's default JRE, you can <c>emerge virtual/jre</c>. |
231 | Or to install your profile's default JRE, you can <c>emerge virtual/jre</c>. |
|
|
232 | </p> |
|
|
233 | |
|
|
234 | <p> |
|
|
235 | In recent events, Sun has relicensed their JDK and JRE under a more Linux |
|
|
236 | distro friendly license. As a result, Sun releases Java 1.5 and onwards are |
|
|
237 | freely downloadable, without any further hassle. |
| 133 | </p> |
238 | </p> |
| 134 | |
239 | |
| 135 | <note> |
240 | <note> |
| 136 | A JDK also includes a JRE, so if you install a JDK you shouldn't have to also |
241 | A JDK also includes a JRE, so if you install a JDK you shouldn't have to also |
| 137 | have to install a JRE. |
242 | have to install a JRE. |
| 138 | </note> |
243 | </note> |
| 139 | |
244 | |
| 140 | </body> |
245 | </body> |
| 141 | </section> |
246 | </section> |
| 142 | <section> |
247 | <section> |
| 143 | <title>Installing the Sun/IBM JRE/JDKs</title> |
248 | <title>Installing fetch-restricted virtual machines</title> |
| 144 | <body> |
249 | <body> |
| 145 | |
250 | |
| 146 | <p> |
251 | <p> |
| 147 | If you run <c>emerge dev-java/sun-jdk</c> or <c>emerge |
252 | As already mentioned, some of the JDKs and JREs require you to jump through a |
| 148 | dev-java/ibm-jdk-bin</c>, you will be notified that you are required to |
253 | few hoops before installing. Simply emerge the packages as you normally would. |
| 149 | download the actual files yourself. This has to do with license restrictions |
254 | The ebuilds will then instruct you where to go and what to download. |
| 150 | for the Sun JRE/JDK (online click-wrap license) and registration issues with |
|
|
| 151 | the IBM JRE/JDK. |
|
|
| 152 | </p> |
255 | </p> |
| 153 | |
256 | |
| 154 | <p> |
257 | <p> |
| 155 | You should download the indicated file(s) into |
258 | You should download the indicated file(s) into |
| 156 | <path>/usr/portage/distfiles</path>. Once there, you can rerun the emerge |
259 | <path>/usr/portage/distfiles</path>. Once there, you can rerun the emerge |
| 157 | command, at which point the JRE/JDK will be begin to install. |
260 | command, at which point the JRE/JDK will be begin to install. |
| 158 | </p> |
261 | </p> |
| 159 | |
262 | |
| 160 | </body> |
263 | </body> |
| 161 | </section> |
264 | </section> |
| 162 | </chapter> |
265 | </chapter> |
| 163 | |
266 | |
| 164 | <chapter> |
267 | <chapter> |
| 165 | <title>Configuring your JRE/JDK</title> |
268 | <title>Configuring your virtual machine</title> |
| 166 | <section> |
269 | <section> |
| 167 | <title>Overview</title> |
270 | <title>Overview</title> |
| 168 | <body> |
271 | <body> |
| 169 | |
272 | |
| 170 | <p> |
273 | <p> |
| 171 | Gentoo has the ability to have multiple JDKs and JREs installed without causing |
274 | Gentoo has the ability to have multiple JDKs and JREs installed without causing |
| 172 | conflicts. |
275 | conflicts. |
| 173 | </p> |
276 | </p> |
| 174 | |
277 | |
| 175 | <p> |
278 | <p> |
| 176 | Using the <c>java-config</c> tool, you can set the system-wide default |
279 | Using the <c>java-config</c> tool, you can set the system-wide default |
| 177 | (provided you have root access). Users can also use <c>java-config</c> to set |
280 | (provided you have root access). Users can also use <c>java-config</c> to set |
| 178 | up their own personal default. |
281 | up their own personal default. |
| 179 | </p> |
282 | </p> |
| 180 | |
283 | |
| 181 | <note> |
284 | <note> |
| 182 | You can also use <e>eselect</e> to change the system and user vm. See |
285 | You can also use <e>eselect</e> to change the system and user vm. See |
| 183 | <c>eselect java-vm help</c>. |
286 | <c>eselect java-vm help</c>. |
| 184 | </note> |
287 | </note> |
| 185 | |
288 | |
| 186 | </body> |
289 | </body> |
| 187 | </section> |
290 | </section> |
| 188 | <section> |
291 | <section> |
| 189 | <title>Setting a default JRE/JDK</title> |
292 | <title>Setting a default virtual machine</title> |
| 190 | <body> |
293 | <body> |
| 191 | |
294 | |
| 192 | <p> |
295 | <p> |
| 193 | Running the command <c>java-config --list-available-vms</c> will give you a |
296 | Running the command <c>java-config --list-available-vms</c> will give you a |
| 194 | list of all JREs and JDKs installed on your system. Here is an example of |
297 | list of all JREs and JDKs installed on your system. Here is an example of |
| 195 | output: |
298 | output: |
| 196 | </p> |
299 | </p> |
| 197 | |
300 | |
| 198 | <pre caption="Listing available VMs"> |
301 | <pre caption="Listing available VMs"> |
| 199 | # <i>java-config --list-available-vms</i> |
302 | # <i>java-config --list-available-vms</i> |
| 200 | 1) Blackdown JDK 1.3.1 [blackdown-jdk-1.3] (/etc/env.d/java/20blackdown-jdk-1.3) |
303 | 1) Blackdown JDK 1.3.1 [blackdown-jdk-1.3] (/etc/env.d/java/20blackdown-jdk-1.3) |
| 201 | 2) Blackdown JDK 1.4.2.02 [blackdown-jdk-1.4] (/etc/env.d/java/20blackdown-jdk-1.4) |
304 | 2) Blackdown JDK 1.4.2.02 [blackdown-jdk-1.4] (/etc/env.d/java/20blackdown-jdk-1.4) |
| 202 | 3) Blackdown JRE 1.4.2.02 [blackdown-jre-1.4] (/etc/env.d/java/20blackdown-jre-1.4) |
305 | 3) Blackdown JRE 1.4.2.02 [blackdown-jre-1.4] (/etc/env.d/java/20blackdown-jre-1.4) |
| 203 | 4) IBM JDK 1.4.2 [ibm-jdk-bin-1.4] (/etc/env.d/java/20ibm-jdk-bin-1.4) |
306 | 4) IBM JDK 1.4.2 [ibm-jdk-bin-1.4] (/etc/env.d/java/20ibm-jdk-bin-1.4) |
| 204 | 5) IBM JRE 1.4.2 [ibm-jre-bin-1.4] (/etc/env.d/java/20ibm-jre-bin-1.4) |
307 | 5) IBM JRE 1.4.2 [ibm-jre-bin-1.4] (/etc/env.d/java/20ibm-jre-bin-1.4) |
| … | |
… | |
| 468 | <li>The <b>java</b> flag adds support for Java in a variety of programs</li> |
571 | <li>The <b>java</b> flag adds support for Java in a variety of programs</li> |
| 469 | <li> |
572 | <li> |
| 470 | The <b>nsplugin</b> flag adds support for Mozilla-like browsers (including |
573 | The <b>nsplugin</b> flag adds support for Mozilla-like browsers (including |
| 471 | Firefox).You will need this for viewing Java applets in your Mozilla-like |
574 | Firefox).You will need this for viewing Java applets in your Mozilla-like |
| 472 | browser. |
575 | browser. |
| 473 | </li> |
576 | </li> |
| 474 | <li> |
577 | <li> |
| 475 | The <b>doc</b> flag will typically install API documentation, as generated |
578 | The <b>doc</b> flag will typically install API documentation, as generated |
| 476 | by javadoc. |
579 | by javadoc. |
| 477 | </li> |
580 | </li> |
| 478 | <li> |
581 | <li> |
| 479 | The <b>source</b> flag will install a zip of the package's source code. |
582 | The <b>source</b> flag will install a zip of the package's source code. |
| 480 | This is typically used to provide your IDE with the source code for the |
583 | This is typically used to provide your IDE with the source code for the |
| 481 | package. |
584 | package. |
| 482 | </li> |
585 | </li> |
|
|
586 | <li> |
|
|
587 | The <b>source</b> flag installs a zip of the source code of a package. |
|
|
588 | This is traditionally used for for IDEs to 'attach' source to the libraries |
|
|
589 | you are using. |
|
|
590 | </li> |
|
|
591 | <li> |
|
|
592 | For Java packages, the <b>doc</b> flag will build API documentation using |
|
|
593 | javadoc. |
|
|
594 | </li> |
| 483 | </ul> |
595 | </ul> |
| 484 | |
596 | |
| 485 | </body> |
597 | </body> |
| 486 | </section> |
598 | </section> |
| 487 | </chapter> |
599 | </chapter> |
| 488 | |
600 | |
| 489 | <chapter> |
601 | <chapter> |
| 490 | <title>Additional resources</title> |
602 | <title>Additional resources</title> |
| 491 | <section> |
603 | <section> |
| 492 | <title>Off-line resources</title> |
604 | <title>Off-line resources</title> |
| 493 | <body> |
605 | <body> |
| 494 | |
606 | |
| 495 | <ul> |
607 | <ul> |
| 496 | <li>java-config man page</li> |
608 | <li>java-config man page</li> |
| 497 | <li><c>java-config --help</c></li> |
609 | <li><c>java-config --help</c></li> |