You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@netbeans.apache.org by Patrik Karlström <pa...@trixon.se> on 2022/08/18 18:00:51 UTC

Re: Run File - LinkageError/UnsupportedClassVersionError

Den lör 7 maj 2022 kl 18:04 skrev Patrik Karlström <pa...@trixon.se>:

> I can't remember if this ever worked for me,
> but I have a problem using Run/File (Shift F6) on main classes within a
> platform module if the source/target level is greater than 11, with or
> without nbjavac.
>
> It works just fine for non platform projects.
>
> cd /home/patrik/git/slask/nbrunfile/nbrunfile-sample;
> JAVA_HOME=/home/patrik/.sdkman/candidates/java/18.0.1-tem
> M2_HOME=/home/patrik/.sdkman/candidates/maven/current
> /home/patrik/.sdkman/candidates/maven/current/bin/mvn -f
> /home/patrik/git/slask/nbrunfile/nbrunfile-sample/pom.xml -Dexec.vmArgs=
> "-Dexec.args=${exec.vmArgs} -classpath %classpath ${exec.mainClass}
> ${exec.appArgs}" -Dexec.executable=java
> -Dexec.mainClass=se.trixon.nbrunfile.RunFileMain
> -Dexec.classpathScope=runtime -DskipTests=true -Dexec.appArgs= --debug
> --errors --debug --errors process-classes
> org.codehaus.mojo:exec-maven-plugin:3.0.0:exec
> Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
> Maven home: /home/patrik/.sdkman/candidates/maven/current
> Java version: 18.0.1, vendor: Eclipse Adoptium, runtime:
> /mnt/atlas/data-config/.sdkman/candidates/java/18.0.1-tem
> Default locale: sv_SE, platform encoding: UTF-8
> OS name: "linux", version: "5.10.0-14-amd64", arch: "amd64", family: "unix"
>   Included
> /snap/netbeans/61/netbeans/java/maven-nblib/netbeans-eventspy.jar
> ....
> Executing command line: [java, -classpath,
> /home/patrik/git/slask/nbrunfile/nbrunfile-sample/target/classes:/home/patrik/.m2/repository/org/netbeans/api/org-netbeans-api-annotations-common/RELEASE130/org-netbeans-api-annotations-common-RELEASE130.jar,
> se.trixon.nbrunfile.RunFileMain]
> Fel: LinkageError inträffade vid laddning av huvudklassen
> se.trixon.nbrunfile.RunFileMain
> java.lang.UnsupportedClassVersionError: se/trixon/nbrunfile/RunFileMain
> has been compiled by a more recent version of the Java Runtime (class file
> version 62.0), this version of the Java Runtime only recognizes class file
> versions up to 55.0
> Command execution failed.
>
> If I do run exec:java manually from a shell it works fine.
>
> I managed to track down
> https://github.com/apache/netbeans/blob/master/java/maven/src/org/netbeans/modules/maven/execute/defaultActionMappings.xml
> but I'm not sure where to go from there.
>
> As a side note it looks like global execution options get duplicated too. --debug
> --errors --debug --errors
>
> I have this problem on Windows too.
>
> /Patrik
>



I decided to try this with nb15-rc4 and it's even worse now as far as I can
tell.
With nb15 I'm even unable to do this with source/target<12, and that worked
in nb14.

But it fails with a new error message. "File or directory does not exist"
(translated)

cd /mnt/atlas/data/git/slask/nbrunfile/nbrunfile-sample;
JAVA_HOME=/home/pata/.sdkman/candidates/java/18.0.2.fx-zulu
M2_HOME=/home/pata/.sdkman/candidates/maven/current
/home/pata/.sdkman/candidates/maven/current/bin/mvn -Dexec.vmArgs=
"-Dexec.args=${exec.vmArgs} -classpath %classpath ${exec.mainClass}
${exec.appArgs}" -Dexec.executable=java
-Dexec.mainClass=se.trixon.nbrunfile.RunFileMain
-Dexec.classpathScope=runtime -DskipTests=true -Dexec.appArgs=
process-classes org.codehaus.mojo:exec-maven-plugin:3.0.0:exec
Scanning for projects...

---------------------< se.trixon:nbrunfile-sample >---------------------
Building nbrunfile-sample 0.0.1-SNAPSHOT
--------------------------------[ nbm ]---------------------------------

--- maven-resources-plugin:3.2.0:resources (default-resources) @
nbrunfile-sample ---
Using 'UTF-8' encoding to copy filtered resources.
Using 'UTF-8' encoding to copy filtered properties files.
Copying 1 resource

--- maven-compiler-plugin:3.10.1:compile (default-compile) @
nbrunfile-sample ---
Nothing to compile - all classes are up to date

