Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Honor the JAVA_HOME environment variable in nbexec script#8725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
matthiasblaesing merged 1 commit intoapache:masterfromstoty:issue8724
Aug 25, 2025

Conversation

@stoty
Copy link
Contributor

@stotystoty commentedAug 11, 2025
edited by matthiasblaesing
Loading

The current code ignores JAVA_HOME.

This patch honors the JAVA_HOME environment variable, then falls back the original java detection code.

The original code does not work jenv style shims.

@mbienmbien added Platform[ci] enable platform tests (platform/*) os:linux labelsAug 11, 2025
Copy link
Contributor

@matthiasblaesingmatthiasblaesing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This breaks the NetBeans IDE launcher. When no JAVA_HOME is set the IDE does not start anymore. I'm on Ubuntu 25.04 and I build this branch. Running the build gives me:

matthias@enterprise:~/src/netbeans$export LANG=Cmatthias@enterprise:~/src/netbeans$ rm -rf xmatthias@enterprise:~/src/netbeans$ nbbuild/netbeans/bin/netbeans --userdir x --cachedir x/home/matthias/src/netbeans/nbbuild/netbeans/platform/lib/nbexec: line 438: /home/matthias/src/netbeans/bin/java: No such file or directorymatthias@enterprise:~/src/netbeans$

@stoty
Copy link
ContributorAuthor

What happens in that case without the patch@matthiasblaesing ?

If you check the patch, it falls back to the original code in the else branch when neither env var is specified.

I've just realized that the patch will also consider /bin/java if JAVA_HOME is not set, but your ouput shows a different directory.

Copy link
Member

@neilcsmith-netneilcsmith-net left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'm in two minds whether this is a good move. NetBeans and the platform have not beenJAVA_HOME aware by default in the past, which might make this an unexpected change. On the other hand, it brings it in line with recent changes in the Windows launcher. Of course, that was broken before so not quite the same thing!

We should probably ignoreJDK_HOME to keep in line with the new Windows launcher behaviour?

TheNBPackage script setsJAVA_HOME for the DEB and RPM packages, although there shouldn't be any effect here if this is ignored withjdkhome set. I think there's a reverse to consider here too - whetherJAVA_HOME should then always be set to thejdkhome value for the execution of the IDE / platform application?

jdkhome=`dirname$java`"/.."
fi
*)
if ["x"!="x${JAVA_HOME}"-a-x"${JAVA_HOME}/bin/java" ];then

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Isn't-a effectively deprecated in favour of multiple tests with&& ?

It might be enough to check for-n "${JAVA_HOME} ? There's a test with-x below.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

-a is used in this same script elsewhere, but I'm not particular about the implementation details.
I'm not confident in shell programming, so I just copy what already see used.

I was wondering how to handle the empty JAVA_HOME.
I thought that "" is probably an error, if someone puts the JDK it in the root directory, they should use "/" instead.

But again, it's fine either way for me.

If you have a strong preference, LMK and I will change it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Ah, OK, leave-a (if theand is required at all). I'd missed that it was used elsewhere - we should rethink them all at some point.

And emptyJAVA_HOME should surely be treated the same as unset. In fact, not sure how easily we could check the difference in all cases. I still think a check forJAVA_HOME being non-zero length without the additional-x check would be enough here anyway. I'm not sure an invalidJAVA_HOME should just be ignored.

Will let others comment on that.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Ah, OK, leave-a (if theand is required at all). I'd missed that it was used elsewhere - we should rethink them all at some point.

And emptyJAVA_HOME should surely be treated the same as unset. In fact, not sure how easily we could check the difference in all cases.

The"x" != "x${JAVA_HOME}" idiom is used quite frequently, it is only true if the variable is set and is not zero length.

I still think a check forJAVA_HOME being non-zero length without the additional-x check would be enough here anyway. I'm not sure an invalidJAVA_HOME should just be ignored.

The rest of the java detection code checks to see if a java executable is present, I copied that.

But I see your point, if JAVA_HOME is set incorrectly, it makes sense to just fail instead of ignoring it.
I'm fine with it either way.

Will let others comment on that.

Copy link
Member

@neilcsmith-netneilcsmith-netAug 19, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The"x" != "x${JAVA_HOME}" idiom is used quite frequently, it is only true if the variable is set and is not zero length.

Sure, and as I understand it the historic form of-n. Mind you, again checking the rest of this file for consistency, we seem to use the pattern[ ! -z "${JAVA_HOME}" ] elsewhere in it.

The rest of the java detection code checks to see if a java executable is present, I copied that.

Yes, and if you let it fall through it should hit that check and exit.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

replaced= with! -z

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Removed the extra executable check.

@stoty
Copy link
ContributorAuthor

I'm in two minds whether this is a good move. NetBeans and the platform have not beenJAVA_HOME aware by default in the past, which might make this an unexpected change. On the other hand, it brings it in line with recent changes in the Windows launcher. Of course, that was broken before so not quite the same thing!

I saw JDK_HOME being used, that was probably the VisualVM Windows launcher code, not the NetBeans one.

We should probably ignoreJDK_HOME to keep in line with the new Windows launcher behaviour?

Sure, will remove.

TheNBPackage script setsJAVA_HOME for the DEB and RPM packages, although there shouldn't be any effect here if this is ignored withjdkhome set. I think there's a reverse to consider here too - whetherJAVA_HOME should then always be set to thejdkhome value for the execution of the IDE / platform application?

I don't think that's really necessary.

The only time JAVA_HOME would come up is when NetBeans is starting a new JDK,

If it is started directly case NB would use one of the configured JDK instances.
In the indirect case (i.e. NB starts a shell script or C code which starts a JDK) it may be sometimes useful, but IMO it's better to be transparent and not try to second guess the user's evironment setup.

@neilcsmith-net
Copy link
Member

I saw JDK_HOME being used, that was probably the VisualVM Windows launcher code, not the NetBeans one.

Maybe. I don't know why they use a fork of that but not this.

I think there's a reverse to consider here too - whetherJAVA_HOME should then always be set to thejdkhome value for the execution of the IDE / platform application?

I don't think that's really necessary.

The only time JAVA_HOME would come up is when NetBeans is starting a new JDK,

Just a related thought to this. It's set conservatively when unset by the user in the DEB and RPM. I find it very useful to ensure that the terminal, etc. in the IDE has JAVA_HOME set to the JDK the IDE is running on.

Thanks for the changes. Let's see if anyone else has any comments, and that@matthiasblaesing issue is resolved.

jdkhome=`dirname$java`"/.."
fi
*)
if [!-z"x${JAVA_HOME}" ];then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What is the idea here? This can't work and in fact does not. If JAVA_HOME is not set, this evaluates:

  • ! -z "x${JAVA_HOME}"
  • ! -z "x"
  • ! false
  • true

And with any other value this is the same as the zero length check will only ever check a longer path.

Let me repeat the test setup:

  • noJAVA_HOME set
  • java and javac on thePATH
  • build from PR and run in base directory:nbbuild/netbeans/bin/netbeans --userdir x --cachedir x (ensure, that directory x does not exist prior)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Sorry, forgot to remove the x

neilcsmith-net reacted with thumbs up emoji
Copy link
Contributor

@matthiasblaesingmatthiasblaesing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Works for me and looks sane. Thank you.

Please squash the changes into a single commit to prepare for merge.

jdkhome=`dirname$java`"/.."
fi
*)
if [!-z"${JAVA_HOME}" ];then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I don't know enough about how NetBeans handles multiple Java enviroments to comment on whether that's a good idea.

In some IDEs the Java that runs the IDE is independent from the Java(s) used for the projects.

IMO such a change would better be done from the Java side, as this patch only touches the non-Apple Unix path, and the java code would be a common path instead of threeseparate ones (MacOS, generic unix, Windows)

@stoty
Copy link
ContributorAuthor

Works for me and looks sane. Thank you.

Please squash the changes into a single commit to prepare for merge.

Thank you, done.

@matthiasblaesingmatthiasblaesing changed the titleHonor the JAVA_HOME and JDK_HOME environment variables in nbexec scriptHonor the JAVA_HOME environment variable in nbexec scriptAug 25, 2025
@matthiasblaesingmatthiasblaesing added this to theNB28 milestoneAug 25, 2025
@matthiasblaesingmatthiasblaesing merged commit5abc89b intoapache:masterAug 25, 2025
32 checks passed
@matthiasblaesing
Copy link
Contributor

@stoty thank you. I adjusted the head message and title of this PR to reflect the final state and merged.

@stoty
Copy link
ContributorAuthor

Thank you@matthiasblaesing .

matthiasblaesing reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@jtulachjtulachjtulach left review comments

@neilcsmith-netneilcsmith-netneilcsmith-net left review comments

@matthiasblaesingmatthiasblaesingmatthiasblaesing approved these changes

Assignees

No one assigned

Labels

os:linuxPlatform[ci] enable platform tests (platform/*)

Projects

None yet

Milestone

NB28

Development

Successfully merging this pull request may close these issues.

Honor the JAVA_HOME and JDK_HOME environment variables in nbexec script

5 participants

@stoty@neilcsmith-net@matthiasblaesing@jtulach@mbien

[8]ページ先頭

©2009-2025 Movatter.jp