JavaOne – Project Jigsaw – Integration with Tools

“Project Jigsaw – Integration with Tools”

Speaker: Alexandru Jecan (author of Java 9 Modularity Revealed)

For more blog posts from JavaOne, see the table of contents


What expect build tools and IDEs to do

  • Code completion (IDEs only)
  • Make things easier
  • Work with class path and module path

Maven

  • Only Maven 3+ supports Java 9.
  • No changes to Maven core to run on Java 9
  • presence of module-info.java decides if Maven uses module path
  • Need Maven compiler plugin 3.6.1 to compile Java 9 code
  • Discourages using automatic module name
  • GAV not related to module name. Continue to use GAV.
  • Use module name in module-info.java – double work
  • Maven does not generate “requires” clauses for module-info.java
  • Can add <compilerArgs> options for -add-modules or -add-exports
  • New tag <release> which takes precedence over source/target tags. Recomended compiling twice or backward compatbility. once for java 9 modules and once for java 8. [why? isn’t that what multi release ars are for?]
  • maven-exec-plugin – can configure module path
  • taked abut updating maven toolchain file [not clear how this differs than prior versions of java]
  • maven-jdeps-plugin – can automatically generate module descriptor [but said earlier couldn’t]
  • maven-jmod-plugin – new plugin; not yet released. Creates and lists content of jmod files. Merge native code into jar
  • maven-jlink-plugin – new plugin; not yet released. Creates runtime images
  • maven-depdendency-plugin – said lists GAV [not clear how changed

Gradle
No first class support for Java 9 yet. Coming soon. [but said using; puzled?]

Ant
Ant 1.9.8+ support JDK 9 modules for java/javac/junit. [yet Ant doesn’t support JUnit 5]

Loom

  • New build tool for Java 9
  • Uses YAML config. Uses Maaven repo.
  • Supports JUnit 5,

loom.builders

Moditect
Maven plugin that generates module-info.java based on dependencies. Says helps a little but doesn’t do all the work. [how?]

SonarJava
SonarJava 4.11+ recognizes module keywords

Graphviz
Open source visualization software
Reads jdeps input to generate graphical representation of Jigsaw. As can IDES

IDEs

  • NetBeans, Eclipse and IntelliJ all understand modules clauses [if you count pre-release versions]
  • Also offer autocompletion, syntax higlighting, etc
  • NetBeans 9 – not yet released; must build yourself. Showed editing module path, visual of module dependencies, jshell, jlink
  • Eclipse Oxygen with Java 9 support – came out 9/27/17. Ten second demo
  • IntelliJ 2017.1+ – Mark directory as source root so directory name matches module name. Errors on common module errors, Showed module editing, module dependencies and other features

Open source readiness

How to modularize your app

  • Introduce modue-info.java by creating manually or running jdeps to generate
  • Problems: using JDK internal APIs (ignore warning or fix), using odule not availalbe such as xml bindings (add-modules at compile and runtime), cyclic dependencies (can have at runtime but not compile time), split packages (Oracle plans to make change in later version of Java to deal with this)
  • [Note: He recommended renaming packags as a solution to spit packages. That sounds like a horrible idea unless you can guarantee only you call that code]

    My take before session: You know how they say that first impressions matter? The speaker is wearing a suit. 90% of the people in the room are wearing jeans. Two people in the room are wearing a suit The speaker and someone he knows. Then he showed the table of contents. There are 29 points in 45 minutes in the outline. Preparing to have my head spin!

    My take after session: He is in fact technical. The suit was misleading! The pace was way too fast though; drinking from a fire hose. Not enough time to understand/process many of the points. He talks fast (as do I), but key is to *pause* if you talk fast so people can catch up. Also the side transitions were distracting. A cube transition is cute. But if you are reading when it moves, it is disorienting. And due to the speed, there was a good chance of being reading when transitions started. This was good information, but should have been two sessions so split up and a decent pace. And omiting how to migrate your libraries; that’s a talk on its own There is a Maven BOF tonight; maybe folks can discuss more then!

    One minute after the official end time, he asked if there were questions. My head was spinning with questions. [I didn’t even have time to process which was most important]. Another attendee asked if having JUnit tests in a parallel directory with the same package name is a split package. The speaker said yes and went on to say to wait for Java 10 or rename. I interjected at that point. Unless you are distributing a test jar, I don’t think this is a problem. In fact, most IDEs compile both the /src/main/java and /test/main/java directories to the same folder. I stated this and asked the speaker if he agreed. He said yes.

getting started with the Finch in NetBeans

This year the robotics team is using The Finch for teaching the new programmers about programming.  The robot is cute and I know I’d want to play with it so I bought one too.

While I like Eclipse better than NetBeans, the programming team uses NetBeans.  I decided to try out NetBeans with the Finch so I’m familiar with their platform/interface.  I’ll want it soon enough anyway to check out NetBeans projects from git.

Step 1 – Install NetBeans on the Mac

  1. Download NetBeans – the basic JSE edition
  2. Open dmg file which allows you to choose to run the installer.
  3. Choose defaults and install
  4. When first launch NetBeans asks if want to install JUnit.  (not clear on why JUnit doesn’t come with NetBeans – it comes with Eclipse)
Step 2 – Import Finch project
This one took me a few minutes.  You need to
  1. Download the NetBeans project
  2. Copy it to the NetBeans project directory which is /Users/me/NetBeansProjects on a mac
  3. In NetBeans, File > “open project” and then drill down to Finch.
Step 3 – Run a program
  1. Connect the Finch’s USB to your computer.  (The tutorial doesn’t say this, but it is implied.)
  2. Per the tutorial, choose Run > Run File.
  3. Enjoy the Finch.  It’s so cute!
Step 4 – Run a different programs
I very carefully misunderstood the instructions about not choosing Run > Run and did it anyway.  Luckily, you can choose Run > Run File and have it ignore your preset default.  Or you can completely unset it by editing the file FinchBeans/nbproject/project.properties and removing the main class line.  Then I can remember to choose Run > Run File.

Lightweight application development – the server side java symposium

This session is a live demo of developing an app quickly. Kind of like the Ruby on Rails “see i can develop an app in 15 minutes so long as it fits my extremely fitting scenario”. It was an informative and humorous/domain specific (casino) example. And I was pleasantly surprised that it didn’t trivialize the amount of work required. It was obviously a hello world type example and not intended you have a complete application in an hour. And the humor made it a great way to end the day.

The demo uses NetBeans because the speaker doesn’t want to install plugins, jab at Eclipse.

Since this was largely demo, comments are light, but here are some points:

  • Recommends using CDI instead of managed beans
  • Noted larger projects take a few seconds to rebuild/redeploy via maven
  • The interceptors and beans look so much like Spring and just as easy. I[ don’t see why you would switch back to ejb and know oracle plans to stay behind the curve]
  • Have a bean.xml even if empty so server doesn’t need to scan the whole project, just the cdi jars
  • I like that he included a custom annotation
  • In jee, an ejb can be a restful service
  • Avoids interfaces, only uses when really variation [what about testing?]

The speaker feels you should use Spring with an older JEE technology, but not JEE 6 because redundant. [you would still be deploying to jee 6 even if you aren’t using it though]