[ 
https://issues.apache.org/jira/browse/NETBEANS-4595?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17467291#comment-17467291
 ] 

Thomas Schapitz commented on NETBEANS-4595:
-------------------------------------------

> The problem actually has nothing to do with JAVA_HOME.

Yes, you got that right. As I hinted above, the exec plugin is looking for the 
executable within the OSes system path, unless it has been given an absolute 
path spec to it - which you didn't, when you passed: 
-Dexec.executable=java
> The user just click the "Run" button. It is the Netbeans calls the the maven 
> exec plugin without setting the java executable the user expects. 

Actually, it's not, at the very least, not directly - the maven-exec-plugin is 
invoked as part of a maven lifecycle within maven as a container, even if you 
invoke it as a single goal for which there are two options, as mvn exec:help 
shows:

exec:exec
  A Plugin for executing external programs.

exec:help
  Display help information on exec-maven-plugin.
  Call mvn exec:help -Ddetail=true -Dgoal=<goal-name> to display parameter
  details.

exec:java
  Executes the supplied java class in the current VM with the enclosing
  project's dependencies as classpath.

 

Unfortunately from your post, it is not obvious which one you are using, since 
the goal is missing from the above output, and there is no explicit declaration 
within your pom. (There should be, maven best practices recommend to at least 
declare the version used). I suspect, it is the first one, but as we will see, 
it doesn't matter, since the second one probably wouldn't be better either in 
this case.

mvn exec.exec will pick the executable from the system path. It's not even 
aware, that it is invoking a JVM, for all it knows it might be starting firefox 
or xcopy.

The other one is mvn exec:java.In this case, its shouldn't even be necessary to 
specify the excutable, as the plugin will pick the same executable, that is 
used for the execution of maven. But: as the very first line of your output 
states:
cd /home/.../myproject; JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
... this is highly likely Java-8.

So your problem results partly from the fact, that you are not running *maven* 
with the proper JDK.

There are a number of ways to remedy that:

You may, within Netbeans, using Tools -> Options -> Tab Java -> Tab Maven -> 
Control "Default JDK" select  a global Default for the Netbeans IDE.

You may write a .mavenrc file, in order to set a local default for all maven 
executions, even those outside of netbeans. You may achieve the same thing by 
editing the maven wrapper scripts in your maven home. Note, that this might 
anihilate your possibiltes to influence that from within netbeans. Also note, 
that you need to check, which maven home is actually the one, you use.

And finally you might change it for every project, by selecting it in the 
project properties build -> compile -> Java Plattform. (*Not* Sources! This 
fixes the Source Level, which _might_ be lower)

One of those approaches should solve your problem.

If you still have difficulties, I suggest, that you post a complete run of your 
command, possibly also using -X (maven debug). It would also be interesting to 
know, how you are actually compling and starting your project (which 
menu/command are you using)

 

> exec-maven-plugin Java version different from maven-compiler-plugin Java 
> version in NetBeans project
> ----------------------------------------------------------------------------------------------------
>
>                 Key: NETBEANS-4595
>                 URL: https://issues.apache.org/jira/browse/NETBEANS-4595
>             Project: NetBeans
>          Issue Type: Bug
>          Components: projects - Maven
>    Affects Versions: 12.0, 12.4
>         Environment: Windows 7, Ubuntu 20.04
>            Reporter: Bernard
>            Priority: Critical
>         Attachments: testcase.zip
>
>
> I start up the NetBeans IDE 12.0 with a system environment JAVA_HOME (1.8) 
> lower than what the IDE uses (14).
> In the project properties, I have set the Build|Compile|Java Platform to JDK 
> 14 (Default) as expected.
> The IDE output window of Maven execution seems to show that the project is 
> run with JAVA_HOME for JDK 14, running project files this way.
> But the exec-maven-plugin fails with java.lang.UnsupportedClassVersionError: 
> com/mycompany/Start has been compiled by a more recent version of the Java 
> Runtime (class file version 55.0), this version of the Java Runtime only 
> recognizes class file versions up to 52.0
> This seems to indicate that the the exec-maven plugin runs under 1.8 in the 
> IDE, ignoring the IDE's own override setting of JAVA_HOME of 14. It appears 
> to use the JDK as set in JAVA_HOME, because if I set JAVA_HOME to 14.0 before 
> IDE startup then it works.
> I am looking for the correct way, the right places, to set the JDK for any 
> project specifically, regardless of the JAVA_HOME setting that is active when 
> the IDE starts.
> My case can be reproduced by running the IDE 12.0 with JDK 14.0 installed, 
> but with JAVA_HOME set to 1.8. before IDE startup. I use the Maven project 
> generated from the command at https://wicket.apache.org/start/quickstart.html 
> - all set to defaults. The file to run is Start.java.
> This is important to me because I must open many different projects with 
> different JDKs so it is not practical to re-start the IDE with different 
> JAVA_HOME settings each time. As it is, it appears that my setting is poorly 
> defined - I must be missing something.
> I know that there are potentially other solutions in maven like the 
> Toolchains plugin. However, with all of that, I would lose IDE support which 
> is letting the project properties dialog drive the JDK in use for everything. 
> Plus I can already see that the IDE aims to do the right thing by overriding 
> JAVA_HOME - for some reason this does not seem to be working and I think that 
> this might be the bug.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to