I'm getting a compilation error when I compile using maven but works in eclipse. Both are using the same JDK:
java -version
java version "1.6.0_35"
Java(TM) SE Runtime Environment (build 1.6.0_35-b10)
Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01, mixed mode)
mvn -version
Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.6.0_35, vendor: Sun Microsystems Inc.
Java home: /usr/lib/jvm/jdk1.6.0_35/jre
Default locale: es_ES, platform encoding: UTF-8
OS name: "linux", version: "3.2.0-29-generic", arch: "amd64", family: "unix"
This is the error:
[ERROR] /blablabla.../myClass.java: [78,107] inconvertible types
[ERROR] found : java.util.Collection<java.lang.Object>
[ERROR] required: java.util.Collection<? extends org.springframework.integration.store.MessageGroup>
[ERROR] -> [Help 1]
And this is the code (no compilation error in eclipse):
Collection<? extends MessageGroup> collection = (Collection<? extends MessageGroup>) this.groupMap.values();
I know that this is a pretty recursive issue, I've found a few posts asking the same, but seems that nobody has a standar fix. Some people say that works with different JDK version. I have tested with 1.6.0_30, 1.6.0_31, 1.6.0_32 and 1.6.0_35 and all fail.
Any idea?
Thanks
I suspect eclipse isn't using the JDK you think it is. Try using type erasure.
Collection<? extends MessageGroup> collection =
(Collection<? extends MessageGroup>)
(Collection) this.groupMap.values();
Related
I believe this is an issue with my development environment since I was able to build this jar before I needed switch to a new laptop.
I need to build this jar with java version 1.7 due to production environment requirements.
In the pom.xml I have the properties
<properties>
<checkstyle.version>8.10.1</checkstyle.version>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
bash-3.2$ java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
bash-3.2$ mvn --version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/Cellar/maven/3.6.3_1/libexec
Java version: 1.7.0_80, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.7", arch: "x86_64", family: "mac"
When I run:
mvn package -DbuildNum=1.0.0-SNAPSHOT
It fails with the output:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.0.0:check (compile) on project syn-dap-hadoop: Execution compile of goal org.apache.maven.plugins:maven-checkstyle-plugin:3.0.0:check failed: An API incompatibility was encountered while executing org.apache.maven.plugins:maven-checkstyle-plugin:3.0.0:check: java.lang.UnsupportedClassVersionError: com/puppycrawl/tools/checkstyle/api/CheckstyleException : Unsupported major.minor version 52.0
Changing my JAVA_HOME to java 1.8 allows it to build properly, but I need it to be built in 1.7 for the environment it runs in.
Usually, it is no problem to build with JDK 1.8 for Java 1.7. The resulting artifacts will run on a Java 1.7 environment just fine.
If you don't want this, you need to downgrade your checkstyle plugin to a version that still support Java 1.7.
I'm using Maven as a build tool for Scala code. I'm able to build the Scala objects fine using maven. However when I echo $M2_HOME ,$M2,$JAVA_HOME, everything is returning blank. While this is a sign that these environment variables are not set properly, they are not causing any issues, which to me sounded a bit surprising. Can you please let me know what I'm missing here. I'm running Ubuntu 15.04 and included the below output if needed.
~$java -version
openjdk version "1.8.0_45-internal"
OpenJDK Runtime Environment (build 1.8.0_45-internal-b14)
OpenJDK 64-Bit Server VM (build 25.45-b02, mixed mode)
~$mvn -version
Apache Maven 3.0.5
Maven home: /usr/share/maven
Java version: 1.8.0_45-internal, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.19.0-58-generic", arch: "amd64",family: "unix"
This is the first time I'm using Java, Maven and Scala so kindly excuse my ignorance.
I have this compilation error un maven
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on
a JRE rather than a JDK?
[INFO] 1 error
But It's not possible because I have the jdk in my path: ;..;C:\PROGRA~2\Java\jdk1.7.0_71\bin
and:
C:\Development\Workspaces\EclipseWS\devices-project>java -version
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) Client VM (build 24.71-b01, mixed mode, sharing)
and here mvn -v :
C:\Users\joanet>mvn -v
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 14:51:
28+0100)
Maven home: C:\apache-maven-3.0.5\bin\..
Java version: 1.7.0_71, vendor: Oracle Corporation
Java home: C:\PROGRA~2\Java\jdk1.7.0_71\jre
Default locale: en_GB, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
If you run mvn -v you will see what Maven thinks it is using
e.g.
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-15T03:59:23+10:30)
Maven home: /usr/local/Cellar/maven/3.2.5/libexec
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.9.5", arch: "x86_64", family: "mac"
Is your problem one of these StackOverflow errors?
Eclipse/Maven error: "No compiler is provided in this environment"
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
Maven error :Perhaps you are running on a JRE rather than a JDK?
Maven Package Compilation Error
Or any of the other google answers.
I have a code that I'm working on from 2 different location, a Win7 machine and an OSX.
When worked on using Win7 machine, I don't need to bother about which java version that Maven compiles, I just need to set the PATH variable. If I'm on Java 5, it compiles against Java 5, if I'm on Java 7, it compiles against Java 7. No problem there.
Different case for my OSX machine. Now this is the exact same set of codes.
My Java version
[Mac-Pro] ~/apache-maven/apache-maven-3.1.1/conf $
p01ntbl4nk> java -version
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)
My Maven version
[Mac-Pro] ~/apache-maven/apache-maven-3.1.1/conf $
p01ntbl4nk> mvn -version
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 23:22:22+0800)
Maven home: /Users/p01ntbl4nk/apache-maven/apache-maven-default
Java version: 1.7.0_60, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9.1", arch: "x86_64", family: "mac"
Both shows the same java version. Java 7u60.
But when I run mvn clean compile on my codes, I am getting this "try-with-resource is not supported in -source1.5"
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project archival-client: Compilation failure
[ERROR] /Users/p01ntbl4nk/GitRepositories/GenericArchival/root/archival-client/src/main/java/org/si/genericArchival/client/App.java:[140,6] error: try-with-resources is not supported in -source 1.5
[ERROR] -> [Help 1]
[ERROR]
I've checked, I don't have any reference in my main maven settings.xml or in any of the pom.xml in the modules that would indicate to use sourve version 1.5
To fix this, I would have to add the following to all my pom.xml
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
But this would mean that the maven modules are no longer adaptable to the java version of the underlying platform.
Am I missing anything?
Well, you already have your answer, but here it is definitively.
http://maven.apache.org/plugins/maven-compiler-plugin/
Also note that at present the default source setting is 1.5 and the
default target setting is 1.5, independently of the JDK you run Maven
with. If you want to change these defaults, you should set source and
target as described in Setting the -source and -target of the Java
Compiler.
I'm trying to compile the oVirt open source project on fedora core 21,
java -version
openjdk version "1.8.0_20"
OpenJDK Runtime Environment (build 1.8.0_20-b26)
OpenJDK 64-Bit Server VM (build 25.20-b23, mixed mode)
I am getting the following errors:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project builtin: Compilation failure: Compilation failure:
[ERROR] /home/jenkins/workspace/ovirt-engine_master_find-bugs_merged_nomvn/ovirt-engine/backend/manager/modules/builtin-extensions/src/main/java/org/ovirt/engine/extensions/aaa/builtin/kerberosldap/utils/ipa/SimpleAuthenticationCheck.java:[61,25] error: cannot access InitializingBean
[ERROR] /home/jenkins/workspace/ovirt-engine_master_find-bugs_merged_nomvn/ovirt-engine/backend/manager/modules/builtin-extensions/src/main/java/org/ovirt/engine/extensions/aaa/builtin/kerberosldap/LDAPTemplateWrapper.java:[145,31] error: cannot access DisposableBean
mvn -version shows :
mvn -version
Apache Maven 3.2.2 (NON-CANONICAL_2014-06-19T11:19:24_mockbuild; 2014-06-19T11:19:24+00:00)
On fedora core18 it works -
Apache Maven 3.0.4 (rNON-CANONICAL_2013-04-08_07-49_mockbuild; 2013-04-08 10:49:23+0300)
Maven home: /usr/share/maven
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.25.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.9.11-200.fc18.x86_64", arch: "amd64", family: "unix"
The spring that is being used is aligned to 3.1.1.RELEASE from what I can see
In both the machines.
Can you give a hand? I know I'm using code that implements InitialzingBean and DisposableBean, but still - if same spring version, how come it does not compile
we had this problem and we had installed JDK 1.8. When we installed JDK 1.7 then this issue disappeared. Try it, maybe it is your case :)