Skip to content

Commit 28e7076

Browse files
committed
Adding blog post on creating multi-release JARs with Java 9
1 parent 5591262 commit 28e7076

File tree

6 files changed

+172
-0
lines changed

6 files changed

+172
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ This repository contains demos used live during presentations; The following dem
1313
* _osgi_: tutorials demonstrating all possible ORM OSGi configurations
1414
* Hibernate OGM
1515
* _hiking-demo_: Demo project used for the talk "Hibernate OGM: Talking to NoSQL in Red Hat JBoss EAP" presented at Red Hat Summit 2014. It shows how to use MongoDB as data store in a Java EE application through JPA / Hibernate OGM.
16+
* Hibernate Search
17+
* _hsearch-with-elasticsearch_: Shows how to use the Elasticsearch backend new in Hibernate Search 5.6.
18+
Used for the talk "From Hibernate to Elasticsearch in no Time" at JavaZone 2016.
19+
* Java 9
20+
* multi-release-jar-demo: Shows how to build multi-release JARs with Java 9.
21+
Accompanies the blog post http://in.relation.to/2017/02/13/building-multi-release-jars-with-maven/
1622

1723
## License
1824

java9/multi-release-jar-demo/pom.xml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<!--
2+
License: Apache License, Version 2.0
3+
See the LICENSE file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
4+
-->
5+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
7+
>
8+
<modelVersion>4.0.0</modelVersion>
9+
10+
<groupId>org.hibernate.demos</groupId>
11+
<artifactId>multi-release-jar-demo</artifactId>
12+
<version>1.0-SNAPSHOT</version>
13+
<packaging>jar</packaging>
14+
15+
<name>multi-release-jar-demo</name>
16+
<url>http://hibernate.org/</url>
17+
18+
<properties>
19+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
20+
<maven.compiler.source>1.8</maven.compiler.source>
21+
<maven.compiler.target>1.8</maven.compiler.target>
22+
<java9.sourceDirectory>${project.basedir}/src/main/java9</java9.sourceDirectory>
23+
<java9.build.outputDirectory>${project.build.directory}/classes-java9</java9.build.outputDirectory>
24+
</properties>
25+
26+
<build>
27+
<plugins>
28+
<plugin>
29+
<groupId>org.apache.maven.plugins</groupId>
30+
<artifactId>maven-antrun-plugin</artifactId>
31+
<version>1.8</version>
32+
<executions>
33+
<execution>
34+
<id>compile-java9</id>
35+
<phase>compile</phase>
36+
<configuration>
37+
<tasks>
38+
<mkdir dir="${java9.build.outputDirectory}" />
39+
<javac srcdir="${java9.sourceDirectory}" destdir="${java9.build.outputDirectory}"
40+
classpath="${project.build.outputDirectory}" includeantruntime="false" />
41+
</tasks>
42+
</configuration>
43+
<goals>
44+
<goal>run</goal>
45+
</goals>
46+
</execution>
47+
</executions>
48+
</plugin>
49+
<plugin>
50+
<groupId>org.apache.maven.plugins</groupId>
51+
<artifactId>maven-resources-plugin</artifactId>
52+
<version>3.0.2</version>
53+
<executions>
54+
<execution>
55+
<id>copy-resources</id>
56+
<phase>prepare-package</phase>
57+
<goals>
58+
<goal>copy-resources</goal>
59+
</goals>
60+
<configuration>
61+
<outputDirectory>${project.build.outputDirectory}/META-INF/versions/9</outputDirectory>
62+
<resources>
63+
<resource>
64+
<directory>${java9.build.outputDirectory}</directory>
65+
</resource>
66+
</resources>
67+
</configuration>
68+
</execution>
69+
</executions>
70+
</plugin>
71+
<plugin>
72+
<groupId>org.apache.maven.plugins</groupId>
73+
<artifactId>maven-jar-plugin</artifactId>
74+
<version>3.0.2</version>
75+
<configuration>
76+
<archive>
77+
<manifestEntries>
78+
<Multi-Release>true</Multi-Release>
79+
<Main-Class>org.hibernate.demos.mrjar.Main</Main-Class>
80+
</manifestEntries>
81+
</archive>
82+
<finalName>mr-jar-demo</finalName>
83+
</configuration>
84+
</plugin>
85+
</plugins>
86+
</build>
87+
</project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* License: Apache License, Version 2.0
3+
* See the LICENSE file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
4+
*/
5+
package org.hibernate.demos.mrjar;
6+
7+
public class Main {
8+
9+
public static void main(String[] args) {
10+
ProcessIdDescriptor pid = new ProcessIdProvider().getPid();
11+
12+
System.out.println( "PID: " + pid.getPid() );
13+
System.out.println( "Provider: " + pid.getProviderName() );
14+
}
15+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* License: Apache License, Version 2.0
3+
* See the LICENSE file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
4+
*/
5+
package org.hibernate.demos.mrjar;
6+
7+
/**
8+
* @author Gunnar Morling
9+
*/
10+
public class ProcessIdDescriptor {
11+
12+
private final long pid;
13+
private final String providerName;
14+
15+
public ProcessIdDescriptor(long pid, String providerName) {
16+
this.pid = pid;
17+
this.providerName = providerName;
18+
}
19+
20+
public long getPid() {
21+
return pid;
22+
}
23+
24+
public String getProviderName() {
25+
return providerName;
26+
}
27+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* License: Apache License, Version 2.0
3+
* See the LICENSE file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
4+
*/
5+
package org.hibernate.demos.mrjar;
6+
7+
import java.lang.management.ManagementFactory;
8+
9+
/**
10+
* @author Gunnar Morling
11+
*/
12+
public class ProcessIdProvider {
13+
14+
public ProcessIdDescriptor getPid() {
15+
String vmName = ManagementFactory.getRuntimeMXBean().getName();
16+
long pid = Long.parseLong( vmName.split( "@" )[0] );
17+
return new ProcessIdDescriptor( pid, "RuntimeMXBean" );
18+
}
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* License: Apache License, Version 2.0
3+
* See the LICENSE file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
4+
*/
5+
package org.hibernate.demos.mrjar;
6+
7+
import java.lang.ProcessHandle;
8+
9+
/**
10+
* @author Gunnar Morling
11+
*/
12+
public class ProcessIdProvider {
13+
14+
public ProcessIdDescriptor getPid() {
15+
long pid = ProcessHandle.current().getPid();
16+
return new ProcessIdDescriptor( pid, "ProcessHandle" );
17+
}
18+
}

0 commit comments

Comments
 (0)