--- nbm-maven-plugin:4.7:manifest (default-manifest) @ nbrunfile-sample ---
NBM Plugin generates manifest

--- exec-maven-plugin:3.0.0:exec (default-cli) @ nbrunfile-sample ---
Command execution failed.
java.io.IOException: Cannot run program "java" (in directory
"/mnt/atlas/data/git/slask/nbrunfile/nbrunfile-sample"): error=2, Filen
eller katalogen finns inte
    at java.lang.ProcessBuilder.start (ProcessBuilder.java:1143)
    at java.lang.ProcessBuilder.start (ProcessBuilder.java:1073)
    at java.lang.Runtime.exec (Runtime.java:615)
    at org.apache.commons.exec.launcher.Java13CommandLauncher.exec
(Java13CommandLauncher.java:61)

Re: Run File - LinkageError/UnsupportedClassVersionError

Posted by Eric Bresie <eb...@gmail.com>.
I suspect you have multiple java's coming in to play (1) the JDK compiled,
and the (2) Java Runtime Environment which may conflict.  In general you
can't run something compiled with a newer version without a little effort
in some cases.  So if you have a version with some new features not yet
supported, then the old one can't necessarily support that.

May want to check the PATH, JAVA_HOME, "java --version", and possibly the
netbeans\etc\netbean.conf jdk_home variable to see if there are some
conflicting versions installed.

When you do mvn --version it should also list what java it's leveraging.
It's possible the maven may be trying to run with one version even though a
newer version is also present on the system.

Eric

Eric Bresie
ebresie@gmail.com


On Sat, Aug 27, 2022 at 1:15 PM Patrik Karlström <pa...@trixon.se> wrote:

> Den sön 21 aug. 2022 kl 20:13 skrev Eric Bresie <eb...@gmail.com>:
>
> > One of the errors mentions trying to run an app compiled on a newer
> version
> > (18) while running with an older JRE (11).
> >
> > See https://javaalmanac.io/bytecode/versions/
> >
> > Have you cleaned and build with current JDK and JRE?
> >
>
> Yes, it's built from scratch with a current jdk.
>
>
>
> > Is your maven using the correct JDK?
> >
>
> It sure looks that way when I check the first line in netbeans output
> window when trying to run a file.
>

Re: Run File - LinkageError/UnsupportedClassVersionError

Posted by Patrik Karlström <pa...@trixon.se>.
Den sön 21 aug. 2022 kl 20:13 skrev Eric Bresie <eb...@gmail.com>:

> One of the errors mentions trying to run an app compiled on a newer version
> (18) while running with an older JRE (11).
>
> See https://javaalmanac.io/bytecode/versions/
>
> Have you cleaned and build with current JDK and JRE?
>

Yes, it's built from scratch with a current jdk.



> Is your maven using the correct JDK?
>

It sure looks that way when I check the first line in netbeans output
window when trying to run a file.

Re: Run File - LinkageError/UnsupportedClassVersionError

Posted by Eric Bresie <eb...@gmail.com>.
One of the errors mentions trying to run an app compiled on a newer version
(18) while running with an older JRE (11).

> se.trixon.nbrunfile.RunFileMain
> java.lang.UnsupportedClassVersionError: se/trixon/nbrunfile/RunFileMain
> has been compiled by a more recent version of the Java Runtime (class file
> version 62.0), this version of the Java Runtime only recognizes class file
> versions up to 55.0

See https://javaalmanac.io/bytecode/versions/

Have you cleaned and build with current JDK and JRE?

Is your maven using the correct JDK?

Eric

On Thu, Aug 18, 2022 at 1:01 PM Patrik Karlström <pa...@trixon.se> wrote:

