7

I have opened git project I was running under Eclipse previously in IntelliJ. I have changed to Java 8 in following places:

File -> Project Structure -> SDKs

and

File -> Project Structure -> Project

Where to set Java 8 else? What it wants?

The project is Maven, pom file has only dependencies sections

UPDATE

I am trying to run under IntelliJ

Dims
  • 47,675
  • 117
  • 331
  • 600
  • @TimBiegeleisen how can `JAVA_HOME` matter if `IntelliJ` allows per project JDK config? It should use that JDK I configures, all path are known to her. – Dims May 25 '15 at 05:42
  • Please post the output from the bottom of your IntelliJ build window. Also, have you tried restarting IntelliJ? – Tim Biegeleisen May 25 '15 at 05:45

3 Answers3

15

In order to compile your code you should add maven build section:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.2</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

Also you can go to File | Settings | Build, Execution, Deployment | Compiler | Java Compiler and change it there, but it will cause other developers failures as they need to modify IDE before build

nesteant
  • 1,070
  • 9
  • 16
  • Why doesn't it takes this information from `IntelliJ` config? – Dims May 25 '15 at 05:44
  • It takes but it is only for you but not for the other team as .idea folder shouldn't be pushed. More over mvn clean install won't be able to build it as it knows nothing about intellij – nesteant May 25 '15 at 05:44
  • What if I set `1.8` in Maven in `1.7` in `IntelliJ` how will it judge what to use? – Dims May 25 '15 at 05:47
  • Idea will catch compile plugin and will propose you to change configuration. Anyway until you have target less then maven it will work smoothly. Intellij won't allow you to write 1.8 constructions (they will be built correctly by maven but will be red in editor). – nesteant May 25 '15 at 05:48
3

In addition to what you have done, you also have to update the build Module.

SHIFT + CTRL + ALT + S -> Modules -> Select JDK 1.8 and press apply

Check the output from your build to make sure that IntelliJ is using JDK 8 and not the earlier version (7?) which you had.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • I can't update my `JAVA_HOME` each time I run different project with different JDK. `IntelliJ` allows per-project `JDK` config, so it should track `JDK` location automatically. – Dims May 25 '15 at 05:45
0

You can try this way:

For Eclipse:

Windows -> Preferences -> Java -> Installed JREs -> add JDK

You can download the JDK for 1.8 and browse the file when you are trying to add JDK. If it's windows OS then you need to install Java 1.8 and then use the path from C:\Program Files\...\jdk1.8 (Please refer this for reference)

The above is for setting eclipse.

Then you need to apply changes for the project setup as below:

Project -> Properties -> Java Build Path -> Libraries -> Click on JRE System Library -> Edit button -> change the Library as 8 that you have set up for eclipse

For IntelliJ, you can try this guide

Estimate
  • 1,421
  • 1
  • 18
  • 31
  • That alone only adds that new JDK to the list of known JDKs. You should add the information that one then has to **pick** that JDK also for a his project. – GhostCat May 25 '15 at 05:28
  • This is for Eclipse sorry, I need for IntelliJ – Dims May 25 '15 at 05:43