I have started a maven project trying to implement the MapReduce algorithm in java 1.5.0_14. I have chosen the 0.20.2 API hadoop version. In the pom.xml i'm using thus the following dependency:
< dependency>
< groupId>org.apache.hadoop< /groupId>
< artifactId>hadoop-core< /artifactId>
< version>0.20.2< /version>
< /dependency>
But when I'm using an import to the org.apache.hadoop classes, I get the following error:
bad class file: ${HOME_DIR}\repository\org\apache\hadoop\hadoop-core\0.20.2\hadoop-core-0.20.2.jar(org/apache/hadoop/fs/Path.class)
class file has wrong version 50.0, should be 49.0.
Does someone know how can I solve this issue.
Thanks.
Maven by default compiles to JDK 1.4 compatibility. You need to change this.
You need to add this to your pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
[Edit: thank you Sean for pointing out Hadoop requires JDK 6]
I ran into this exact same problem. Turned out sbt itself was running on Java 5, which is the default on my Mac for a silly but valid reason. Once I changed my sbt script to explicitly start with Java6, everything worked fine.
Regardless of your maven-compiler-plugin's source & target configurations (that only controls how your own source code is compiled) you must use a 1.6 JVM to run Hadoop's code since it is compiled targetting "1.6" JVM.
So, just install a 1.6 java runtime and use that to run your program.
Related
Exit code: 1 - javadoc: error - The code being documented uses packages in the unnamed module, but the packages defined in https://docs.oracle.com/en/java/javase/11/docs/api/ are in named modules.
Has anyone been able to make javadoc work without having to change the source version to 1.8 (as suggested in other forums)? I'm using JDK v11.0.5 and the issue still present (also with JDK 12+).
Edit: This error originated from maven and thrown by the maven-javadoc-plugin. I have not been able to make it work for JDK 11+ even with the <source>8</source> configuration.
As suggested in OpenJDK issue tracker this can be worked around with defining source on Javadoc plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<source>8</source>
</configuration>
</plugin>
Adding <detectJavaApiLink>false</detectJavaApiLink> to the Maven javadoc pluging configuration fix the error
I needed the bit from Carlos Santos to make this really work. The complete config that incorporates his answer is:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<source>8</source>
<detectJavaApiLink>false</detectJavaApiLink>
</configuration>
</plugin>
javadoc produces links to packages you use, e.g. to classes documented in .../javase/11/docs/api. While your comments are in an unnamed module, the targets are not, and javadoc can't combine those two. It produces either a package-list or an element-list file, so you can't mix unnamed modules (packages) with named modules.
I didn't find a way to limit the links that javadoc tries to produce; so you may have to use modules for your own project. This seems ridiculous to me, just to make javadoc happy. I guess this is just one of the reasons that so many people stick to Java 8.
I was able to get my own project to work by using a new version of the compiler plugin and setting the release property to 8.
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<properties>
<maven.compiler.release>8</maven.compiler.release>
</properties>
I was facing the same issue. I was using Java 11.0.3 and org.apache.maven.plugins:maven-javadoc-plugin:2.10.4:jar. Updating the maven-javadoc-plugin version to 3.2.0 worked perfectly for me.
We can use <detectOfflineLinks>false</detectOfflineLinks> in the configuration.
I am running a simple pattern matcher program exactly as in
test_harness
Information:java: Errors occurred while compiling module 'demo_java8'
Information:javac 1.8.0_121 was used to compile java sources
Information:2018-02-06 10:15 - Compilation completed with 1 error and 0 warnings in 376ms
Error:java: Compilation failed: internal java compiler error
However terminal command javac xxx.java and java xxx run properly.
Running the first hello world program gives the same error.
In my case, the issue is resolved by adding a type parameter object to a class instance that needed it. In the following code replaced new ParameterizedTypeReference<> with new ParameterizedTypeReference<Map<String, Object>>
return getRestTemplate().exchange(uri,
HttpMethod.POST,
new HttpEntity<>(headers),
new ParameterizedTypeReference<Map<String, Object>>() {
});
It turned out that "odd" error description is because of maven plugin was missing. And it's default was 1.5 while Console class is only available since 1.6. Instead of jar or class cannot be found, it gives a blur description internal java compiler error. Information:javac 1.8.0_121 was used to compile java sources was a hint that the javac version and sdk version mismatch. Besides, I was surprised that intellij idea run function uses maven build (I thought it was just for cli) .
If I have to guess, your IntelliJ is using the JDK packed with IntelliJ, try to set up your JDK for your project, in Project Structure make sure the JDK match your Java environment.
JDK selection
If you use a maven project and for example, you use java version as 1.8 please use this plugin where you specify which version you are using.
Working example:
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
ive imported a bunch on maven projects from svn and they all (...a lot) try to use
JRE System Library [JavaSE-1.7]
But i only have
jdk1.8.0_102_64Bit
Which i told eclipse about in eclipse.ini with:
-vm C:\Users\myuser\Downloads\jdk1.8.0_102_64Bit\bin
Yet all the imported maven projects insist to use the "System JRE" which is unbound when i check it.
How do you tell maven to use what eclipse knows about? or where does maven get its information about JDK's / JRE'S?
Maven by default uses JAVA_HOME Environment Variable to know which java version to use. Unless you set different one in pom.xml.
Try check every pom.xml of your projects, they must have a plugin section like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable>${JAVA_1_6_HOME}/bin/javac</executable>
</configuration>
</plugin>
Executable tag tell maven to use java 6 in this example.
In this case i probably did something wrong while importing it from svn..a second try worked, but im not sure why :(
I am using Java 8 for my JRE in Eclipse Luna with with the m2e Maven plugin. I see this warning as soon as I create a Maven project: Build path specifies execution environment J2SE-1.5. There are no JREs installed in the workspace that are strictly compatible with this environment. I see lots of older advice on this site on how to deal with this error, but nothing related to Java 8. I also that Oracle says J2SE was deprecated in 2008. The most promising answer I have found thus far comes from #Pascal Thivent here:
Warning - Build path specifies execution environment J2SE-1.4
But these instructions no longer seem to be relevant for Luna:
Eclipse project Properties > Maven > Update Project Configuration
I only see "Lifecycle mapping" under Maven.
Can someone please explain (1) what this error means (2) if it is still a worry, given that J2SE-1.5 seems to have been deprecated (3) how to best fix it in Luna?
This error is because the project pom file is instructing maven to compile against java 1.5.
It is best to compile and test to a current java version. In your case java 8.
I am unsure how to fix it inside the eclipse IDE, but the project pom file can be edited to include the compile version as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
While running java program getting following error in eclipse
Caused by: java.lang.Error: Unresolved compilation problem:
Resource specification not allowed here for source level below 1.7
Although I am using java 1.7.25 and all eclipse settings are in place but not sure why getting this error
SOLUTION.
Problem solved by updating project in eclipse using maven.
Despite of the fact that you are using Java 1.7 you can compile source code as if you had compiler from Java 1.6 (this can be useful for example for cross-compilation).
As Shivam Tiwari said in Eclipse you can change it in window->preferences->java->Compiler Compiler
If you are using Maven you should add the following plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
In Eclipse. Go to Project->Properties->Click on Java Compiler and change Compiler compliance level to 1.8 or above.
It works for me many times.
Maven update with 'Force snapshot release' did the trick. pom.xml doesn't need to be changed.