Skip to content

Commit

Permalink
Merge pull request #40 from jperedadnr/issue-27
Browse files Browse the repository at this point in the history
#27: Update docs with new JavaFX plugin
  • Loading branch information
José Pereda committed Nov 24, 2018
2 parents 55e0792 + 6038ae6 commit 351523a
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 85 deletions.
61 changes: 8 additions & 53 deletions gradle.html
Original file line number Diff line number Diff line change
@@ -1,70 +1,25 @@
<h2>Run HelloWorld using Gradle</h2>

<p>
Similar to Maven, we can declare JavaFX jars as dependency in the <kbd>build.gradle</kbd> file.
However, for Gradle we need to find and specify the platform/OS as classifier. This requires a
small script:
Similar to Maven, we can declare the required JavaFX modules in the <kbd>build.gradle</kbd> file.
However, for Gradle we need to apply the JavaFX gradle plugin:
</p>

<pre><code>
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.gradle:osdetector-gradle-plugin:1.6.0'
}
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.5'
}

apply plugin: 'application'
apply plugin: 'com.google.osdetector'

ext.platform = osdetector.os == 'osx' ? 'mac' : osdetector.os == 'windows' ? 'win' : osdetector.os
</code></pre>

<p>
Next, we add all the dependencies using the platform. For instance, if we only need the <kbd>javafx.controls</kbd>
Next, we add the required modules. For instance, if we only need the <kbd>javafx.controls</kbd>
module, we will include:
</p>

<pre><code>
dependencies {
compile "org.openjfx:javafx-base:<span class="JFX_VERSION">11</span>:$platform"
compile "org.openjfx:javafx-graphics:<span class="JFX_VERSION">11</span>:$platform"
compile "org.openjfx:javafx-controls:<span class="JFX_VERSION">11</span>:$platform"
}
</code></pre>

<div class="alert alert-warning">
<strong>Note: </strong>
The classifiers are not taken into account when resolving
transitive dependencies in Gradle. Therefore, we need to specify all this three JavaFX modules
with <kbd>platform</kbd> as classifier.
</div>

<p>
Next, we set <kbd>--module-path</kbd> to the value that would have been the classpath
and add <kbd>javafx.controls</kbd> as a module to both <kbd>javac</kbd> and <kbd>java</kbd> commands.
This makes sense because all the dependencies are currently on the classpath.
</p>

<pre><code>
compileJava {
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'javafx.controls'
]
}
}

run {
doFirst {
jvmArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'javafx.controls'
]
}
javafx {
modules = [ 'javafx.controls' ]
}
</code></pre>

Expand Down
26 changes: 16 additions & 10 deletions ide-eclipse.html
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,15 @@ <h5>2. Modify the build</h5>
<kbd>mainClassName</kbd> accordingly to <kbd>org.openjfx.MainApp</kbd>.
</p>
<p>
Note we have added the required dependencies with the classifier for the platform.
Since Gradle doesn't resolve transitive dependencies with classifiers, we need to add all
the modules (<kbd>javafx.base</kbd>, <kbd>javafx.graphics</kbd> and for <kbd>javafx.controls</kbd>).

