Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nicolai Parlog
committed
Mar 22, 2017
1 parent
585045b
commit b9b99e4
Showing
4 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# `mavenrc` | ||
|
||
Maven can apparently be configured with the [mostly undocumented][jira-mavenrc-doc] files `~/.mavenrc` (for current user) and `/etc/mavenrc` (for all users). | ||
In there, environment variables and command line options for the Java command can be configured. | ||
|
||
With this, it is easy to set `JAVA_HOME` just for the Maven command, which will lead to it running with the specified version. | ||
Here's the content of that file: | ||
|
||
``` | ||
JAVA_HOME="/path/to/your/jdk-9" | ||
``` | ||
|
||
## Pros and Cons | ||
|
||
If you not only want to compile with Java 9 but also use Java 9 features, you still have to specify the target `1.9` in your [pom](pom.xml). | ||
Note that this puts the pom into an awkward state where it is supposed to use JDK 9 but does not reference where it might come from (unlike the [toolchain approach](../toolchain)) | ||
|
||
|
||
[jira-mavenrc-doc]: https://issues.apache.org/jira/browse/MNGSITE-246 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.codefx.demo.mvn-java-9</groupId> | ||
<artifactId>demo</artifactId> | ||
<version>java-9</version> | ||
|
||
<build> | ||
<plugins> | ||
<!-- target Java 9 --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.6.1</version> | ||
<configuration> | ||
<source>1.9</source> | ||
<target>1.9</target> | ||
<release>9</release> | ||
</configuration> | ||
</plugin> | ||
<!-- make resulting JAR executable --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.0.2</version> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<addClasspath>true</addClasspath> | ||
<mainClass>org.codefx.demo.mvn_java9.Main</mainClass> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.codefx.demo.mvn_java9; | ||
|
||
import static java.lang.StackWalker.Option.RETAIN_CLASS_REFERENCE; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
printCallerClass(); | ||
} | ||
|
||
private static void printCallerClass() { | ||
Class<?> callerClass = StackWalker | ||
.getInstance(RETAIN_CLASS_REFERENCE) | ||
.getCallerClass(); | ||
System.out.println(callerClass); | ||
} | ||
|
||
} |