Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Commit

Permalink
Add script to switch Java versions
Browse files Browse the repository at this point in the history
  • Loading branch information
nipa committed Jun 12, 2017
1 parent ac24791 commit e780b9e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -28,6 +28,8 @@ To run it on Java 9:
* [define `JAVA_HOME` in a `.mavenrc` file](https://github.com/CodeFX-org/mvn-java-9/tree/master/mavenrc), pointing to your Java 9 install
* in the `.mvn` folders, rename the non-empty files `jvm9.config` to `jvm.config`, which adds Java-9-specific command line flags required for the project

If you're on Linux, you can use the `switch-to-java` script.
Called with either `8` or `9` as parameter, it makes sure that the build runs on the appropriate version.

## Contribute!

Expand Down
34 changes: 34 additions & 0 deletions switch-to-java
@@ -0,0 +1,34 @@
#!/bin/bash

# Calling this script will make the build run on the entered Java version - it
# is called with either 8 or 9 as parameter.
#
# The assumption is that the system JDK is version 8 and that JDK 9 is
# installed somewhere as well. The script edits the ~/.mavenrc file to define
# the JAVA_HOME variable for Maven and makes sure that project-specific
# .mvn/jvm.config files are either present or not, depending on the version.

java_version=$1
# define the path to your Java 9 install here
java_9_path="/opt/jdk-9"

if [ $java_version -eq 8 ]; then
if [ -f ~/.mavenrc ]; then
sed -i -e 's/^JAVA_HOME/#JAVA_HOME/' ~/.mavenrc
fi
if [ -f $PWD/.mvn/jvm.config ]; then
mv -f $PWD/.mvn/jvm.config $PWD/.mvn/jvm9.config
fi
elif [ $java_version -eq 9 ]; then
if [ -f ~/.mavenrc ]; then
sed -i -e 's/^JAVA_HOME/#JAVA_HOME/' ~/.mavenrc
else
echo "JAVA_HOME=\"$java_9_path\"" >> ~/.mavenrc
fi
sed -i -e 's/#*JAVA_HOME/JAVA_HOME/' ~/.mavenrc
if [ -f $PWD/.mvn/jvm9.config ]; then
mv -f $PWD/.mvn/jvm9.config $PWD/.mvn/jvm.config
fi
else
echo "Unknown version $java_version - doing nothing"
fi

0 comments on commit e780b9e

Please sign in to comment.