├── .gitignore
├── README.md
├── fd-java9-jigsaw-algorithm-add
├── pom.xml
└── src
│ └── main
│ └── java
│ ├── module-info.java
│ └── nl
│ └── frisodobber
│ └── java9
│ └── jigsaw
│ └── calculator
│ └── algorithm
│ └── add
│ └── Add.java
├── fd-java9-jigsaw-algorithm-api
├── pom.xml
└── src
│ └── main
│ └── java
│ ├── module-info.java
│ └── nl
│ └── frisodobber
│ └── java9
│ └── jigsaw
│ └── calculator
│ └── algorithm
│ └── api
│ └── Algorithm.java
├── fd-java9-jigsaw-algorithm-substract
├── pom.xml
└── src
│ └── main
│ └── java
│ ├── module-info.java
│ └── nl
│ └── frisodobber
│ └── java9
│ └── jigsaw
│ └── calculator
│ └── algorithm
│ └── substract
│ └── Substract.java
├── fd-java9-jigsaw-cli
├── pom.xml
└── src
│ └── main
│ └── java
│ ├── module-info.java
│ └── nl
│ └── frisodobber
│ └── java9
│ └── jigsaw
│ └── calculator
│ └── cli
│ └── Main.java
├── fd-java9-jigsaw-gui
├── pom.xml
└── src
│ └── main
│ └── java
│ ├── module-info.java
│ └── nl
│ └── frisodobber
│ └── java9
│ └── jigsaw
│ └── calculator
│ └── gui
│ └── Main.java
├── java-commandos.txt
└── pom.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # IDEs and editors
4 | /.idea
5 | *.iml
6 | **/target
7 | libs
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # maven-java9-jigsaw
2 |
3 | ## Install
4 |
5 | ### Step 1: Create a toolchains.xml in you Maven local repository folder .m2
6 | Default location:
7 | - Linux (Ubuntu): ~/.m2
8 | - Windows: C:\Documents and Settings\{your-username}\.m2
9 |
10 | toolchains.xml example:
11 |
12 | ```
13 |
14 |
15 |
16 | jdk
17 |
18 | 1.9
19 | oracle
20 |
21 |
22 | /path/to/jdk-9
23 |
24 |
25 |
26 | jdk
27 |
28 | 1.8
29 | oracle
30 |
31 |
32 | /path/to/jdk1.8.0_112
33 |
34 |
35 |
36 | ```
37 |
38 | ### Step 2: Build the application
39 | ```
40 | mvn clean package
41 | ```
42 |
43 | ### Step 3: Run the GUI or CLI
44 | Your JAVA_HOME should be pointing to jdk9 for this
45 | ##### Run GUI
46 | ```
47 | java --module-path libs:lib -m calculator.gui/nl.frisodobber.java9.jigsaw.calculator.gui.Main
48 | ```
49 | ##### Run CLI
50 | ```
51 | java --module-path libs:lib -m calculator.cli/nl.frisodobber.java9.jigsaw.calculator.cli.Main
52 | ```
53 |
54 |
55 |
--------------------------------------------------------------------------------
/fd-java9-jigsaw-algorithm-add/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | fd-java9-jigsaw
7 | nl.frisodobber
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | fd-java9-jigsaw-algorithm-add
13 |
14 |
15 |
16 | nl.frisodobber
17 | fd-java9-jigsaw-algorithm-api
18 | ${project.version}
19 |
20 |
21 |
22 |
23 |
24 |
25 | org.apache.maven.plugins
26 | maven-jar-plugin
27 |
28 | ../libs
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/fd-java9-jigsaw-algorithm-add/src/main/java/module-info.java:
--------------------------------------------------------------------------------
1 | module calculator.algorithm.add {
2 | requires calculator.algorithm.api;
3 |
4 | provides nl.frisodobber.java9.jigsaw.calculator.algorithm.api.Algorithm
5 | with nl.frisodobber.java9.jigsaw.calculator.algorithm.add.Add;
6 | }
--------------------------------------------------------------------------------
/fd-java9-jigsaw-algorithm-add/src/main/java/nl/frisodobber/java9/jigsaw/calculator/algorithm/add/Add.java:
--------------------------------------------------------------------------------
1 | package nl.frisodobber.java9.jigsaw.calculator.algorithm.add;
2 |
3 | import nl.frisodobber.java9.jigsaw.calculator.algorithm.api.Algorithm;
4 | /**
5 | * Created by dobber on 31-12-16.
6 | */
7 | public class Add implements Algorithm {
8 |
9 | @Override
10 | public Integer calculate(Integer input, Integer input2) {
11 | return input + input2;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/fd-java9-jigsaw-algorithm-api/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | fd-java9-jigsaw
7 | nl.frisodobber
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | fd-java9-jigsaw-algorithm-api
13 |
14 |
15 |
16 |
17 | org.apache.maven.plugins
18 | maven-jar-plugin
19 |
20 | ../libs
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/fd-java9-jigsaw-algorithm-api/src/main/java/module-info.java:
--------------------------------------------------------------------------------
1 | module calculator.algorithm.api {
2 | exports nl.frisodobber.java9.jigsaw.calculator.algorithm.api;
3 | }
--------------------------------------------------------------------------------
/fd-java9-jigsaw-algorithm-api/src/main/java/nl/frisodobber/java9/jigsaw/calculator/algorithm/api/Algorithm.java:
--------------------------------------------------------------------------------
1 | package nl.frisodobber.java9.jigsaw.calculator.algorithm.api;
2 |
3 | /**
4 | * Created by dobber on 31-12-16.
5 | */
6 | public interface Algorithm {
7 | Integer calculate(Integer input, Integer input2);
8 | }
9 |
--------------------------------------------------------------------------------
/fd-java9-jigsaw-algorithm-substract/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | fd-java9-jigsaw
7 | nl.frisodobber
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | fd-java9-jigsaw-algorithm-substract
13 |
14 |
15 |
16 | nl.frisodobber
17 | fd-java9-jigsaw-algorithm-api
18 | ${project.version}
19 |
20 |
21 |
22 |
23 |
24 |
25 | org.apache.maven.plugins
26 | maven-jar-plugin
27 |
28 | ../libs
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/fd-java9-jigsaw-algorithm-substract/src/main/java/module-info.java:
--------------------------------------------------------------------------------
1 | module calculator.algorithm.substract {
2 | requires calculator.algorithm.api;
3 |
4 | provides nl.frisodobber.java9.jigsaw.calculator.algorithm.api.Algorithm
5 | with nl.frisodobber.java9.jigsaw.calculator.algorithm.substract.Substract;
6 | }
--------------------------------------------------------------------------------
/fd-java9-jigsaw-algorithm-substract/src/main/java/nl/frisodobber/java9/jigsaw/calculator/algorithm/substract/Substract.java:
--------------------------------------------------------------------------------
1 | package nl.frisodobber.java9.jigsaw.calculator.algorithm.substract;
2 |
3 | import nl.frisodobber.java9.jigsaw.calculator.algorithm.api.Algorithm;
4 | /**
5 | * Created by dobber on 31-12-16.
6 | */
7 | public class Substract implements Algorithm {
8 |
9 | @Override
10 | public Integer calculate(Integer input, Integer input2) {
11 | return input - input2;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/fd-java9-jigsaw-cli/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | fd-java9-jigsaw
7 | nl.frisodobber
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | fd-java9-jigsaw-cli
13 |
14 |
15 |
16 | nl.frisodobber
17 | fd-java9-jigsaw-algorithm-api
18 | ${project.version}
19 |
20 |
21 |
22 |
23 |
24 | org.apache.maven.plugins
25 | maven-jar-plugin
26 |
27 | ../libs
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/fd-java9-jigsaw-cli/src/main/java/module-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by dobber on 31-12-16.
3 | */
4 | module calculator.cli {
5 | requires calculator.algorithm.api;
6 | uses nl.frisodobber.java9.jigsaw.calculator.algorithm.api.Algorithm;
7 | }
8 |
--------------------------------------------------------------------------------
/fd-java9-jigsaw-cli/src/main/java/nl/frisodobber/java9/jigsaw/calculator/cli/Main.java:
--------------------------------------------------------------------------------
1 | package nl.frisodobber.java9.jigsaw.calculator.cli;
2 |
3 | import nl.frisodobber.java9.jigsaw.calculator.algorithm.api.Algorithm;
4 |
5 | import java.io.Console;
6 | import java.util.HashMap;
7 | import java.util.Map;
8 | import java.util.ServiceLoader;
9 |
10 | /**
11 | * Created by dobber on 31-12-16.
12 | */
13 | public class Main {
14 | private ServiceLoader algorithms;
15 | private Map algorithmMap;
16 |
17 | public Main() {
18 | loadAlgorithms();
19 | }
20 |
21 | private void loadAlgorithms() {
22 | algorithms = ServiceLoader.load(Algorithm.class);
23 | algorithmMap = new HashMap<>();
24 | algorithms.stream().forEach(al -> algorithmMap.put(al.get().getClass().getSimpleName(), al.get()));
25 | }
26 |
27 | public static void main(String[] args) {
28 | new Main().launch();
29 | }
30 |
31 | public void launch() {
32 | Console c = System.console();
33 | if (c == null) {
34 | System.err.println("No console.");
35 | System.exit(1);
36 | }
37 |
38 | c.printf("Welcome to the calculator CLI. ");
39 | Integer input1 = getValidInput(c, c.readLine("Enter your first input parameter: "));
40 |
41 | Algorithm algorithm = getAlgorithm(c);
42 |
43 | Integer input2 = getValidInput(c, c.readLine("Enter your second input parameter: "));
44 | c.format("The answer is: " + algorithm.calculate(input1, input2) + "\n");
45 | }
46 |
47 | private Integer getValidInput(Console c, String input) {
48 | Integer result = 0;
49 | boolean noValidInput;
50 | do {
51 | try {
52 | result = Integer.valueOf(input);
53 | noValidInput = false;
54 | } catch(NumberFormatException ex) {
55 | noValidInput = true;
56 | input = c.readLine("No valid number please try again: ");
57 | }
58 | } while (noValidInput);
59 | return result;
60 | }
61 |
62 | private Algorithm getAlgorithm(Console c) {
63 | final StringBuffer algorithmText = new StringBuffer("Please select which algorithm you want to use from the following list: ");
64 | algorithmMap.keySet().stream().forEach(aln -> {
65 | algorithmText.append(aln);
66 | algorithmText.append(", ");
67 | });
68 | algorithmText.append("\n");
69 | c.printf(algorithmText.toString());
70 |
71 | String algorithm;
72 | do {
73 | algorithm = c.readLine("Select the algorithm: " );
74 | } while(!algorithmMap.keySet().contains(algorithm));
75 | return algorithmMap.get(algorithm);
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/fd-java9-jigsaw-gui/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | fd-java9-jigsaw
7 | nl.frisodobber
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | fd-java9-jigsaw-gui
13 |
14 |
15 |
16 | nl.frisodobber
17 | fd-java9-jigsaw-algorithm-api
18 | ${project.version}
19 |
20 |
21 |
22 |
23 |
24 |
25 | org.apache.maven.plugins
26 | maven-jar-plugin
27 |
28 | ../libs
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/fd-java9-jigsaw-gui/src/main/java/module-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by dobber on 31-12-16.
3 | */
4 | module calculator.gui {
5 | exports nl.frisodobber.java9.jigsaw.calculator.gui to javafx.graphics;
6 |
7 | requires javafx.base;
8 | requires javafx.graphics;
9 | requires javafx.controls;
10 | requires calculator.algorithm.api;
11 | uses nl.frisodobber.java9.jigsaw.calculator.algorithm.api.Algorithm;
12 | }
13 |
--------------------------------------------------------------------------------
/fd-java9-jigsaw-gui/src/main/java/nl/frisodobber/java9/jigsaw/calculator/gui/Main.java:
--------------------------------------------------------------------------------
1 | package nl.frisodobber.java9.jigsaw.calculator.gui;
2 |
3 | import javafx.application.Application;
4 | import javafx.collections.FXCollections;
5 | import javafx.collections.ObservableList;
6 | import javafx.geometry.Insets;
7 | import javafx.geometry.Pos;
8 | import javafx.scene.Scene;
9 | import javafx.scene.control.*;
10 | import javafx.scene.layout.GridPane;
11 | import javafx.scene.layout.HBox;
12 | import javafx.scene.paint.Color;
13 | import javafx.scene.text.Font;
14 | import javafx.scene.text.FontWeight;
15 | import javafx.scene.text.Text;
16 | import javafx.stage.Stage;
17 | import javafx.util.StringConverter;
18 | import nl.frisodobber.java9.jigsaw.calculator.algorithm.api.Algorithm;
19 |
20 | import java.util.ServiceLoader;
21 |
22 | /**
23 | * Created by dobber on 5-1-17.
24 | */
25 | public class Main extends Application {
26 | private ServiceLoader algorithms;
27 |
28 | @Override
29 | public void init() {
30 | loadAlgorithms();
31 | }
32 |
33 | private void loadAlgorithms() {
34 | algorithms = ServiceLoader.load(Algorithm.class);
35 | }
36 |
37 | @Override
38 | public void start(Stage stage) throws Exception {
39 | stage.setTitle("Calculator");
40 |
41 | GridPane grid = new GridPane();
42 | grid.setAlignment(Pos.CENTER);
43 | grid.setHgap(10);
44 | grid.setVgap(10);
45 | grid.setPadding(new Insets(25, 25, 25, 25));
46 |
47 | Text scenetitle = new Text("Calculate");
48 | scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
49 | grid.add(scenetitle, 0, 0, 2, 1);
50 |
51 | Label input1Label = new Label("Input 1:");
52 | grid.add(input1Label, 0, 1);
53 |
54 | final TextField input1Field = new TextField();
55 | grid.add(input1Field, 1, 1);
56 |
57 | Label algorithmLabel = new Label("Algorithm");
58 | grid.add(algorithmLabel, 0, 2);
59 |
60 | ObservableList options = FXCollections.observableArrayList();
61 | algorithms.forEach(v -> {
62 | options.add(v);
63 | });
64 | final ComboBox comboBox = new ComboBox(options);
65 | grid.add(comboBox, 1, 2);
66 |
67 | // Define rendering of the list of values in ComboBox drop down.
68 | comboBox.setCellFactory((cb) -> {
69 | return new ListCell() {
70 | @Override
71 | protected void updateItem(Algorithm item, boolean empty) {
72 | super.updateItem(item, empty);
73 |
74 | if (item == null || empty) {
75 | setText(null);
76 | } else {
77 | setText(item.getClass().getSimpleName());
78 | }
79 | }
80 | };
81 | });
82 |
83 | // Define rendering of selected value shown in ComboBox.
84 | comboBox.setConverter(new StringConverter() {
85 | @Override
86 | public String toString(Algorithm al) {
87 | if (al == null) {
88 | return null;
89 | } else {
90 | return al.getClass().getSimpleName();
91 | }
92 | }
93 |
94 | @Override
95 | public Algorithm fromString(String alString) {
96 | return null; // No conversion fromString needed.
97 | }
98 | });
99 |
100 | Label input2Label = new Label("Input 2:");
101 | grid.add(input2Label, 0, 3);
102 |
103 | final TextField input2Field = new TextField();
104 | grid.add(input2Field, 1, 3);
105 |
106 | final Text actiontarget = new Text();
107 | grid.add(actiontarget, 1, 5);
108 |
109 | Button btn = new Button("Calculate");
110 | HBox hbBtn = new HBox(10);
111 | hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
112 | hbBtn.getChildren().add(btn);
113 | grid.add(hbBtn, 1, 4);
114 |
115 | btn.setOnAction((event) -> {
116 | Algorithm al = (Algorithm)comboBox.getValue();
117 | actiontarget.setFill(Color.FIREBRICK);
118 | Integer input1 = Integer.valueOf(input1Field.getText());
119 | Integer input2 = Integer.valueOf(input2Field.getText());
120 |
121 | actiontarget.setText(al.calculate(input1,input2).toString());
122 | });
123 |
124 | Scene scene = new Scene(grid, 300, 275);
125 | stage.setScene(scene);
126 | stage.show();
127 | }
128 |
129 | public static void main(String[] args) {
130 | launch(args);
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/java-commandos.txt:
--------------------------------------------------------------------------------
1 | #Switch the current execution version:
2 | sudo update-alternatives --config java
3 | #Switch the current compiler version:
4 | sudo update-alternatives --config javac
5 | #Install a new JDK for java execution
6 | sudo update-alternatives --install /usr/bin/java java /home/dobber/ide/jdk-9/bin/java 1
7 | #Install a new JDK for java compiler
8 | sudo update-alternatives --install /usr/bin/javac javac /home/dobber/ide/jdk-9/bin/javac 1
9 | #Run executable jar
10 | java -jar name-of-jar.jar
11 |
12 | #THIS DOESN'T WORK YET
13 | # Set JAVA_HOME on java 9:
14 | #Open /etc/environment with sudo gedit /etc/environment and add JAVA_HOME="path/to/jdk"
15 | source /etc/environment
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | nl.frisodobber
8 | fd-java9-jigsaw
9 | pom
10 | 1.0-SNAPSHOT
11 |
12 | fd-java9-jigsaw-algorithm-api
13 | fd-java9-jigsaw-algorithm-add
14 | fd-java9-jigsaw-algorithm-substract
15 | fd-java9-jigsaw-gui
16 | fd-java9-jigsaw-cli
17 |
18 |
19 |
20 | 1.9
21 | 1.9
22 | 9
23 |
24 |
25 |
26 |
27 |
28 |
29 | org.apache.maven.plugins
30 | maven-compiler-plugin
31 | 3.7.0
32 |
33 |
34 | org.apache.maven.plugins
35 | maven-jar-plugin
36 | 3.0.2
37 |
38 |
39 | org.apache.maven.plugins
40 | maven-toolchains-plugin
41 | 1.1
42 |
43 |
44 |
45 |
46 |
47 | org.apache.maven.plugins
48 | maven-compiler-plugin
49 |
50 |
51 | org.apache.maven.plugins
52 | maven-toolchains-plugin
53 |
54 |
55 |
56 | 1.9
57 | oracle
58 |
59 |
60 |
61 |
62 |
63 |
64 | toolchain
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------