> Den lör 7 maj 2022 kl 18:04 skrev Patrik Karlström <pa...@trixon.se>:
>
> > I can't remember if this ever worked for me,
> > but I have a problem using Run/File (Shift F6) on main classes within a
> > platform module if the source/target level is greater than 11, with or
> > without nbjavac.
> >
> > It works just fine for non platform projects.
> >
> > cd /home/patrik/git/slask/nbrunfile/nbrunfile-sample;
> > JAVA_HOME=/home/patrik/.sdkman/candidates/java/18.0.1-tem
> > M2_HOME=/home/patrik/.sdkman/candidates/maven/current
> > /home/patrik/.sdkman/candidates/maven/current/bin/mvn -f
> > /home/patrik/git/slask/nbrunfile/nbrunfile-sample/pom.xml -Dexec.vmArgs=
> > "-Dexec.args=${exec.vmArgs} -classpath %classpath ${exec.mainClass}
> > ${exec.appArgs}" -Dexec.executable=java
> > -Dexec.mainClass=se.trixon.nbrunfile.RunFileMain
> > -Dexec.classpathScope=runtime -DskipTests=true -Dexec.appArgs= --debug
> > --errors --debug --errors process-classes
> > org.codehaus.mojo:exec-maven-plugin:3.0.0:exec
> > Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
> > Maven home: /home/patrik/.sdkman/candidates/maven/current
> > Java version: 18.0.1, vendor: Eclipse Adoptium, runtime:
> > /mnt/atlas/data-config/.sdkman/candidates/java/18.0.1-tem
> > Default locale: sv_SE, platform encoding: UTF-8
> > OS name: "linux", version: "5.10.0-14-amd64", arch: "amd64", family:
> "unix"
> >   Included
> > /snap/netbeans/61/netbeans/java/maven-nblib/netbeans-eventspy.jar
> > ....
> > Executing command line: [java, -classpath,
> >
> /home/patrik/git/slask/nbrunfile/nbrunfile-sample/target/classes:/home/patrik/.m2/repository/org/netbeans/api/org-netbeans-api-annotations-common/RELEASE130/org-netbeans-api-annotations-common-RELEASE130.jar,
> > se.trixon.nbrunfile.RunFileMain]
> > Fel: LinkageError inträffade vid laddning av huvudklassen
> > se.trixon.nbrunfile.RunFileMain
> > java.lang.UnsupportedClassVersionError: se/trixon/nbrunfile/RunFileMain
> > has been compiled by a more recent version of the Java Runtime (class
> file
> > version 62.0), this version of the Java Runtime only recognizes class
> file
> > versions up to 55.0
> > Command execution failed.
> >
> > If I do run exec:java manually from a shell it works fine.
> >
> > I managed to track down
> >
> https://github.com/apache/netbeans/blob/master/java/maven/src/org/netbeans/modules/maven/execute/defaultActionMappings.xml
> > but I'm not sure where to go from there.
> >
> > As a side note it looks like global execution options get duplicated
> too. --debug
> > --errors --debug --errors
> >
> > I have this problem on Windows too.
> >
> > /Patrik
> >
>
>
>
> I decided to try this with nb15-rc4 and it's even worse now as far as I can
> tell.
> With nb15 I'm even unable to do this with source/target<12, and that worked
> in nb14.
>
> But it fails with a new error message. "File or directory does not exist"
> (translated)
>
> cd /mnt/atlas/data/git/slask/nbrunfile/nbrunfile-sample;
> JAVA_HOME=/home/pata/.sdkman/candidates/java/18.0.2.fx-zulu
> M2_HOME=/home/pata/.sdkman/candidates/maven/current
> /home/pata/.sdkman/candidates/maven/current/bin/mvn -Dexec.vmArgs=
> "-Dexec.args=${exec.vmArgs} -classpath %classpath ${exec.mainClass}
> ${exec.appArgs}" -Dexec.executable=java
> -Dexec.mainClass=se.trixon.nbrunfile.RunFileMain
> -Dexec.classpathScope=runtime -DskipTests=true -Dexec.appArgs=
> process-classes org.codehaus.mojo:exec-maven-plugin:3.0.0:exec
> Scanning for projects...
>
> ---------------------< se.trixon:nbrunfile-sample >---------------------
> Building nbrunfile-sample 0.0.1-SNAPSHOT
> --------------------------------[ nbm ]---------------------------------
>
> --- maven-resources-plugin:3.2.0:resources (default-resources) @
> nbrunfile-sample ---
> Using 'UTF-8' encoding to copy filtered resources.
> Using 'UTF-8' encoding to copy filtered properties files.
> Copying 1 resource
>
> --- maven-compiler-plugin:3.10.1:compile (default-compile) @
> nbrunfile-sample ---
> Nothing to compile - all classes are up to date
>
> --- nbm-maven-plugin:4.7:manifest (default-manifest) @ nbrunfile-sample ---
> NBM Plugin generates manifest
>
> --- exec-maven-plugin:3.0.0:exec (default-cli) @ nbrunfile-sample ---
> Command execution failed.
> java.io.IOException: Cannot run program "java" (in directory
> "/mnt/atlas/data/git/slask/nbrunfile/nbrunfile-sample"): error=2, Filen
> eller katalogen finns inte
>     at java.lang.ProcessBuilder.start (ProcessBuilder.java:1143)
>     at java.lang.ProcessBuilder.start (ProcessBuilder.java:1073)
>     at java.lang.Runtime.exec (Runtime.java:615)
>     at org.apache.commons.exec.launcher.Java13CommandLauncher.exec
> (Java13CommandLauncher.java:61)
>
-- 
Eric Bresie
ebresie@gmail.com