You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

link.html 18 KiB

6 years ago
6 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. <!DOCTYPE html>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. https://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <html lang="en">
  17. <head>
  18. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  19. <title>Link Task</title>
  20. </head>
  21. <body>
  22. <h2 id="link">Link</h2>
  23. <p><em>Since Apache Ant 1.10.6</em></p>
  24. <h3>Description</h3>
  25. <p>Assembles jmod files into an executable image. Equivalent to the JDK's
  26. <a href="https://docs.oracle.com/en/java/javase/11/tools/jlink.html">jlink</a>
  27. tool.
  28. </p>
  29. <p>Requires Java 9 or later.</p>
  30. <h3>Parameters</h3>
  31. <table class="attr">
  32. <tr>
  33. <th scope="col">Attribute</th>
  34. <th scope="col">Description</th>
  35. <th scope="col">Required</th>
  36. </tr>
  37. <tr>
  38. <td>destDir</td>
  39. <td>Root directory of created image.</td>
  40. <td>Yes</td>
  41. </tr>
  42. <tr>
  43. <td>modulepath</td>
  44. <td>Path-like sequence of jmod files to link in order to create image.</td>
  45. <td rowspan="2">One of these is required, unless a nested
  46. <code>&lt;modulepath&gt;</code> is present.</td>
  47. </tr>
  48. <tr>
  49. <td>modulepathref</td>
  50. <td class="left">Path-like sequence of jmod files to link in order to
  51. create image, given as a <a href="../using.html#references">reference</a>
  52. to a path defined elsewhere.</td>
  53. </tr>
  54. <tr>
  55. <td>modules</td>
  56. <td>Comma-separated list of modules to place in the linked image.</td>
  57. <td>Yes, unless one or more nested <code>&lt;module&gt;</code> elements
  58. are present.</td>
  59. </tr>
  60. <tr>
  61. <td>observableModules</td>
  62. <td>Comma-separated list of explicit modules that comprise
  63. "universe" visible to link tool while linking.</td>
  64. <td>No</td>
  65. </tr>
  66. <tr>
  67. <td>launchers</td>
  68. <td>Comma-separated list of commands, each of the form
  69. <var>name</var><code>=</code><var>module</var> or
  70. <var>name</var><code>=</code><var>module</var><code>/</code><var>mainclass</var></td>
  71. <td>No</td>
  72. </tr>
  73. <tr>
  74. <td>locales</td>
  75. <td>Comma-separated list of extra locales, or wildcard patterns matching
  76. multiple locale names, to include.
  77. Requires <code>jdk.localedata</code> module.</td>
  78. <td>No</td>
  79. </tr>
  80. <tr>
  81. <td>excludeResources</td>
  82. <td>Comma-separated list of patterns specifying resources to exclude
  83. from source jmods. Each is either a
  84. <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/FileSystem.html#getPathMatcher%28java.lang.String%29">standard PathMatcher pattern</a>
  85. or <code>@</code><var>filename</var>, indicating a text file with
  86. one resource name per line.</td>
  87. <td>No</td>
  88. </tr>
  89. <tr>
  90. <td>excludeFiles</td>
  91. <td>Comma-separated list of patterns specifying files to exclude
  92. from linked image. Each is either a
  93. <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/FileSystem.html#getPathMatcher%28java.lang.String%29">standard PathMatcher pattern</a>
  94. or <code>@</code><var>filename</var>, indicating a text file with
  95. one file name per line.</td>
  96. <td>No</td>
  97. </tr>
  98. <tr>
  99. <td>resourceOrder</td>
  100. <td>Comma-separated list of patterns specifying resource search order.
  101. Each is either a
  102. <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/FileSystem.html#getPathMatcher%28java.lang.String%29">standard PathMatcher pattern</a>
  103. or <code>@</code><var>filename</var>, indicating a text file with
  104. one resource name per line.</td>
  105. <td>No</td>
  106. </tr>
  107. <tr>
  108. <td>bindServices</td>
  109. <td>Boolean, whether to include in linked image any service providers
  110. found in module path corresponding to service provider interfaces
  111. used by explicitly linked modules.</td>
  112. <td>No, default is false</td>
  113. </tr>
  114. <tr>
  115. <td>ignoreSigning</td>
  116. <td>Boolean, whether to allow signed jar files.
  117. (Note: As of Java 11, this is ignored and is always treated as true.)</td>
  118. <td>No, default is false</td>
  119. </tr>
  120. <tr>
  121. <td>includeHeaders</td>
  122. <td>Boolean, whether to include header files in linked image.</td>
  123. <td>No, default is true</td>
  124. </tr>
  125. <tr>
  126. <td>includeManPages</td>
  127. <td>Boolean, whether to include man pages in linked image.</td>
  128. <td>No, default is true</td>
  129. </tr>
  130. <tr>
  131. <td>includeNativeCommands</td>
  132. <td>Boolean, whether to include native executables in linked image.</td>
  133. <td>No, default is true</td>
  134. </tr>
  135. <tr>
  136. <td>debug</td>
  137. <td>Boolean, whether to include debug information.</td>
  138. <td>No, default is true</td>
  139. </tr>
  140. <tr>
  141. <td>verboseLevel</td>
  142. <td>If set, the linker will produce verbose output, which will be logged at
  143. the specified Ant log level (<code>DEBUG</code>, <code>VERBOSE</code>,
  144. <code>INFO</code>, <code>WARN</code>, or <code>ERR</code>).</td>
  145. <td>No, default is no verbose output</td>
  146. </tr>
  147. <tr>
  148. <td>compress</td>
  149. <td>Compression level of linked image. One of:
  150. <dl>
  151. <dt><code>0</code> or
  152. <code>none</code></dt>
  153. <dd>no compression (default)</dd>
  154. <dt><code>1</code> or
  155. <code>strings</code></dt>
  156. <dd>constant string sharing</dd>
  157. <dt><code>2</code> or
  158. <code>zip</code></dt>
  159. <dd>zip compression</dd>
  160. </dl>
  161. </td>
  162. <td>No, default is no compression</td>
  163. </tr>
  164. <tr>
  165. <td>endianness</td>
  166. <td>Byte order of linked image, must be <code>little</code> or <code>big</code>
  167. <td>No, default is native byte order</td>
  168. </tr>
  169. <tr>
  170. <td>checkDuplicateLegal</td>
  171. <td>Boolean. When merging legal notices from different modules
  172. because they have the same name, verify that their contents
  173. are identical.</td>
  174. <td>No, default is false, which means any license files
  175. with the same name are assumed to have the same content, and no
  176. checking is done.</td>
  177. </tr>
  178. <tr>
  179. <td>vmType</td>
  180. <td>Hotspot VM in image. One of:
  181. <ul>
  182. <li><code>client</code>
  183. <li><code>server</code>
  184. <li><code>minimal</code>
  185. <li><code>all</code>
  186. </ul>
  187. </td>
  188. <td>No, default is <code>all</code></td>
  189. </tr>
  190. </table>
  191. <h3>Parameters specified as nested elements</h3>
  192. <p><code>&lt;link&gt;</code> can have the following nested elements:</p>
  193. <ul>
  194. <li><a href="#nested-modulepath">modulepath</a></li>
  195. <li><a href="#nested-module">module</a></li>
  196. <li><a href="#nested-observableModule">observableModule</a></li>
  197. <li><a href="#nested-launcher">launcher</a></li>
  198. <li><a href="#nested-locale">locale</a></li>
  199. <li><a href="#nested-resourceOrder">resourceOrder</a></li>
  200. <li><a href="#nested-excludeResources">excludeResources</a></li>
  201. <li><a href="#nested-excludeFiles">excludeFiles</a></li>
  202. <li><a href="#nested-compress">compress</a></li>
  203. <li><a href="#nested-releaseInfo">releaseInfo</a></li>
  204. </ul>
  205. <h4 id="nested-modulepath">modulepath</h4>
  206. <p><a href="../using.html#path">Path-like structure</a> pointing to
  207. jmod files to link into image.</p>
  208. <h4 id="nested-module">module</h4>
  209. <p>Names a single module to be placed in the linked image. This may be
  210. specified multiple times.</p>
  211. <p>Attributes:</p>
  212. <table class="attr">
  213. <tr>
  214. <th scope="col">Attribute</th>
  215. <th scope="col">Description</th>
  216. <th scope="col">Required</th>
  217. </tr>
  218. <tr>
  219. <td>name</td>
  220. <td>Name of module to add.</td>
  221. <td>Yes</td>
  222. </tr>
  223. </table>
  224. <h4 id="nested-observableModule">observableModule</h4>
  225. <p>Names a module visible to the linking process, instead of every module
  226. in the module path being considered. This may be specified multiple times.
  227. <p>Attributes:</p>
  228. <table class="attr">
  229. <tr>
  230. <th scope="col">Attribute</th>
  231. <th scope="col">Description</th>
  232. <th scope="col">Required</th>
  233. </tr>
  234. <tr>
  235. <td>name</td>
  236. <td>Name of module to add to list of observable modules.</td>
  237. <td>Yes</td>
  238. </tr>
  239. </table>
  240. <h4 id="nested-launcher">launcher</h4>
  241. <p>Specifies an executable file which will be added to the linked image,
  242. which executes a particular module's main class. Attributes:</p>
  243. <table class="attr">
  244. <tr>
  245. <th scope="col">Attribute</th>
  246. <th scope="col">Description</th>
  247. <th scope="col">Required</th>
  248. </tr>
  249. <tr>
  250. <td>name</td>
  251. <td>Name of launcher. This typically is used for the name of the
  252. executable file.</td>
  253. <td>Yes</td>
  254. </tr>
  255. <tr>
  256. <td>module</td>
  257. <td>Name of module to execute.</td>
  258. <td>Yes</td>
  259. </tr>
  260. <tr>
  261. <td>mainClass</td>
  262. <td>Name of entry point class in module to execute.</td>
  263. <td>Required unless module has its own main class defined.</td>
  264. </tr>
  265. </table>
  266. <h4 id="nested-locale">locale</h4>
  267. <p>Specifies locales to include in linked image. May be specified multiple
  268. times. Requires <code>jdk.localedata</code> module. Attributes:</p>
  269. <table class="attr">
  270. <tr>
  271. <th scope="col">Attribute</th>
  272. <th scope="col">Description</th>
  273. <th scope="col">Required</th>
  274. </tr>
  275. <tr>
  276. <td>name</td>
  277. <td>Name of locale, or wildcard pattern with <q><code>*</code></q>
  278. that matches multiple locale names.</td>
  279. <td>Yes</td>
  280. </tr>
  281. </table>
  282. <h4 id="nested-resourceOrder">resourceOrder</h4>
  283. <p>Explicit resource search order in linked image. May be specified multiple
  284. times. Attributes:</p>
  285. <table class="attr">
  286. <tr>
  287. <th scope="col">Attribute</th>
  288. <th scope="col">Description</th>
  289. <th scope="col">Required</th>
  290. </tr>
  291. <tr>
  292. <td>pattern</td>
  293. <td>A <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/FileSystem.html#getPathMatcher%28java.lang.String%29">standard PathMatcher pattern</a>
  294. for matching resources</td>
  295. <td rowspan="2">Exactly one of these</td>
  296. </tr>
  297. <tr>
  298. <td>listFile</td>
  299. <td class="left">Text file containing list of resource names (not patterns),
  300. one per line</td>
  301. </tr>
  302. </table>
  303. <p>If the <code>resourceOrder</code> attribute is also present on the task, its
  304. patterns are treated as if they occur before patterns in nested
  305. <code>&lt;resourceOrder&gt;</code> elements.</p>
  306. <h4 id="nested-excludeResources">excludeResources</h4>
  307. <p>Excludes files from linked image tree. May be specified multiple times.
  308. Attributes:</p>
  309. <table class="attr">
  310. <tr>
  311. <th scope="col">Attribute</th>
  312. <th scope="col">Description</th>
  313. <th scope="col">Required</th>
  314. </tr>
  315. <tr>
  316. <td>pattern</td>
  317. <td>A <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/FileSystem.html#getPathMatcher%28java.lang.String%29">standard PathMatcher pattern</a>
  318. for matching resources</td>
  319. <td rowspan="2">Exactly one of these</td>
  320. </tr>
  321. <tr>
  322. <td>listFile</td>
  323. <td class="left">Text file containing list of resource names (not patterns),
  324. one per line</td>
  325. </tr>
  326. </table>
  327. <h4 id="nested-excludeFiles">excludeFiles</h4>
  328. <p>Excludes files from linked image. May be specified multiple times.
  329. Attributes:</p>
  330. <table class="attr">
  331. <tr>
  332. <th scope="col">Attribute</th>
  333. <th scope="col">Description</th>
  334. <th scope="col">Required</th>
  335. </tr>
  336. <tr>
  337. <td>pattern</td>
  338. <td>A <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/FileSystem.html#getPathMatcher%28java.lang.String%29">standard PathMatcher pattern</a>
  339. for matching files</td>
  340. <td rowspan="2">Exactly one of these</td>
  341. </tr>
  342. <tr>
  343. <td>listFile</td>
  344. <td class="left">Text file containing list of file names (not patterns),
  345. one per line</td>
  346. </tr>
  347. </table>
  348. <h4 id="nested-compress">compress</h4>
  349. <p>Describes how image should be compressed. Attributes:</p>
  350. <table class="attr">
  351. <tr>
  352. <th scope="col">Attribute</th>
  353. <th scope="col">Description</th>
  354. <th scope="col">Required</th>
  355. </tr>
  356. <tr>
  357. <td>level</td>
  358. <td>Compression level of linked image. One of:
  359. <dl>
  360. <dt><code>0</code> or
  361. <code>none</code></dt>
  362. <dd>no compression (default)</dd>
  363. <dt><code>1</code> or
  364. <code>strings</code></dt>
  365. <dd>constant string sharing</dd>
  366. <dt><code>2</code> or
  367. <code>zip</code></dt>
  368. <dd>zip compression</dd>
  369. </dl>
  370. </td>
  371. <td>Yes</td>
  372. </tr>
  373. <tr>
  374. <td>files</td>
  375. <td>Comma-separated list of patterns matching files to compress.
  376. Each pattern either a
  377. <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/FileSystem.html#getPathMatcher%28java.lang.String%29">standard PathMatcher pattern</a>
  378. or <code>@</code><var>filename</var>, indicating a text file with
  379. one file name per line.</td>
  380. <td>No</td>
  381. </tr>
  382. </table>
  383. <p><code>&lt;compress&gt;</code> can also have any number of nested
  384. <code>&lt;files&gt;</code> elements, with these attributes:</p>
  385. <table class="attr">
  386. <tr>
  387. <th scope="col">Attribute</th>
  388. <th scope="col">Description</th>
  389. <th scope="col">Required</th>
  390. </tr>
  391. <tr>
  392. <td>pattern</td>
  393. <td>A <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/FileSystem.html#getPathMatcher%28java.lang.String%29">standard PathMatcher pattern</a>
  394. for matching files</td>
  395. <td rowspan="2">Exactly one of these</td>
  396. </tr>
  397. <tr>
  398. <td>listFile</td>
  399. <td class="left">Text file containing list of file names (not patterns),
  400. one per line</td>
  401. </tr>
  402. </table>
  403. <h4 id="nested-releaseInfo">releaseInfo</h4>
  404. <p>Replaces, augments, or trims the image's release info properties.
  405. Can be specified multiple times. Attributes:</p>
  406. <table class="attr">
  407. <tr>
  408. <th scope="col">Attribute</th>
  409. <th scope="col">Description</th>
  410. <th scope="col">Required</th>
  411. </tr>
  412. <tr>
  413. <td>file</td>
  414. <td>Java properties file containing new release info properties
  415. that will entirely replace the current ones.</td>
  416. <td>No</td>
  417. </tr>
  418. <tr>
  419. <td>delete</td>
  420. <td>Comma-separated property keys to remove from application's
  421. release info
  422. <td>No</td>
  423. </tr>
  424. </table>
  425. <p><code>&lt;releaseInfo&gt;</code> can also have any number of these nested elements:</p>
  426. <h5>add</h5>
  427. <p>Specifies additional release info properties. Attributes:</p>
  428. <table class="attr">
  429. <tr>
  430. <th scope="col">Attribute</th>
  431. <th scope="col">Description</th>
  432. <th scope="col">Required</th>
  433. </tr>
  434. <tr>
  435. <td>key</td>
  436. <td>Key of single property to add.</td>
  437. <td rowspan="2">Yes, unless <code>file</code> is specified</td>
  438. </tr>
  439. <tr>
  440. <td>value</td>
  441. <td class="left">Value of single property to add.</td>
  442. </tr>
  443. <tr>
  444. <td>file</td>
  445. <td>Java property file containing any number of properties to add.</td>
  446. <td>Yes, unless <code>key</code> and <code>value</code> are specified</td>
  447. </tr>
  448. <tr>
  449. <td>charset</td>
  450. <td>Character set of property file.</td>
  451. <td>No, default is <code>ISO_8859_1</code>, in accordance with
  452. java.util.Properties class.</td>
  453. </tr>
  454. </table>
  455. <h5>delete</h5>
  456. <p>Property keys to remove from applicaiton's release info. Attributes:</p>
  457. <table class="attr">
  458. <tr>
  459. <th scope="col">Attribute</th>
  460. <th scope="col">Description</th>
  461. <th scope="col">Required</th>
  462. </tr>
  463. <tr>
  464. <td>key</td>
  465. <td>Key of property to remove.</td>
  466. <td>Yes</td>
  467. </tr>
  468. </table>
  469. <h3>Examples</h3>
  470. <h4>Basic linking</h4>
  471. <pre>
  472. &lt;jmod destfile="MyApp.jmod" classpath="build/myapp.jar"/&gt;
  473. &lt;link destDir="build/image" modulepath="MyApp.jmod"
  474. modules="com.example.myapp"/&gt;
  475. </pre>
  476. <h4>Custom binaries</h4>
  477. <p>This will cause a <samp>bin/MyEditor</samp> script to appear in the
  478. image:
  479. <pre>
  480. &lt;jmod destfile="MyApp.jmod" classpath="build/myapp.jar"/&gt;
  481. &lt;link destDir="build/image" modulepath="MyApp.jmod"
  482. modules="com.example.myapp"
  483. launchers="MyEditor=com.example.myapp/com.example.myapp.editors.EditorMain"/&gt;
  484. </pre>
  485. <p>Same thing, using a nested launcher element:</p>
  486. <pre>
  487. &lt;jmod destfile="MyApp.jmod" classpath="build/myapp.jar"/&gt;
  488. &lt;link destDir="build/image" modulepath="MyApp.jmod"
  489. modules="com.example.myapp"&gt;
  490. &lt;launcher name="MyEditor" module="com.example.myapp"
  491. mainClass="com.example.myapp.editors.EditorMain"/&gt;
  492. &lt;/link&gt;
  493. </pre>
  494. <h4>Limiting locales</h4>
  495. <p>Include just the locales needed by the application from the <a href="https://docs.oracle.com/en/java/javase/11/docs/api/jdk.localedata/module-summary.html">jdk.localedata</a> module:</p>
  496. <pre>
  497. &lt;jmod destfile="MyApp.jmod" classpath="build/myapp.jar"/&gt;
  498. &lt;link destDir="build/image" modulepath="MyApp.jmod"
  499. modules="com.example.myapp,jdk.localedata"
  500. locales="zh,jp-*"/&gt;
  501. </pre>
  502. <h4>Compressed image</h4>
  503. <p>Compress entire image:</p>
  504. <pre>
  505. &lt;jmod destfile="MyApp.jmod" classpath="build/myapp.jar"/&gt;
  506. &lt;link destDir="build/image" modulepath="MyApp.jmod"
  507. modules="com.example.myapp,jdk.localedata"
  508. compress="zip"/&gt;
  509. </pre>
  510. <p>Compress only some files in the image:</p>
  511. <pre>
  512. &lt;jmod destfile="MyApp.jmod" classpath="build/myapp.jar"/&gt;
  513. &lt;link destDir="build/image" modulepath="MyApp.jmod"
  514. modules="com.example.myapp,jdk.localedata"&gt;
  515. &lt;compress level="zip" files=".*\.xml"/&gt;
  516. &lt;/link&gt;
  517. </pre>
  518. <h4>Cross-compiling</h4>
  519. <p>To create an image for a different platform:
  520. <ul>
  521. <li>Download the JDK for that platform, and expand the archive manually into
  522. a directory of your choice. (Downloading a zip or tar.gz version of a JDK
  523. instead of an installer will make this easier.)</li>
  524. <li>Determine the foreign JDK's platform string. This can be done with
  525. a command that examines the JDK's <samp>jmods/java.base.jmod</samp> file:
  526. <pre>
  527. jmod describe "$FOREIGN_JDK_HOME"/jmods/java.base.jmod | grep '^platform'
  528. </pre>
  529. </li>
  530. <li>Create your jmod using the foreign JDK's platform string:
  531. <pre>
  532. &lt;jmod destfile="MyApp.jmod" classpath="build/myapp.jar" platform="windows-amd64"/&gt;
  533. </pre>
  534. </li>
  535. <li>Link with the foreign JDK's <samp>jmods</samp> directory in the module path:
  536. <pre>
  537. &lt;link destDir="build/image"
  538. modulepath="MyApp.jmod;${foreign-jdk-home}/jmods"
  539. modules="com.example.myapp"/&gt;
  540. </pre>
  541. </li>
  542. </ul>
  543. </body>
  544. </html>