Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot run program "/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/javac" #619

Closed
tribbloid opened this issue Jun 28, 2022 · 11 comments
Closed

Comments

@tribbloid
Copy link

When compiling, it cannot find the proper javac path:


[ERROR] Failed to execute goal net.alchim31.maven:scala-maven-plugin:4.6.3:testCompile (scala-test-compile-first) on project dp-utilities-mldsl: wrap: java.io.IOException: Cannot run program "/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/javac" (in directory "/home/peng/git/datapassports/dp-utilities"): error=2, No such file or directory -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal net.alchim31.maven:scala-maven-plugin:4.6.3:testCompile (scala-test-compile-first) on project dp-utilities-mldsl: wrap: java.io.IOException: Cannot run program "/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/javac" (in directory "/home/peng/git/datapassports/dp-utilities"): error=2, No such file or directory
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:190)
    at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:186)
    at java.util.concurrent.FutureTask.run (FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:511)
    at java.util.concurrent.FutureTask.run (FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
    at java.lang.Thread.run (Thread.java:748)
Caused by: org.apache.maven.plugin.MojoExecutionException: wrap: java.io.IOException: Cannot run program "/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/javac" (in directory "/home/peng/git/datapassports/dp-utilities"): error=2, No such file or directory
    at scala_maven.ScalaMojoSupport.execute (ScalaMojoSupport.java:316)
    at scala_maven.ScalaTestCompileMojo.execute (ScalaTestCompileMojo.java:51)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:190)
    at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:186)
    at java.util.concurrent.FutureTask.run (FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:511)
    at java.util.concurrent.FutureTask.run (FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
    at java.lang.Thread.run (Thread.java:748)
Caused by: java.io.IOException: Cannot run program "/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/javac" (in directory "/home/peng/git/datapassports/dp-utilities"): error=2, No such file or directory
    at java.lang.ProcessBuilder.start (ProcessBuilder.java:1048)
    at scala.sys.process.ProcessBuilderImpl$Simple.run (ProcessBuilderImpl.scala:85)
    at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.run (ProcessBuilderImpl.scala:119)
    at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.$anonfun$runBuffered$1 (ProcessBuilderImpl.scala:205)
    at scala.runtime.java8.JFunction0$mcI$sp.apply (JFunction0$mcI$sp.scala:17)
    at sbt.internal.inc.javac.JavacLogger.buffer (JavacProcessLogger.scala:49)
    at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.runBuffered (ProcessBuilderImpl.scala:205)
    at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.$bang (ProcessBuilderImpl.scala:146)
    at sbt.internal.inc.javac.ForkedJava$.$anonfun$launch$3 (ForkedJava.scala:55)
    at sbt.internal.inc.javac.ForkedJava$.$anonfun$launch$3$adapted (ForkedJava.scala:48)
    at sbt.internal.inc.javac.ForkedJava$.$anonfun$withArgumentFile$1 (ForkedJava.scala:77)
    at sbt.io.IO$.withTemporaryDirectory (IO.scala:490)
    at sbt.io.IO$.withTemporaryDirectory (IO.scala:500)
    at sbt.internal.inc.javac.ForkedJava$.withArgumentFile (ForkedJava.scala:74)
    at sbt.internal.inc.javac.ForkedJava$.launch (ForkedJava.scala:48)
    at sbt.internal.inc.javac.ForkedJavaCompiler.run (ForkedJava.scala:103)
    at sbt.internal.inc.javac.AnalyzingJavaCompiler.$anonfun$compile$12 (AnalyzingJavaCompiler.scala:172)
    at scala.runtime.java8.JFunction0$mcV$sp.apply (JFunction0$mcV$sp.scala:18)
    at sbt.internal.inc.javac.AnalyzingJavaCompiler.timed (AnalyzingJavaCompiler.scala:262)
    at sbt.internal.inc.javac.AnalyzingJavaCompiler.compile (AnalyzingJavaCompiler.scala:161)
    at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compileJava$2 (MixedAnalyzingCompiler.scala:103)
    at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compileJava$2$adapted (MixedAnalyzingCompiler.scala:91)
    at sbt.internal.inc.JarUtils$.withPreviousJar (JarUtils.scala:239)
    at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compileJava$1 (MixedAnalyzingCompiler.scala:91)
    at scala.runtime.java8.JFunction0$mcV$sp.apply (JFunction0$mcV$sp.scala:18)
    at sbt.internal.inc.MixedAnalyzingCompiler.timed (MixedAnalyzingCompiler.scala:247)
    at sbt.internal.inc.MixedAnalyzingCompiler.compileJava (MixedAnalyzingCompiler.scala:61)
    at sbt.internal.inc.MixedAnalyzingCompiler.compileJava0$1 (MixedAnalyzingCompiler.scala:197)
    at sbt.internal.inc.MixedAnalyzingCompiler.compile (MixedAnalyzingCompiler.scala:210)
    at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1 (IncrementalCompilerImpl.scala:528)
    at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted (IncrementalCompilerImpl.scala:528)
    at sbt.internal.inc.Incremental$.$anonfun$apply$5 (Incremental.scala:177)
    at sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted (Incremental.scala:175)
    at sbt.internal.inc.Incremental$$anon$2.run (Incremental.scala:461)
    at sbt.internal.inc.IncrementalCommon$CycleState.next (IncrementalCommon.scala:116)
    at sbt.internal.inc.IncrementalCommon$$anon$1.next (IncrementalCommon.scala:56)
    at sbt.internal.inc.IncrementalCommon$$anon$1.next (IncrementalCommon.scala:52)
    at sbt.internal.inc.IncrementalCommon.cycle (IncrementalCommon.scala:263)
    at sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8 (Incremental.scala:416)
    at sbt.internal.inc.Incremental$.withClassfileManager (Incremental.scala:503)
    at sbt.internal.inc.Incremental$.incrementalCompile (Incremental.scala:403)
    at sbt.internal.inc.Incremental$.apply (Incremental.scala:169)
    at sbt.internal.inc.IncrementalCompilerImpl.compileInternal (IncrementalCompilerImpl.scala:528)
    at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1 (IncrementalCompilerImpl.scala:482)
    at sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError (IncrementalCompilerImpl.scala:332)
    at sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally (IncrementalCompilerImpl.scala:420)
    at sbt.internal.inc.IncrementalCompilerImpl.compile (IncrementalCompilerImpl.scala:137)
    at sbt_inc.SbtIncrementalCompiler.compile (SbtIncrementalCompiler.java:186)
    at scala_maven.ScalaCompilerSupport.incrementalCompile (ScalaCompilerSupport.java:364)
    at scala_maven.ScalaCompilerSupport.compile (ScalaCompilerSupport.java:122)
    at scala_maven.ScalaCompilerSupport.doExecute (ScalaCompilerSupport.java:89)
    at scala_maven.ScalaMojoSupport.execute (ScalaMojoSupport.java:310)
    at scala_maven.ScalaTestCompileMojo.execute (ScalaTestCompileMojo.java:51)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:190)
    at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:186)
    at java.util.concurrent.FutureTask.run (FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:511)
    at java.util.concurrent.FutureTask.run (FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
    at java.lang.Thread.run (Thread.java:748)
Caused by: java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.forkAndExec (Native Method)
    at java.lang.UNIXProcess.<init> (UNIXProcess.java:247)
    at java.lang.ProcessImpl.start (ProcessImpl.java:134)
    at java.lang.ProcessBuilder.start (ProcessBuilder.java:1029)
    at scala.sys.process.ProcessBuilderImpl$Simple.run (ProcessBuilderImpl.scala:85)
    at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.run (ProcessBuilderImpl.scala:119)
    at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.$anonfun$runBuffered$1 (ProcessBuilderImpl.scala:205)
    at scala.runtime.java8.JFunction0$mcI$sp.apply (JFunction0$mcI$sp.scala:17)
    at sbt.internal.inc.javac.JavacLogger.buffer (JavacProcessLogger.scala:49)
    at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.runBuffered (ProcessBuilderImpl.scala:205)
    at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.$bang (ProcessBuilderImpl.scala:146)
    at sbt.internal.inc.javac.ForkedJava$.$anonfun$launch$3 (ForkedJava.scala:55)
    at sbt.internal.inc.javac.ForkedJava$.$anonfun$launch$3$adapted (ForkedJava.scala:48)
    at sbt.internal.inc.javac.ForkedJava$.$anonfun$withArgumentFile$1 (ForkedJava.scala:77)
    at sbt.io.IO$.withTemporaryDirectory (IO.scala:490)
    at sbt.io.IO$.withTemporaryDirectory (IO.scala:500)
    at sbt.internal.inc.javac.ForkedJava$.withArgumentFile (ForkedJava.scala:74)
    at sbt.internal.inc.javac.ForkedJava$.launch (ForkedJava.scala:48)
    at sbt.internal.inc.javac.ForkedJavaCompiler.run (ForkedJava.scala:103)
    at sbt.internal.inc.javac.AnalyzingJavaCompiler.$anonfun$compile$12 (AnalyzingJavaCompiler.scala:172)
    at scala.runtime.java8.JFunction0$mcV$sp.apply (JFunction0$mcV$sp.scala:18)
    at sbt.internal.inc.javac.AnalyzingJavaCompiler.timed (AnalyzingJavaCompiler.scala:262)
    at sbt.internal.inc.javac.AnalyzingJavaCompiler.compile (AnalyzingJavaCompiler.scala:161)
    at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compileJava$2 (MixedAnalyzingCompiler.scala:103)
    at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compileJava$2$adapted (MixedAnalyzingCompiler.scala:91)
    at sbt.internal.inc.JarUtils$.withPreviousJar (JarUtils.scala:239)
    at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compileJava$1 (MixedAnalyzingCompiler.scala:91)
    at scala.runtime.java8.JFunction0$mcV$sp.apply (JFunction0$mcV$sp.scala:18)
    at sbt.internal.inc.MixedAnalyzingCompiler.timed (MixedAnalyzingCompiler.scala:247)
    at sbt.internal.inc.MixedAnalyzingCompiler.compileJava (MixedAnalyzingCompiler.scala:61)
    at sbt.internal.inc.MixedAnalyzingCompiler.compileJava0$1 (MixedAnalyzingCompiler.scala:197)
    at sbt.internal.inc.MixedAnalyzingCompiler.compile (MixedAnalyzingCompiler.scala:210)
    at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1 (IncrementalCompilerImpl.scala:528)
    at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted (IncrementalCompilerImpl.scala:528)
    at sbt.internal.inc.Incremental$.$anonfun$apply$5 (Incremental.scala:177)
    at sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted (Incremental.scala:175)
    at sbt.internal.inc.Incremental$$anon$2.run (Incremental.scala:461)
    at sbt.internal.inc.IncrementalCommon$CycleState.next (IncrementalCommon.scala:116)
    at sbt.internal.inc.IncrementalCommon$$anon$1.next (IncrementalCommon.scala:56)
    at sbt.internal.inc.IncrementalCommon$$anon$1.next (IncrementalCommon.scala:52)
    at sbt.internal.inc.IncrementalCommon.cycle (IncrementalCommon.scala:263)
    at sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8 (Incremental.scala:416)
    at sbt.internal.inc.Incremental$.withClassfileManager (Incremental.scala:503)
    at sbt.internal.inc.Incremental$.incrementalCompile (Incremental.scala:403)
    at sbt.internal.inc.Incremental$.apply (Incremental.scala:169)
    at sbt.internal.inc.IncrementalCompilerImpl.compileInternal (IncrementalCompilerImpl.scala:528)
    at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1 (IncrementalCompilerImpl.scala:482)
    at sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError (IncrementalCompilerImpl.scala:332)
    at sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally (IncrementalCompilerImpl.scala:420)
    at sbt.internal.inc.IncrementalCompilerImpl.compile (IncrementalCompilerImpl.scala:137)
    at sbt_inc.SbtIncrementalCompiler.compile (SbtIncrementalCompiler.java:186)
    at scala_maven.ScalaCompilerSupport.incrementalCompile (ScalaCompilerSupport.java:364)
    at scala_maven.ScalaCompilerSupport.compile (ScalaCompilerSupport.java:122)
    at scala_maven.ScalaCompilerSupport.doExecute (ScalaCompilerSupport.java:89)
    at scala_maven.ScalaMojoSupport.execute (ScalaMojoSupport.java:310)
    at scala_maven.ScalaTestCompileMojo.execute (ScalaTestCompileMojo.java:51)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:190)
    at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:186)
    at java.util.concurrent.FutureTask.run (FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:511)
    at java.util.concurrent.FutureTask.run (FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
    at java.lang.Thread.run (Thread.java:748)
[ERROR] 
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command

@tribbloid
Copy link
Author

tribbloid commented Jun 28, 2022

This problem is triggered by the following maven config:

        <configuration>
          <scalaVersion>${scala.version}</scalaVersion>
          <scalaCompatVersion>${scala.binary.version}</scalaCompatVersion>
          <recompileMode>incremental</recompileMode>
          <args>
            <arg>-unchecked</arg>
            <arg>-deprecation</arg>
            <arg>-feature</arg>
            <arg>-g:vars</arg>
            <arg>-encoding</arg>
            <arg>UTF-8</arg>
            <arg>-Xlint</arg>
          </args>
          <javacArgs>
<!--            <javacArg>-source</javacArg>-->
<!--            <javacArg>${java.version}</javacArg>-->
<!--            <javacArg>-target</javacArg>-->
<!--            <javacArg>${java.version}</javacArg>-->
          </javacArgs>
        </configuration>

@slandelle
Copy link
Collaborator

Please provide a complete standalone reproducer like described in here, otherwise there's no way to help.
Also, make sure your linux user as execute permission on Java.

@roti
Copy link

roti commented Jul 11, 2022

Happened to me as well. The situation occurs when the environment variable JAVA_HOME does not exist, and maven uses the java executable from PATH. You can avoid it by setting JAVA_HOME.
This happens because the path detection for java in JavaLocator.findExecutableFromToolchain returns the JRE Path instead of JDK. This is wrong in my oppinion, it should be possible to detect the JDK if it is PATH.
In my tests the argument toolchain of JavaLocator.findExecutableFromToolchain was always null. Maybe that's the problem.

@slandelle
Copy link
Collaborator

Can't say what happens exactly on your setup.
What I can say for sure is that scalac works with a simple JRE but can only compile Scala code.
A JDK is required in order to compile Java code, which is what happens when you have a mixed project.

I'd say the issue if with your setup and you have to provide a proper JDK and note a simple JRE if you want to compile Java code too.

I'm closing for now. I'll reopen if someone finds an issue with the Java resolution and provides a reproducer.

@roti
Copy link

roti commented Jul 11, 2022

@slandelle yes, in my case I have Java sources as well. And I provide a JDK, not a JRE, but not in the environment variable JAVA_HOME, but in the PATH. In my oppionion it should work in this case as well.

@slandelle
Copy link
Collaborator

but in the PATH. In my oppionion it should work in this case as well.

Why? Why would it have precedence over the JVM that was used to launch maven?

@roti
Copy link

roti commented Jul 11, 2022

Because the JVM that was used to launch Maven is a JDK. It's the java executable from a JDK.
I will gladly provide a reproducer, if you tell me what your expectations are. A full project where the problem is repoduced?

@slandelle
Copy link
Collaborator

A full project where the problem is repoduced?

Yes

@roti
Copy link

roti commented Jul 11, 2022

Here you go. To reproduce the error:

  • make sure a java JDK is in the Path, in my case it's c:\Program Files\Eclipse Adoptium\jdk-8.0.312.7-hotspot\bin\
  • make sure JAVA_HOME is not defined
  • run mvn clean compile
    => following error occurs:
[INFO] compiling 1 Scala source and 1 Java source to D:\scala-test-prj\target\classes ...
[WARNING] javac exited with exit code -1
[ERROR] ## Exception when compiling 2 sources to D:\scala-test-prj\target\classes
java.io.IOException: Cannot run program "C:\Program Files\Eclipse Adoptium\jdk-8.0.312.7-hotspot\jre\bin\javac" (in directory "D:\scala-test-prj"): CreateProcess error=2, The system cannot find the file specified
java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
scala.sys.process.ProcessBuilderImpl$Simple.run(ProcessBuilderImpl.scala:85)
scala.sys.process.ProcessBuilderImpl$AbstractBuilder.run(ProcessBuilderImpl.scala:119)
scala.sys.process.ProcessBuilderImpl$AbstractBuilder.$anonfun$runBuffered$1(ProcessBuilderImpl.scala:205)
scala.runtime.java8.JFunction0$mcI$sp.apply(JFunction0$mcI$sp.scala:17)
sbt.internal.inc.javac.JavacLogger.buffer(JavacProcessLogger.scala:49)
scala.sys.process.ProcessBuilderImpl$AbstractBuilder.runBuffered(ProcessBuilderImpl.scala:205)
scala.sys.process.ProcessBuilderImpl$AbstractBuilder.$bang(ProcessBuilderImpl.scala:146)
sbt.internal.inc.javac.ForkedJava$.$anonfun$launch$3(ForkedJava.scala:55)
sbt.internal.inc.javac.ForkedJava$.$anonfun$launch$3$adapted(ForkedJava.scala:48)
sbt.internal.inc.javac.ForkedJava$.$anonfun$withArgumentFile$1(ForkedJava.scala:77)
sbt.io.IO$.withTemporaryDirectory(IO.scala:490)
sbt.io.IO$.withTemporaryDirectory(IO.scala:500)
sbt.internal.inc.javac.ForkedJava$.withArgumentFile(ForkedJava.scala:74)
sbt.internal.inc.javac.ForkedJava$.launch(ForkedJava.scala:48)
sbt.internal.inc.javac.ForkedJavaCompiler.run(ForkedJava.scala:103)
sbt.internal.inc.javac.AnalyzingJavaCompiler.$anonfun$compile$12(AnalyzingJavaCompiler.scala:172)
scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
sbt.internal.inc.javac.AnalyzingJavaCompiler.timed(AnalyzingJavaCompiler.scala:262)
sbt.internal.inc.javac.AnalyzingJavaCompiler.compile(AnalyzingJavaCompiler.scala:161)
sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compileJava$2(MixedAnalyzingCompiler.scala:103)
sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compileJava$2$adapted(MixedAnalyzingCompiler.scala:91)
sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239)
sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compileJava$1(MixedAnalyzingCompiler.scala:91)
scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:247)
sbt.internal.inc.MixedAnalyzingCompiler.compileJava(MixedAnalyzingCompiler.scala:61)
sbt.internal.inc.MixedAnalyzingCompiler.compileJava0$1(MixedAnalyzingCompiler.scala:197)
sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:210)
sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:528)
sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:528)
sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:177)
sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:175)
sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:461)
sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116)
sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56)
sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52)
sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:263)
sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:416)
sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:503)
sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:403)
sbt.internal.inc.Incremental$.apply(Incremental.scala:169)
sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:528)
sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:482)
sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:420)
sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
sbt_inc.SbtIncrementalCompiler.compile(SbtIncrementalCompiler.java:186)
scala_maven.ScalaCompilerSupport.incrementalCompile(ScalaCompilerSupport.java:364)
scala_maven.ScalaCompilerSupport.compile(ScalaCompilerSupport.java:122)
scala_maven.ScalaCompilerSupport.doExecute(ScalaCompilerSupport.java:89)
scala_maven.ScalaMojoSupport.execute(ScalaMojoSupport.java:310)
scala_maven.ScalaCompileMojo.execute(ScalaCompileMojo.java:108)
org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  11.779 s
[INFO] Finished at: 2022-07-11T15:14:37+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal net.alchim31.maven:scala-maven-plugin:4.6.3:compile (default-compile) on project scala-test-prj: wrap: java.io.IOException: Cannot run program "C:\Program Files\Eclipse Adoptium\jdk-8.0.312.7-hotspot\jre\bin\javac" (in directory "D:\scala-test-prj"): CreateProcess error=2, The system cannot find the file specified -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

