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.
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>
I am using the maven compiler plugin 3.0 and I get the error "Element compilerArgs is not allowed here". This seems to work for command line but I get this Error in the IDE,.I use IDEA 2017.2 community edition. There is likely some schema missing somewhere, but I am not sure. Does anyone have a good way to solve issues like this, that is not to send a bug report to JetBrains and wait for a fix?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<fork>true</fork>
<compilerArgs>
<arg>-DspecificArg</arg>
</compilerArgs>
</configuration>
</plugin>
I suggest you try maven-compiler-plugin version 3.7.0.
If you stay on version 3.0, update your setup so it looks like this example: http://maven.apache.org/plugins-archives/maven-compiler-plugin-3.0/examples/pass-compiler-arguments.html
If you can go up to 3.7.0, take a look at this example (which is very similar to your code):
https://maven.apache.org/plugins/maven-compiler-plugin/examples/pass-compiler-arguments.html#
Changing the tag name to compilerArguments or another allowed by the IDE may work.
I was with almost the same problem.
I was with jdk 16, maven compiler 3.8.1 and IntelliJ version 2021.1.3.
After any changes in pom.xml, a small icon on the right showed to me (Load Maven Changes). After clicking that button, the issue was solved.
This is how I solved it without making any changes into the pom.xml
mvn clean compile -Dmaven.compiler.forceJavacCompilerUse=true
This will highlight the actual compilation error in the console to solve.
I am not able to successfully import the okhttp project in the intellij.
https://github.com/square/okhttp
I am using intellij community edition: 2016.1
Maven: 3.0
When I hit make. It shows following error message for "okhttp-tests" module:
Error:(94, 49) java: diamond operator is not supported in -source 1.5
(use -source 7 or higher to enable diamond operator)
The language level for all the submodules is automatically set to 5, while for parent it is set to 7.
When I change the language level for okhttp-tests module to 7 and hot make, ideas shown me following error message:
Error:java: javacTask: source release 1.7 requires target release 1.7
Am i using wrong version of idea/maven ?
Please help.
Also there is no detailed documentation available for importing project/ setting up dev environment on the git repo.
I would like to request okhttp members to create a descriptive Contributors.md file for beginners like me.
If JAVA_HOME is set correctly, Please also check the Project Parent POM file for the compiler Version of maven-compiler-plugin
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
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>