apache / apache/maven-mvnd

Problem when running in Cygwin with an existed env variable “JAVA_HOME”.

Open
#619 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
3.5k
Forks
250
Avg merge
16h 22m
Merged PRs (30d)
36

Description

This problem seems like #156 but has a little difference.

I'm using SDKMAN installed JDK and mvnd.
So Here's a env variable `JAVA_HOME` managed by Cygwin.

```
~ » echo $JAVA_HOME

/home/Bennie/.sdkman/candidates/java/current
```

The problem is that an error output when checkout mvnd version:

```
~ » mvnd -v
mvnd native client 0.7.1-windows-amd64 (97c587c11383a67b5bd0ff8388bd94c694b91c1e)
Terminal: org.jline.terminal.impl.jansi.win.JansiWinSysTerminal
Exception in thread "main" java.lang.RuntimeException: Could not get a real path from path \home\Bennie\.sdkman\candidates\java\current
at org.mvndaemon.mvnd.client.DaemonParameters.javaHome(DaemonParameters.java:144)
at org.mvndaemon.mvnd.client.DaemonConnector.connect(DaemonConnector.java:99)
at org.mvndaemon.mvnd.client.DefaultClient.execute(DefaultClient.java:272)
at org.mvndaemon.mvnd.client.DefaultClient.main(DefaultClient.java:118)
```

I'm trying to solve the problem as the below as description.

## Configure java.home manually
I'm trying `mvnd -v` agin after edit `java.home` in the `conf/mvnd.properties` with following:
```
java.home=/home/Bennie/.sdkman/candidates/java/8.0.322-tem
```

Still got the same error output before.

## Unset JAVA_HOME

After read the #156 I find out maybe the @gnodet doesn't have a `JAVA_HOME` in Cygwin itself which just copied from Windows one.

Thus I unset the JAVA_HOME and ran `mvnd -v` agin.

```
~ » unset JAVA_HOME
~ » mvnd -v
mvnd native client 0.7.1-windows-amd64 (97c587c11383a67b5bd0ff8388bd94c694b91c1e)
Terminal: org.jline.terminal.impl.jansi.win.JansiWinSysTerminal
Exception in thread "main" java.lang.RuntimeException: Could not get a real path from path \home\Bennie\.sdkman\candidates\java\8.0.322-tem
at org.mvndaemon.mvnd.client.DaemonParameters.javaHome(DaemonParameters.java:144)
at org.mvndaemon.mvnd.client.DaemonConnector.connect(DaemonConnector.java:99)
at org.mvndaemon.mvnd.client.DefaultClient.execute(DefaultClient.java:272)
at org.mvndaemon.mvnd.client.DefaultClient.main(DefaultClient.java:118)
```

This time the `java.home` path point to the configured one. Verified that the `unset JAVA_HOME` operation is valid.
But the problem still does what it does.

## Adjust path

I checked out the #156 bug-fix details. Found out the `java.home` path start with `\cygdrive\`, So edit `java.home` in the `conf/mvnd.properties` again.

Then It's just worked.

```
java.home=/cygdrive/d/Tools/cygwin/home/Bennie/.sdkman/candidates/java/8.0.322-tem

~ » mvnd -v

mvnd native client 0.7.1-windows-amd64 (97c587c11383a67b5bd0ff8388bd94c694b91c1e)
Terminal: org.jline.terminal.impl.jansi.win.JansiWinSysTerminal
Apache Maven 3.8.3 (ff8e977a158738155dc465c6a97ffaf31982d739)
Maven home: D:\Tools\cygwin\home\Bennie\.sdkman\candidates\mvnd\0.7.1\mvn
Java version: 1.8.0_322, vendor: Temurin, runtime: D:\Tools\cygwin\home\Bennie\.sdkman\candidates\java\8.0.322-tem\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
```

## Finally
Is there any good ways to solve this.
This is may be a bug? due to the `java.home` property override by `$JAVA_HOME`.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with DaemonParameters.javaHome, where the stack trace reports the path failure, and compare the JAVA_HOME environment value with java.home in conf/mvnd.properties. Reproduce mvnd -v under Cygwin with JAVA_HOME set and unset, then verify that the resulting Windows path works without requiring a manually edited /cygdrive path.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.