Why eclipse doesn't see implemented interfaces? - java

I've imported jfreechart-fse from here: https://github.com/jfree/jfreechart-fse
and I've imported this to eclipse as maven project.
After that, I have many problems, for example in class ChartPanel in org.jfree.chart paskage, eclipse doesn't see "implements" section, and notice
#Override
public void actionPerformed(ActionEvent event) {...}
as a problem. The same situation is in many other cases.
Can you tell what is wrong with that?

Change version of java to 1.7. It resolves most of errors (errors still appear only in test directory in package-info.java files). Maven can build project successfully.
In eclipse you can change java version in project properties in Java Compiler tab or in properties of JRE System Library in your project tree.

pom.xml doesn't declare java version for maven compiler plugin.
J2SE-1.5 is used by default, and Override anotation cannot be used for Interface implementation for this version.
Change Eclipse project configuration to use JavaSE-1.6, or fix pom.xml of project before importing:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>

Related

Maven: Handling Builds for Differing source/target Versions

Two different maven Java projects (let's call them ProjectA and ProjectB) depend on the same library (also a maven Java project, all three projects are self-written). ProjectA needs the library to be compiled for Java 1.7, ProjectB for 1.8. So far I had the following configuration in my library's pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
Installing the library like this then allows me to build ProjectB but not ProjectA, as and are both set to 1.8. I can change those two fields to 1.7 to allow ProjectA to be built but not B.
I want to do proper version control, automated builds, etc. and hence can't always change the lib's source/target version before building a project. Maintaining two library release branches, so solving the issue via the version control system, is also annoying and does not seem elegant (that's my current approach which I'd like to change).
If I replace the version with a variable (e.g. ${jdk.version}) and use the command line flag -Djdk.version=1.7 when installing the lib ProjectA will, for some reason, still not build, claiming the lib is targeted at 1.8. So apparently this is not equivalent to manually putting the 1.7 into the pom.xml file.
How can one solve this problem elegantly? Why will maven/Java not properly target the library at 1.7 if I try to set the corresponding property via the command line?

IntelliJ won't accept Java8 and diamonds at the end of List/Map

I'm using the latest JDK and everywhere from project creation to now everything is set to Java8 or SDK 8.
Still, intelliJ gives me this issue:
The red lamp tells me to change to Java7.
This is my project settings:
and this is the Modules section:
As you can see; I specifically changed it from the SDK default to java 8 when I got the error, but no result.
The compiler settings look like this:
I'm on a macbook and the intelliJ is the community version. Does anyone know why this is happening and how I fix it?
Try to run the project, if this is your error message:
Then I suggest you have a little look into your pom-file.
This project was built using the intelliJ maven project setting, and it was missing this lovely line of code:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
IntelliJ doesn't (at least in my case) generate the version in the pom (despite that I picked all the settings for it).
I tried specifying the compiler version in the plugin too, to no avail. Have you tried invalidating the cache? It's File -> Invalidate Caches/Restart.... I would probably restart as well for good measure.

IntelliJ imports project from POM using wrong JDK version

We have a Maven based Android build, and we just made the switch from JDK 6 to 7.
This came with its share of IntelliJ problems though. What happens is that every time it detects a change in the POM, and reimports/refreshes the project, it returns to selecting the old "Module SDK", the one that's configured to use Java 6:
Even if I manually delete these SDKs from the "Platform Settings" dialog, they keep reappearing as "Maven Android API 19 Platform (N)" where N is the number used to disambiguate it from all the other (identical) SDKs.
I should mention that we do specify in the POM that Java 7 is targeted. I tried to set both the compiler plugin language level, and the maven.compiler.* properties (not sure if that accomplishes the same thing or not), without luck:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
shouldn't IntelliJ pick that up and always configure the project to use a Java 7 SDK? Am I missing something?
I noticed that the problem disappears when I remove any references to 1.6 SDKs entirely in IntelliJ. Not surprising I guess, but also not viable since I have other projects that still rely on the presence of a Java 6 SDK.
I encountered a very similar issue with Maven projects I'd created using IntelliJ (version 14.x in my case). I'd configured IntelliJ to use JDK 8 in the Project Settings but the IDE continued to highlight issues in my code (e.g. complaining about the usage of #Override).
It turns out that the Maven Settings take precedence here, which in my case defaulted to JDK 1.5 (hence the IDE redlines). Changing the settings here does resolve the issue, but only temporarily because they revert back whenever the Maven projects are reimported, or when IntelliJ is restarted.
The permanent fix is to explicitly declared the JDK version in your Maven pom file, as explained in these items.
stop IntelliJ IDEA to switch java language level everytime the pom is reloaded (or change the default project language level) by #vikingsteve
IDEA: javac: source release 1.7 requires target release 1.7 by #bacchus
Here's what they've said you need to add to your pom.xml file.
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
These settings get reflected in the Maven Settings in the IDE and resolved the issue for me.
It will pick up the jdk that you choose in project structure please change it there.
File > project structure > project setting > project > project sdk choose 1.7.
If 1.7 is not present go to
File > project structure > Platform setting > SDKs addd 1.7 there.
It's also important to note that you need to change the runner (jdk level) of your maven.
Maven > Runner > JRE

Addition of a parent item in POM causes JDK version to change

In one of the classes I have this code:
str.isEmpty()
which compiles fine until I add this element to the POM:
<parent>
<artifactId>teevra.platform.parent</artifactId>
<groupId>com.hs.fusion</groupId>
<version>2.0.0</version>
</parent>
And then immediately the eclipse starts giving an error saying "The method isEmpty() is undefined for the type String". I obviously need this parent to access classes/interfaces needed for this child project.
I wonder what is causing the shift from Java Version 1.6 to 1.4 and how can it be prevented? Even more baffling is the fact that from command prompt, the project builds fine but not in Eclipse Juno.
Any help would be greatly appreciated,
G.
You need to specify the specific version of java to use. your problem is probably that your eclipse default is different from the maven default, so as soon as you add the dependency, m2e regenerates the project settings using the maven default (1.5)
Just specify the required java version explicitly. Something like this in your plugins section
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
To ensure that no invalid JRE calls leak into your project, you should use http://mojo.codehaus.org/animal-sniffer/ It seems like your parent lowered the source/target of the maven-compiler-plugin

How to make Maven use Eclipse workspace default JRE?

I'm using Spring Tool Suite and m2e to convert some of our existing projects to Maven projects. The project in question uses jdk1.6.0_20 which is named [jdk1.6] in Eclipse. When I do Maven -> Update project, though, it replaces that jre with the standard [JavaSE-1.6]. While they seem to point to the same libraries, the change in name causes a bunch of exceptions like:
Access restriction: The type WindowsPopupMenuSeparatorUI is not
accessible due to restriction on required library C:\Program
Files\Java\jdk1.6.0_20\jre\lib\rt.jar
My pom.xml has this:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
Is there any way to get Maven/m2e to use the default workspace JRE instead of replacing it with a specific one in the .classpath?
Go into Configure Build Path on the project and go to the Libraries tab.
Remove the JRE System Library
Click on "Add Library..." and select "Workspace Default JRE"
That will give you the current JRE and not specify a specific JRE
Adding maven-compiler-plugin to your pom forces maven to use given version of Java:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
However if you have both jre and jdk installed on your system (for a particular java version), maven may choose jre and then complain that it needs JDK. This may happen after using Maven > Update Project in Eclipse.
To solve this, in Eclipse, right click on JRE System Library > Properties > Environments and select JavaSE-1.8. If you have more than one compatible JREs in your system then tick the jdk1.8.x > OK > select JavaSE-1.8 (jdk1.8.x) as Execution environment > OK
Now maven should choose Java version 1.8 and Eclipse will tell maven to use jdk1.8 as the default JRE for this java version.
It turns out there doesn't seem to be a way to do this with Maven. Instead I changed the error to a warning in Eclipse settings while I work with the owners of the offending code to fix the problems.

Categories

Resources