Similar to Maven, we can declare the required JavaFX modules in the <kbd>build.gradle</kbd> file.
However, for Gradle we need to apply the JavaFX gradle plugin:
</p>
<pre><code>
javafx {
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
</code></pre>
<p>
Refresh the gradle project and you will get the JavaFX dependencies.
<a href="images/ide/eclipse/gradle/eclipse03.png" target="_blank"><img src="images/ide/eclipse/gradle/eclipse03.png" alt="Update the build"/></a>
As for any other Gradle dependencies, these jars can be found in the local <kbd>.gradle</kbd> repository.
Expand All @@ -324,7 +329,8 @@ <h5>3. Add the source code</h5>
and the <a class="samples" href="/IDE/Eclipse/Non-Modular/Gradle/hellofx/src/main/resources/org/openjfx/scene.fxml" target="_blank">FXML</a> and
and the <a class="samples" href="/IDE/Eclipse/Non-Modular/Gradle/hellofx/src/main/resources/org/openjfx/styles.css" target="_blank">css</a>
files.

</p>
<p>
You can add a main class <kbd>MainApp</kbd>, and an <kbd>FXMLController</kbd> class, and add to resources the <kbd>FXML</kbd> file.

<a href="images/ide/eclipse/maven/eclipse04.png" target="_blank"><img src="images/ide/eclipse/maven/eclipse04.png" alt="Add JavaFX project"/></a>
Expand Down Expand Up @@ -398,8 +404,7 @@ <h5>4. Run the project</h5>

<pre class="alert"><code class="alert">
run {
...
if (platform == 'win') {
if (osdetector.os == 'windows') {
systemProperty "java.library.path", "C:\tmp"
}
}
Expand Down Expand Up @@ -661,9 +666,10 @@ <h5>2. Modify the build</h5>
</p>

<p>
Note the use of the <kbd>org.javamodularity.moduleplugin</kbd> plugin, that removes the necessity of setting the module-path
for the compile and run task.

Note the use of the <kbd>org.openjfx.javafxplugin</kbd> plugin, that removes the necessity of adding the
JavaFX dependencies and setting the module-path for the compile and run task for them.
</p>
<p>
Note also that the use of the <kbd>eclipse</kbd> plugin is required to include the modules to the module path.

<a href="images/ide/eclipse/modular/gradle/eclipse01.png" target="_blank"><img src="images/ide/eclipse/modular/gradle/eclipse01.png" alt="Update the build"/></a>
Expand Down
30 changes: 20 additions & 10 deletions ide-intellij.html
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,16 @@ <h5>2. Modify the build</h5>
<kbd>mainClassName</kbd> accordingly to <kbd>org.openjfx.MainApp</kbd>.
</p>
<p>
Unlike Maven, the platform needs to be manually determined and added as classifier to the dependencies.
Since Gradle doesn't resolve transitive dependencies with classifiers, we need to add all
the modules (<kbd>javafx.base</kbd>, <kbd>javafx.graphics</kbd> and for <kbd>javafx.controls</kbd>).

Similar to Maven, we can declare the required JavaFX modules in the <kbd>build.gradle</kbd> file.
However, for Gradle we need to apply the JavaFX gradle plugin:
</p>
<pre><code>
javafx {
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
</code></pre>

<p>
Synchronize the project and you will get the JavaFX dependencies.
<a href="images/ide/intellij/gradle/idea03.png" target="_blank"><img src="images/ide/intellij/gradle/idea03.png" alt="Update the build"/></a>
As for any other Gradle dependencies, these jars can be found in the local <kbd>.gradle</kbd> repository.
Expand Down Expand Up @@ -288,8 +294,12 @@ <h5>2. Set JDK <span class="JDK_MAJOR">11</span> and add JavaFX11</h5>

<p>
Go to <kbd>File -> Project Structure -> Project</kbd>, and set the project SDK to <span class="JDK_MAJOR">11</span>.
You can also set the language level to 11.

You can also set the language level to 11 and change the default compiler output directory
<kbd>out</kbd> to <kbd>mods</kbd>.

<a href="images/ide/intellij/modular/ide/idea00.png" target="_blank"><img src="images/ide/intellij/modular/ide/idea00.png" alt="mods output"/></a>
</p>
<p>
Go to <kbd>File -> Project Structure -> Libraries</kbd> and add the JavaFX <span class="JFX_MAJOR">11</span> SDK as a library to the project.
Point to the <kbd>lib</kbd> folder of the JavaFX SDK.
</p>
Expand Down Expand Up @@ -333,12 +343,12 @@ <h5>5. Add VM options</h5>
<div class="tab-content">
<div class="tab-pane active" id="nix-idea-mod-ide-1">
<pre class="no-border-radius"><code>
--module-path $PATH_TO_FX:mods/production --add-modules=javafx.controls,javafx.fxml
--module-path $PATH_TO_FX:mods/production
</code></pre>
</div>
<div class="tab-pane" id="win-idea-mod-ide-1">
<pre><code>
--module-path "%PATH_TO_FX%;mods\production" --add-modules=javafx.controls,javafx.fxml
--module-path "%PATH_TO_FX%;mods\production"
</code></pre>
</div>
</div>
Expand Down Expand Up @@ -503,8 +513,8 @@ <h5>2. Modify the build</h5>
<kbd>mainClassName</kbd> accordingly to <kbd>org.openjfx.MainApp</kbd>.
</p>
<p>
Note the use of the <kbd>org.javamodularity.moduleplugin</kbd> plugin, that removes the necessity of setting the module-path
for the compile and run task.
Note the use of the <kbd>org.openjfx.javafxplugin</kbd> plugin, that removes the necessity of adding the
JavaFX dependencies and setting the module-path for the compile and run task for them.

<a href="images/ide/intellij/modular/gradle/idea01.png" target="_blank"><img src="images/ide/intellij/modular/gradle/idea01.png" alt="Update the build"/></a>
</p>
Expand Down
21 changes: 13 additions & 8 deletions ide-netbeans.html
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,14 @@ <h5>2. Modify the build</h5>
<kbd>mainClassName</kbd> accordingly to <kbd>org.openjfx.MainApp</kbd>.
</p>
<p>
Note we have added the required dependencies with the classifier for the platform.
Since Gradle doesn't resolve transitive dependencies with classifiers, we need to add all
the modules (<kbd>javafx.base</kbd>, <kbd>javafx.graphics</kbd> and for <kbd>javafx.controls</kbd>).

We can declare the required JavaFX modules in the <kbd>build.gradle</kbd> file using the JavaFX gradle plugin:
</p>
<pre><code>
javafx {
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
</code></pre>
<p>
Reload the project and you will get the JavaFX dependencies.

<a href="images/ide/netbeans/gradle/netbeans03.png" target="_blank"><img src="images/ide/netbeans/gradle/netbeans03.png" alt="Update the build"/></a>
Expand All @@ -303,9 +307,10 @@ <h5>3. Add the source code</h5>
and the <a class="samples" href="/IDE/NetBeans/Non-Modular/Gradle/hellofx/src/main/resources/org/openjfx/scene.fxml" target="_blank">FXML</a> and
and the <a class="samples" href="/IDE/NetBeans/Non-Modular/Gradle/hellofx/src/main/resources/org/openjfx/styles.css" target="_blank">css</a>
files.

Note that the JavaFX classes are recognized by the IDE.

<a href="images/ide/netbeans/gradle/netbeans04.png" target="_blank"><img src="images/ide/netbeans/gradle/netbeans04.png" alt="Add JavaFX project"/></a>

Note that the JavaFX classes are recognized by the IDE.
</p>

<h5>4. Run the project</h5>
Expand Down Expand Up @@ -566,8 +571,8 @@ <h5>2. Modify the build</h5>
<kbd>mainClassName</kbd> accordingly to <kbd>org.openjfx.MainApp</kbd>.
</p>
<p>
Note the use of the <kbd>org.javamodularity.moduleplugin</kbd> plugin, that removes the necessity of setting the module-path
for the compile and run task.
Note the use of the <kbd>org.openjfx.javafxplugin</kbd> plugin, that removes the necessity of adding the
JavaFX dependencies and setting the module-path for the compile and run task for them.

<a href="images/ide/netbeans/modular/gradle/netbeans01.png" target="_blank"><img src="images/ide/netbeans/modular/gradle/netbeans01.png" alt="Update the build"/></a>
</p>
Expand Down
Binary file modified images/ide/eclipse/gradle/eclipse03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/ide/eclipse/modular/gradle/eclipse01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/ide/intellij/modular/gradle/idea01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/ide/intellij/modular/ide/idea00.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/ide/netbeans/gradle/netbeans03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/ide/netbeans/modular/gradle/netbeans01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions js/gluon.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ $(function() {
});
});

$(document).on('click', '.modular-jlink-action', function(event) {
event.preventDefault();
var anchor = $('.jlink');
$('html,body').scrollTop($(anchor).offset().top);
});

// Scroll to anchor from list-group-sub links
$(document).on('click', ".scrollto", function(event) {
event.preventDefault();
Expand Down
12 changes: 8 additions & 4 deletions modular.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ <h2>Runtime images</h2>
</div>
</div>

<a name="jlink"></a><h4>jlink</h4>
<a class="jlink"></a><h4>jlink</h4>

<p>
With a modular project, <a href="https://docs.oracle.com/en/java/javase/11/tools/jlink.html">jlink</a>
With a modular project, <a href="https://docs.oracle.com/en/java/javase/11/tools/jlink.html" target="_blank">jlink</a>
can be used to create a custom runtime image using the JavaFX jmods:
</p>

Expand Down Expand Up @@ -252,7 +252,7 @@ <h2>Runtime images</h2>
</div>

<p>
To create a custom runtime the referred <a href="#jlink">steps</a> have been added to the <kbd>jlink</kbd> task
To create a custom runtime the referred <a class="modular-jlink-action" href="#">steps</a> have been added to the <kbd>jlink</kbd> task
included in the build file.
</p>

Expand Down Expand Up @@ -516,7 +516,7 @@ <h4>Gradle</h4>
</p>

<pre><code>
mainClassName = 'hellofx.Launcher'
mainClassName = 'hellofx.HelloFX'
jar {
manifest {
attributes 'Main-Class': 'hellofx.Launcher'
Expand Down Expand Up @@ -570,6 +570,10 @@ <h5>Cross-platform jar</h5>
compile "org.openjfx:javafx-graphics:<span class="JFX_VERSION">11</span>:mac"
</code></pre>

<p>
Now run the jar task again to create the cross-platform fat jar.
</p>

<a name="command-line"></a><h3>Command Line</h3>

<p>
Expand Down

0 comments on commit 351523a

Please sign in to comment.