scala-test-prj.zip

@slandelle slandelle reopened this Jul 15, 2022
@slandelle
Copy link
Collaborator

This is a Windows specific error and I don't have a Windows machine.

@roti Could you please provide me with the full content layout of your c:\Program Files\Eclipse Adoptium\jdk-8.0.312.7-hotspot?

@roti
Copy link

roti commented Jul 15, 2022

@slandelle It's the JDK from the Temurin Project: https://adoptium.net/temurin/releases/?version=8
I listed the files and folders in the attached file.
jdk_files.txt

slandelle added a commit that referenced this issue Jul 15, 2022
Motivation:

1. We should prefer the Java installation used to run maven to what's defined in JAVA_HOME
2. We should prefer JDK over JRE (for old versions that used to have one) as we need javac for compiling Java code in mixed projects

Modifications:

Resolve with the following chain:
* prefer toolchain if defined
* try to use "java.home" System prop to resolve a JDK, a JRE otherwise
* fall back to JAVA_HOME env var

Result:

Behavior consistent with `maven-compiler-plugin` and `org.codehaus.plexus.compiler.javac.JavacCompiler#getJavacExecutable`.

In particular:
* we no longer unexpectedly jump to a different Java install because JAVA_HOME env var is defined
* we no longer crash on Java 8 when trying to compile mixed projects and JAVA_HOME env var is undefined or doesn't point to a JDK.
slandelle added a commit that referenced this issue Jul 17, 2022
Motivation:

