运行 JavaFX 11+ 应用的 Maven 插件
该插件在Maven仓库可以找到。
如果要build和install最新的快照, 你可以clone本项目, 并设置成JDK 11运行
mvn install
创建一个 Maven 项目,使用现有的项目,例如:HelloFX,或者使用 archetype 。
该项目可以是模块化的也可以是非模块化的。
添加 JavaFX 依赖项:
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>12.0.2</version>
</dependency>
添加插件:
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<mainClass>hellofx/org.openjfx.App</mainClass>
</configuration>
</plugin>
编译项目 (可选):
mvn javafx:compile
或者使用 maven-compiler-plugin
:
mvn compile
Note that including this plugin is convenient for a better project integration within your IDE.
运行项目:
mvn javafx:run
For modular projects, to create and run a custom image:
mvn javafx:jlink
target/image/bin/java -m hellofx/org.openjfx.App
When compiling with javafx:compile
, the source level,
target level and/or the release level for the Java compiler can be set.
The default value is 11.
This configuration changes these levels to 12, for instance:
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<source>12</source>
<target>12</target>
<release>12</release>
<mainClass>org.openjfx.hellofx/org.openjfx.App</mainClass>
</configuration>
</plugin>
If required, compiler arguments can be set. For instance:
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<compilerArgs>
<arg>--add-exports</arg>
<arg>javafx.graphics/com.sun.glass.ui=org.openjfx.hellofx</arg>
</compilerArgs>
<mainClass>org.openjfx.hellofx/org.openjfx.App</mainClass>
</configuration>
</plugin>
The plugin includes by default: --module-path
, --add-modules
and -classpath
options.
Optionally, the configuration can be modified with:
mainClass
: The main class, fully qualified name, with or without module nameworkingDirectory
: The current working directoryskip
: Skip the execution. Values: false (default), trueoutputFile
File to redirect the process outputoptions
: A list of VM options passed to the executable.commandlineArgs
: Arguments separated by space for the executed programincludePathExceptionsInClasspath
: When resolving the module-path, setting this value to true will include the
dependencies that generate path exceptions in the classpath. By default the value is false, and these dependencies
won't be included.For instance, the following configuration adds some VM options and a command line argument:
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<mainClass>org.openjfx.hellofx/org.openjfx.App</mainClass>
<options>
<option>--add-opens</option>
<option>java.base/java.lang=org.openjfx.hellofx</option>
</options>
<commandlineArgs>-Xmx1024m</commandlineArgs>
</configuration>
</plugin>
注意
可以使用本地SDK代替 Maven Central。 This is helpful for developers trying to test a local build of OpenJFX. Since transitive dependencies are not resolved, all the required jars needs to be added as a separate dependency, like:
<properties>
<sdk>/path/to/javafx-sdk</sdk>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx.base</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${sdk}/lib/javafx.base.jar</systemPath>
</dependency>
...
</dependencies>
The same command line options for jlink
can be set:
stripDebug
: Strips debug information out. Values: false (default) or truecompress
: Compression level of the resources being used. Values: 0 (default), 1, 2.noHeaderFiles
: Removes the includes
directory in the resulting runtime image. Values: false (default) or truenoManPages
: Removes the man
directory in the resulting runtime image. Values: false (default) or truebindServices
: Adds the option to bind services. Values: false (default) or trueignoreSigningInformation
: Adds the option to ignore signing information. Values: false (default) or truejlinkVerbose
: Adds the verbose option. Values: false (default) or truelauncher
: Adds a launcher script with the given name.
options
are defined, these will be passed to the launcher script as vm options.commandLineArgs
are defined, these will be passed to the launcher script as command line arguments.jlinkImageName
: The name of the folder with the resulting runtime imagejlinkZipName
: When set, creates a zip of the resulting runtime imagejlinkExecutable
: The jlink
executable. It can be a full path or the name of the executable, if it is in the PATH.jmodsPath
: When using a local JavaFX SDK, sets the path to the local JavaFX jmodsFor instance, with the following configuration:
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<stripDebug>true</stripDebug>
<compress>2</compress>
<noHeaderFiles>true</noHeaderFiles>
<noManPages>true</noManPages>
<launcher>hellofx</launcher>
<jlinkImageName>hello</jlinkImageName>
<jlinkZipName>hellozip</jlinkZipName>
<mainClass>hellofx/org.openjfx.MainApp</mainClass>
</configuration>
</plugin>
a custom image can be created and run as:
mvn clean javafx:jlink
target/hello/bin/hellofx
可以将问题提交到 Issues 跟踪器.
Contributions can be submitted via Pull 请求, providing you have signed the Gluon Individual Contributor License Agreement (CLA).
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。