Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to use jlink in IntelliJ IDEA to create a custom modular run-time image?

I'm following the Project Jigsaw: Module System Quick-Start Guide in IntelliJ IDEA 2018.2.5. I did everything right in the IDE until The linker section. Is there any way to use jlink in IntelliJ IDEA?

jlink (see JEP 282) is the linker tool and can be used to link a set of modules, along with their transitive dependences, to create a custom modular run-time image (see JEP 220).
- Project Jigsaw: Module System Quick-Start Guide

I found this Ability to produce JLink artefacts issue in JetBrains Bug & Issue Tracker, but it has been open for more than 2 years and it doesn't even have a description.


As a workaround, I have seen this Is there a maven jigsaw jlink plugin? interesting question and the most promising alternative seems to be the Apache Maven JLink Plugin, but it has also been there for more than 2 years and it hasn't been released yet.

like image 848
lcnicolau Avatar asked Nov 09 '18 17:11

lcnicolau


People also ask

What is Jlink used for?

Jlink is a Java command line tool that is used to generate a custom Java runtime environment (JRE). You can use your customized JRE to run Java applications. Using jlink, you can create a custom runtime environment that only includes the relevant class file.

How do I create a runtime image?

Creating Runtime Images To create an image, jlink needs two pieces of information, each specified with a command line option: which modules to start with / --add-modules. in which folder to create the image / --output.

How do I create a custom JRE?

You can use jdep command on your custom module to know module dependency . 5. Now use jlink command line tool to create your custom JRE. Command will create new JRE and now you can use your own JRE to run your program.

How do I compile a module in IntelliJ?

Build a module, or a project  Select a module or a project you want to compile and from the main menu, select Build | Build Project ( Ctrl+F9 ). IntelliJ IDEA displays the compilation results in the Review compilation and build output.


1 Answers

You could use Ant as a build tool and specify your own jlink target, like this:

<target name="link">
    <echo message="Creating jlink image in directory = dist\bin\java" />
    <exec executable="jlink">
        <arg line='--module-path bin;"C:\Program Files\Java\jdk-11.0.1-Linux\jmods";"C:\Users\VTorroni\_libs\hsqldb-2.4.1\modules";"C:\Users\VTorroni\_libs\tinylog-1.3.5\module";"C:\Users\VTorroni\_libs\javax.servlet-api-4.0.1\module\javax.servlet.api-4.0.1.jar" --add-modules pnode --output dist\bin\java --strip-debug --no-header-files --no-man-pages --compress=2' />
    </exec>
</target>
like image 172
Vittorio Torroni Avatar answered Sep 25 '22 06:09

Vittorio Torroni