1. We should prefer the Java installation used to run maven to what's defined in JAVA_HOME
2. We should prefer JDK over JRE (for old versions that used to have one) as we need javac for compiling Java code in mixed projects

Modifications:

Resolve with the following chain:
* prefer toolchain if defined
* try to use "java.home" System prop to resolve a JDK, a JRE otherwise
* fall back to JAVA_HOME env var

Result:

Behavior consistent with `maven-compiler-plugin` and `org.codehaus.plexus.compiler.javac.JavacCompiler#getJavacExecutable`.

In particular:
* we no longer unexpectedly jump to a different Java install because JAVA_HOME env var is defined
* we no longer crash on Java 8 when trying to compile mixed projects and JAVA_HOME env var is undefined or doesn't point to a JDK.
slandelle added a commit to gatling/gatling-maven-plugin that referenced this issue Jul 18, 2022
Motivation:

gatling-maven-plugin and the bundle have to locate the java executable in order to spawn a forked process to run Gatling.
The current strategy is broken:
* it favors the JAVA_HOME env var over the launcher's JVM
* if JAVA_HOME is undefined and Java 8 is used, it will pick the JRE instead of the JDK, causing crashes when compiling Java code

This is the same issue as davidB/scala-maven-plugin#619

Modification:

* Share Java location resolution is commons module.
* Favor current JVM over JAVA_HOME
* Favor JDK over JRE
slandelle added a commit to gatling/gatling-maven-plugin that referenced this issue Jul 18, 2022
Motivation:

gatling-maven-plugin and the bundle have to locate the java executable in order to spawn a forked process to run Gatling.
The current strategy is broken:
* it favors the JAVA_HOME env var over the launcher's JVM
* if JAVA_HOME is undefined and Java 8 is used, it will pick the JRE instead of the JDK, causing crashes when compiling Java code

This is the same issue as davidB/scala-maven-plugin#619

Modification:

* Share Java location resolution is commons module.
* Favor current JVM over JAVA_HOME
* Favor JDK over JRE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants