UnsupportedClassVersionError deploying EJB "HelloWord" in Glasshfish 3 - eclipse

I try to deploy a simple "Hello Word" in my local server GlasshFish 3, but at the deploy the console print this message
[#|2013-01-15T15:00:02.458+0100|SEVERE|glassfish3.1.2|
javax.enterprise.system.tools.admin.org.Exception while deploying the app
[HelloWorldEJB] :UnsupportedClassVersionError: Class ejb_other.PlaceAuctionItemBean
as unsupported major or minor version numbers, which are greater than those found
in the Java Runtime Environment version 1.6.0_27|#]
My JAVA_HOME has java version 1.6.0_27 (it refers to _C:\Program Files\Java\jdk1.6.0_27_), my Eclipse (indigo) project refers to java 1.6.0_27.
I think (i don't know how to verify) that GlasshFish refers to JAVA_HOME.
In my PC (Windows 7) I found 2 directory having java.exe:
C:\Windows\SysWOW64>java -version -->>java version "1.6.0_29"
C:\Windows\System32>java -version -->>java version "1.6.0_27"
I found more discussions about this exception (f.e. this or this ), but I need of something more specific for Eclipse/Glasshfish, because I can't to solve. I see that the JVM is the same for compilation and execution.
Post Scriptim
I add the screenshot about the places where I declare JVM: it's always 1.6.
one:
two:
three:
Where can I see that I compile with java 7 or it runs with another JVM?

ejb_other.PlaceAuctionItemBean was obviously compiled for Java 7 which won't work if you run it in a Java 6 JVM.

Found solution
There's another place where setting the compiler's options:
how do I get eclipse to use a different compiler version for Java?

Related

Scala not builds on Java 10

while building through Intellij Idea, I got the following message:
Error:scalac: 'jvm-1.10' is not a valid choice for '-target'
Error:scalac: bad option: '-target:jvm-1.10'
later, after a Java upgrade
Build, Execution, Deployment -> Build Tools -> Gradle -> Gradle JVM:
1.8 Build, Execution, Deployment -> Complier -> Scala Complier -> Scala Compile Server -> JDK: 1.8
in build.gradle
compileScala.targetCompatibility = 1.8
ScalaCompileOptions.metaClass.useAnt = false
Nothing helps!
upd:
this helps: in build.gradle
tasks.withType(ScalaCompile) {
scalaCompileOptions.useAnt = false
}
not needed:
compileScala.targetCompatibility = 1.8
ScalaCompileOptions.metaClass.useAnt = false
"Error:scalac: 'jvm-1.10' is not a valid choice for '-target' Error:scalac: bad option: '-target:jvm-1.10'"
In the JDK compatibility notes as mentioned below, it also indicates
that the Java 10 is not fully supporting Scala 2.12.6 JDK 9 & 10
compatibility notes
As you were saying you build this through IntelliJ IDEA, I suspect
you haven't configure your java version (Java 10) or scala version
(2.12.6) inside running configuration project settings.
And also please try out building/compile your application through
commandline in order to check whether you are getting the same error
with that (Otherwise this is just bad configuration in IDEA tht you
need to change)
JDK 9 & 10 compatibility notes (Mentioned in Scala Docs)
JDK 9 & 10 compatibility notes
As of Scala 2.12.6 and 2.11.12, JDK 9 & 10 support is incomplete. Notably, scalac will not enforce the restrictions of the Java Platform Module System, which means that code that typechecks may incur linkage errors at runtime.
JDK 9 & 10 support requires minimum sbt version 1.1.0, or 0.13.17 in the 0.13.x series.
For more information on JDK 9 & 10 compatibility, watch the “Support JDK 9” issue on GitHub.
The same issue can happen with mixed multi-module gradle projects that use java 11 and scala 2.12.10.
In that case, it may help to reconfigure IntelliJ (2019.2) via
Settings > Build, Execution, Deployment > Scala Compiler
by removing the targets defined in Additional compiler options for the affected scala modules.
I stumbled over this issue when having the same problem with Java 11. The reconfiguration comment of Roland Ewald solved the problem. It is important to mention, that this reconfiguration has to be made for all modules of the project (at least for me this was necessary) as well as that IntelliJ sometimes hides parts of the Additional compiler options, so be sure to click on expand even if they seem empty or correct.

Java 9 The type URL is not visible

Eclipse oxygen; windows 7; JDK 9 final from 9, 21.
Just trying to port an old application written for Java 6 but also compiled with java 8. On the line:
String path = Config.class.getResource("").getPath();
With JDK 9 I get the error: "The type URL is not visible".
Further, the line:
URL url = Config.class.getResource(Config.get(iconPath));
tells me: "Type mismatch: cannot convert from URL to URL"
I can't find any hint in the API description for Java 9, nor in the migration guide telling me, that either of it is related to restrictions of internal API access.
Beside The erros poped up a little later. Before, I could compile and run the application!
May be a proplem of eclipse java 9 beta plugin.
Do anybody know more about it?
# Alan: Your assumption is right. As I said it’s an old application built for Java 6. Just for fun I was curious to see what happened with Java 9. Running the jar compiled with Java 6 using java 9, no problem it works. Hence next step was to try to compile the source with Java9 and to run it with Java9, not changing any code or declaration. Then the mentioned error popped up. With Java 8 and before, java.net.URL was not imported, as it was an intermediate!
Eclipse with Java 9 don’t like it and mention the error "The type URL is not visible" and don’t compile. When I import java.net.URL, it works and the application can be compiled and run. However now Eclipse suggest to “remove the unused import”!
I guess, this requires a little fix of the Eclipse Java 9 plugin!

Troubles launching Kestrel

I am try to play with Kestrel 2.4.1 (http://robey.github.io/kestrel/). Unfortunately, it does not launch. I get the following exception when I run the devel.sh script. IOther scripts produce similar exception.
Starting kestrel in development mode...
May 17, 2014 2:26:06 PM java.util.logging.LogManager$RootLogger log
FATAL: Error in config file: %s
java.lang.UnsupportedOperationException: Position.line
at scala.tools.nsc.util.Position$class.line(Position.scala:173)
at scala.tools.nsc.util.NoPosition$.line(Position.scala:196)
at com.twitter.util.Eval$StringCompiler$$anon$1.display(Eval.scala:444)
at scala.tools.nsc.reporters.AbstractReporter.info0(AbstractReporter.scala:45)
Any help would be appreciated. I am using Java 8.
Scala support for Java 8 is experimental even in 2.11.0, and the github version has the last version of Scala being used as 2.9.2
From: Kestrel Build File
scalaVersion := "2.9.2",
From: SCALA 2.11.0 IS NOW AVAILABLE!
The Scala 2.11.x series targets Java 6, with (evolving) experimental support for Java 8. In 2.11.0, Java 8 support is mostly limited to reading Java 8 bytecode and parsing Java 8 source. Stay tuned for more complete (experimental) Java 8 support.
I would not expect this to work on Java 8 without having to fix compile issues for 2.10 and 2.11 and then Scala would need better support for Java 8.
Actually it's Logger can not init correctly.
Make sure queuePath and filename of development.scala are available.

Accessing a library (compiled using higher jdk) gives exception when accessed from lower JRE

I created a jar file (compiled it using jdk1.7). When I used this jar in a project(using JRE 1.6), I get the following exception- unsupported major.minor version 51.0 (I suppose 51.0 is meant for jdk1.7). I used eclipse IDE for all these operations.
I am wondering whether this exception is a norm (in this kind of situation) or is it coming just because class loading in eclipse works differently
This is expected. Bytecode specifically compiled for a java version, can't be executed on a lower version. This is because it might have bytecode instructions and/or features not supported by an earlier Java version.
To compile for a lower java version, you need to explicitly specify the target version of compilation, eg:
javac -target 1.6 ...
In Eclipse you can set this under Properties > Java Compiler > "Generated .class files compatibility". However in general it is advisable to just use a Java 6 compiler to make sure you are actually only using features and libraries included in Java 6.
Class loading is performed by the JVM, both within eclipse and outside of it. This error simply indicates the the file format of class files has changed in Java 7, and a Java 6 virtual machine does't know the class file format from the future.
You can instruct the Java compiler to use the class file format of a previous java version (in eclipse, you can find the setting under Properties -> Java Compiler -> JDK compliance).
In addition, you'll want to verify that you only use API elements that also existed in JDK 6.

Are there undocumented changes in the classpath in Java 7

I used to do the following command line in Java 6:
java -cp "d:\mylib\*" com.my.package.program
Now I upgraded to JDK 7 u1 64 bit and it started to complain that a jar can not be found. The jar IS in the mylib folder.
I looked in http://download.oracle.com/javase/7/docs/technotes/tools/windows/java.html
There is nothing specific written for Java 7. But is the info there up to date?
Java 7 single entry classpaths under windows seem to be broken. To work around this issue I split my classpath, because for some odd reason, java 7 classpaths under windows do work if they consist of 2 or more entries.
For example:
java -cp "d:\mylib\*;d:\myLib" com.my.package.program
or even
java -cp "d:\mylib\*;" com.my.package.program
would work with java 7. I am aware that this is by no means a very elegant solution, but at least the programs run.