-
Notifications
You must be signed in to change notification settings - Fork 25
/
maven.html
79 lines (69 loc) · 3.03 KB
/
maven.html
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
<h2>Run HelloWorld using Maven</h2>
<p>
If you want to develop JavaFX applications using Maven, you don't have to download
the JavaFX SDK. Just specify the modules and the versions you want in the <kbd>pom.xml</kbd>,
and the build system will download the required modules, including the native libraries for your platform.
</p>
<p>
Here is a <a class="samples" href="https://github.com/openjfx/samples/blob/master/HelloFX/Maven/hellofx/pom.xml" target="_blank">pom.xml</a>
file which shows how to achieve this, included in this <a class="samples" href="https://github.com/openjfx/samples/blob/master/HelloFX/Maven" target="_blank">sample</a>.
</p>
<p>
Alternatively, we have created <a href="https://github.com/openjfx/javafx-maven-archetypes" target="_blank">JavaFX Maven Archetypes</a> to quickly create Maven projects.
A simple JavaFX project can be created by executing the following command:
</p>
<pre><code>
mvn archetype:generate \
-DarchetypeGroupId=org.openjfx \
-DarchetypeArtifactId=javafx-archetype-simple \
-DarchetypeVersion=0.0.3 \
-DgroupId=org.openjfx \
-DartifactId=sample \
-Dversion=1.0.0 \
-Djavafx-version=<span class="JFX_VERSION">11</span>
</code></pre>
<p>
The pom uses the <a href="https://github.com/openjfx/javafx-maven-plugin" target="_blank">JavaFX Maven plugin</a>:
</p>
<pre><code>
<plugins>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version><span class="JFX_MVN_PLUGIN_VERSION">0.0.1</span></version>
<configuration>
<mainClass>HelloFX</mainClass>
</configuration>
</plugin>
</plugins>
</code></pre>
<p>
Add the maven dependencies:
</p>
<pre><code>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version><span class="JFX_VERSION">11</span></version>
</dependency>
</dependencies>
</code></pre>
<p>
<b>Important</b>: Note that transitive dependencies are automatically resolved
(for instance, there is no need to add a dependency for the <kbd>javafx.graphics</kbd> module, since it is
<a href="https://openjfx.io/javadoc/23/javafx.controls/module-summary.html" target="_blank">transitively</a> resolved by the
<kbd>javafx.controls</kbd> module). But if your application is using <kbd>FXML</kbd>, you will need to
add a dependency for the <kbd>javafx.fxml</kbd> module as well.
</p>
<p>
Finally, run the application (e.g. based on the <a class="samples" href="https://github.com/openjfx/samples/blob/master/HelloFX/Maven/hellofx/src/main/java/HelloFX.java" target="_blank">HelloFX.java</a>
from the referred sample):
</p>
<pre><code>
mvn clean javafx:run
</code></pre>
<div class="alert alert-warning">
<strong>Note: </strong>
Make sure to set the JAVA_HOME environment variable to the correct JDK location.
</div>