Making applications created with old Java versions work on Java 9 and later versions
Tags: java, tutorial, adapter, programming
Published: 2020-12-15 12:28:18

With [**Burningwave Tools**](https://burningwave.github.io/tools/) it is possible to perform dependencies shrinking and also to make applications created with old java versions work on java 9 and later versions.
To include Burningwave Tools in our project you need to add the following dependency to your pom.xml: 

{% gist https://gist.github.com/Roberto-Gentili/e7eeaa80443d27985be8563d3e0fb561.js %}

To adapt applications to java 9 and later you must **create an application adapater and run it with a jdk 9 or later**. In this application adapter you must load, by using PathHelper, the jdk libraries by which the target application was developed and pass to the method **captureAndStore** of **TwoPassCapturer** component, as first parameter, the name of the class of your application that contains the main method. In the example below we adapt a Java 8 Spring Boot application to Java 9 or later.

```java
ComponentSupplier componentSupplier = ComponentContainer.getInstance();
PathHelper pathHelper = componentSupplier.getPathHelper();
Collection<String> paths = pathHelper.getAllMainClassPaths();
if (JVMInfo.getVersion() > 8) {
    paths.addAll(pathHelper.getPaths("dependencies-capturer.additional-resources-path"));
}
List<String> _paths = new ArrayList<>(paths);
Collections.sort(_paths);
Result result = TwoPassCapturer.getInstance().captureAndStore(
    //Here you indicate the main class of your application
    "com.springbootappadapter.SpringBootWebApplication",
    args,
    paths,
    //Here you indicate the destination path where extracted
    //classes and resources will be stored  
    System.getProperty("user.home") + "/Desktop/dependencies",
    true,
    //Here you indicate the waiting time after the main of your
    //application has been executed. This is useful, for example, 
    //for spring boot applications to make it possible, once started,
    //to run rest methods to continue extracting the dependencies
    0L
);
result.waitForTaskEnding();
```

After prepared the dependencies adapter you need to run it: at the end of the execution **you will find in the destination folder a system executable** (a .cmd file under windows and a .sh file under unix) **with which it will be possible to test the extracted dependencies**:

![extracted dependencies folder](https://dev-to-uploads.s3.amazonaws.com/i/5k7pq7pufksdkncq8hmy.png)


We learned how to adapt a Java application to Java 9 and later versions and you can download/clone the tutorial shared [**here on GitHub**] (https://github.com/JJBRT/advanced-java-tutorials/tree/master/spring-boot-application-adapter): to make it works you need:
* to set the property '**paths.jdk-home**' of [**burningwave.properties**](https://github.com/JJBRT/advanced-java-tutorials/blob/master/spring-boot-application-adapter/src/test/resources/burningwave.properties#L1) file with a jdk 8 home
* to run with a jdk 9 or later the [**DependenciesAdapter**](https://github.com/JJBRT/advanced-java-tutorials/blob/master/spring-boot-application-adapter/src/test/java/org/springbootappadapter/DependenciesAdapter.java)

**For further assistance you can [open a discussion on GitHub](https://github.com/burningwave/tools/discussions) or you can ask on [Stack Overflow](https://stackoverflow.com/search?q=burningwave)**.

##### Special thanks to [**Jim Jerald Burton**](https://github.com/JJBRT) for maintaining the source code of this tutorial.