JavaOne BOF: The Legacy Developer’s Guide to Java 9

Slides:



Advertisements
Similar presentations
Here’s what we see when we start a new BlueJ “Project”. BlueJ automatically creates a small “readme.txt” file to hold any directions we wish to write about.
Advertisements

XHTML Basics.
Programming with Android: SDK install and initial setup Luca Bedogni Marco Di Felice Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna.
Android: Hello World Frank Xu Gannon University. Steps Configuration ▫Android SDK ▫Android Development Tools (ADT)  Eclipse plug-in ▫Android SDK and.
26-Jun-15 Getting Ready for CIT Labs Lab is scheduled for 3;00-4:30 Fridays in Moore 207 Lab is not in Towne 309 (Registrar has it wrong) Everyone.
עיצוב תוכנה מונחה עצמים תירגול 1. 1.Packages and Paths 2.Jar Files Outline.
Android 4: Creating Contents Kirk Scott 1. Outline 4.1 Planning Contents 4.2 GIMP and Free Sound Recorder 4.3 Using FlashCardMaker to Create an XML File.
WDV 331 Dreamweaver Applications Templates Dreamweaver CS6 Chapter 19.
Introduction to Android. Android as a system, is a java based operating system that runs on the Linux kernel. The system is very lightweight and full.
Slide 1/8Jack IDE Tutorial, Index This program is part of the software suite that accompanies the book The Elements of Computing.
The Basics of Javadoc Presented By: Wes Toland. Outline  Overview  Background  Environment  Features Javadoc Comment Format Javadoc Program HTML API.
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
9/2/ CS171 -Math & Computer Science Department at Emory University.
CS 4720 Dynamic Web Applications CS 4720 – Web & Mobile Systems.
240-Current Research Easily Extensible Systems, Octave, Input Formats, SOA.
M1G Introduction to Programming 2 5. Completing the program.
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
Drill-Through Features Cognos 8 BI. Objectives  In this module we will examine:  Cognos 8 Drill Through Overview  Model / Package Drill Through  Cross.
Time to apply stuff… Faculty of Mathematics and Physics Charles University in Prague 5 th October 2015 Workshop 1 – Java Wrestling.
Learning Aim C.  In this section we will look at some simple client-side scripts, browser compatibility, exporting and compressing and suitable file.
Today Javadoc. Packages and static import. Viewing API source code. Upcoming Topics: –protected access modifier –Using the debugger in Eclipse –JUnit testing.
Text2PTO: Modernizing Patent Application Filing A Proposal for Submitting Text Applications to the USPTO.
Java 9 support in Eclipse Jay Arthanareeswaran, Manoj Palat IBM.
What type of project? I tried three type of project and the only one I managed to obtain the results I wanted was this one. It is more flexible and much.
Using FlexTraining.
Produce the help package
Dreamweaver – Setting up a Site and Page Layouts
JavaScript/ App Lab Programming:
Development Environment
Visit for more Learning Resources
EET 2259 Unit 4 SubVIs Read Bishop, Chapter 4.
Advanced Programing practices
Build Automation with Gradle
Before You Begin Nahla Abuel-ola /WIT.
Obtaining the Required Tools
XHTML Basics.
Introduction to Triggers
CSE 143 Error Handling [Section 2.8] 3/30/98 CSE 143.
Introduction Enosis Learning.
Algorithm and Ambiguity
Binary Tree and General Tree
Java 9.
Introduction Enosis Learning.
XHTML Basics.
Java 9 Project Jigsaw / JSR 376: JavaTM Platform Module System.
XHTML Basics.
Some Tips for Using Eclipse
Embracing Java 9 and beyond with Eclipse JDT
Packages and Interfaces
Fall 2018 CISC124 12/1/2018 CISC124 Note that the next assignment, on encapsulation, is due next Wednesday at 7pm – not Friday. The next Quiz is not until.
Electronics II Physics 3620 / 6620
CISC124 Assignment 4 on Inheritance due next Friday.
CISC124 Assignment 3 due tomorrow at 7pm.
CISC124 Assignment 4 on Inheritance due next Friday.
XHTML Basics.
CISC101 Reminders All assignments are now posted.
CMPE212 – Reminders Assignment 2 sample solution is posted.
Java IDE Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
Polymorphism 2019/4/29.
XHTML Basics.
Classes 5/5 May 14, 2019 ICS102: Classes 5/5.
Working with Libraries
CMPE212 – Reminders Assignment 2 due today, 7pm.
Review of Previous Lesson
David Cleverly – Development Lead
EET 2259 Unit 4 SubVIs Read Bishop, Chapter 4.
Lecture 26: Array Disjoint Sets
Outline Announcements: Version control with CVS HW II due today!
Presentation transcript:

JavaOne BOF: The Legacy Developer’s Guide to Java 9 Wayne Citrin CTO, JNBridge October 2017

Outline The agony of the legacy Java developer Java 9 and the legacy developer Multi-release JAR files Modules Jlink

The agony of the legacy Java developer Legacy Java developers are like the kids with their noses pressed up against the window of the candy store Attractive new APIs But the code needs to run on older JREs New non-API language constructs and JDK features Can’t be used when targeting older JREs Users might be using the new JRE, behavior could be different despite promised backward compatibility @ Iam Muttoo

Java 9 features that help the legacy developer Multi-release JAR files Modules Jlink

Multi-release JAR files Include code that will run against new JRE Use new features, APIs Also include code that will run against legacy JREs Appropriate code is always chosen

What we do now Use late binding – probe for desired APIs, use if available Tedious and error-prone

How multi-release JAR files work Create special nooks that can only be seen by specific versions of the JRE and that override previous versions Manifest file contains Multi-Release: true

How to create a multi-release JAR file Place your legacy code (Java 8 and earlier) in one folder hierarchy Place new Java 9-targeted code in another folder hierarchy Use new Java 9 jar.exe tool: jar cfe pid.jar -C legacyFolder . --release 9 -C java9Folder .

Module basics Modularized jar files: Contain module-info.class file Indicates what they expose to the outside world, who can read them, and what they require from elsewhere Ordinary jar files: Plain old jar files – no module-info.class file In addition to the class path, there is now a module path Can you use your old ordinary jar files in Java 9 alongside modularized jar files? Can your legacy ordinary jar files participate in the module system unchanged? Can a multi-release jar file be modularized when used in Java 9?

Using the classpath The classpath works the way it always has Modularized jar files in the classpath are treated like any other jar file If you’ve modularized one of your jar files, but aren’t ready to actually use the module system in your application, you can do it without consequence All the jar files in the classpath are considered part of a single unnamed module Exports everything to all other modules Can access all other modules If you have a modularized application, but have some old unmodularized modules, just put them in the classpath. It’ll just work!

Putting jar files in the module path Modularized jar files can be placed in the module path (modpath) Each is treated as a module, and the runtime enforces module rules and visibility What happens if you put an ordinary jar file in the modpath? Becomes an automatic module It’s name is the name of the jar file It exposes everything and accesses everything If you have a legacy jar file, can almost always add it directly to the modpath and it’ll just work Caveat: A package can only be part of one named module If a package appears in more than one jar file, only one of them can be made an automatic module. The rest must be left in the classpath and remain part of the unnamed module.

Can you use modularized jar files in Java 8 and earlier? It’s complicated To have a module-info.class, you need to be targeting Java 9 Means that you can’t use those JAR files on Java 8 Can we put module-info.class in the versioned section of a multi-release JAR? Yes! Modular multi-release jar files can have module-info.class in the versioned section, if: There’s no module-info.class in the root section (i.e., if you’re targeting Java 8), or There is a module-info.class in the root section, in which case they need to conform to certain similarity rules, but that’s irrelevant if you’re targeting pre-Java 9

Jlink: Automatically constructing private JREs Problem: Can we guarantee that the end user has the correct JRE to run your legacy application? What we do now: Create a private JRE and ship it with the application Instructions on creating a private JRE come in every JRE’s README file What files and folders must be included Which are optional What folder structure needs to be enforced Process is error-prone. If you make a mistake, it won’t work

How Jlink works Java 9’s Jlink tool automates the process The Java 9 runtime is itself modularized Given the modules in your application, Jlink figures out which runtime modules to include, too. Leaves the rest out. When invoking Jlink, supply the module path and the modules of your application, and it’ll include everything else you’ll need, and will package it in a folder hierarchy (the run-time image) Caveats: If your jar files are not modularized, Jlink will be forced to include everything. Still, it’s convenient to let Jlink worry about assembling the run-time image. Jlink is a Java 9 tool and only works with the modularized Java 9 JRE, so this really only supports legacy development and maintenance post-Java 9

Summary Java 9’s designers did think about how legacy Java developers might use Java 9 features and APIs These features let you ease into Java 9’s offerings, without breaking your legacy code, or having to rewrite things you’ve already written. Using these Java 9 features, your code should continue to run on older JREs, too! Multi-release jar files: You can include code for Java 9, and equivalent code for pre-Java 9, and your application will continue to work on all platforms. Module system: Modularize your jar files, or not. Put your jar files in the classpath, or put them in the module path. Things will just work, and they’ll continue to work in Java 8 and earlier. Of course, the more modularization you do, the more benefits you’ll get. Jlink: Starting with Java 9, you’ll easily be able to generate tailored run-time images so that your users will have exactly the JRE they need.

Discussion

Resources Overview: https://techbeacon.com/legacy-developers-guide-java-9 Multi-release JAR files: Spec: http://openjdk.java.net/jeps/238 Tutorial: https://www.voxxed.com/2016/11/java-9-series-multi-release-jar-files/ Modules: http://openjdk.java.net/projects/jigsaw/ https://jaxenter.com/java-9-modules-jpms-basics-135885.html Jlink: http://openjdk.java.net/jeps/220 and http://openjdk.java.net/jeps/282