Lambda error during maven build - java

I am using Maven build to build my project(using Eclipse IDE).
I have put jdk1.8 as default jdk, but still, I am getting an error as the source is 1.6.
Is there a configuration problem I am missing out? Please let me know?
(use -source 8 or higher to enable lambda expressions)
1. "clean install" as goals in "Run Configurations" in Eclipse.
2.pom.xml file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mastercard.ayman</groupId>
<artifactId>Spring_MVC</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-webmvc</artifactId>
<version>3.0.7.RELEASE</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>spring-libs-release</id>
<name>Spring Releases</name>
<url>https://repo.spring.io/libs-release</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</project>
Compiler is JavaSE-1.8

Either set the maven-compiler-plugin as #Horst says or set the maven.compiler.source and maven.compiler.target properties like this.
<project ...>
...
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
...
</dependencies>
<build>
...
</build>
</project>

This is something I have dealt with too many times.
Could you post the following things as an answer?
Your current build command/query.
Your pom.xml code.
Your compiler version.
With these file(s) I could help you further to resolve your problem!

Setting the JDK in eclipse is only half the story, as maven manages the compiler itself.
Try adding the maven compiler plugin to you build configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

Related

Eclipse Maven Build Error invalid target release

I am using Maven for the first time (in Eclipse). I would like to include
HakariCP to my project. Every time I try to build my project I get following error message:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project WindowPanel: Fatal error compiling: invalid target release: 1.8 -> [Help 1]
Here is my pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>me.gustavwww</groupId>
<artifactId>WindowPanel</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>WindowPanel</name>
<description>A Windows Server Panel</description>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.10.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>LATEST</version>
<scope>compile</scope>
</dependency>
</dependencies>
Thanks in advance!
EDIT: All I did was update my JDK to the latest version.
If you have JRE set to 1.7 by default in Eclipse you need to specify 1.8 in the Run Configurations. Go to "Run > Run Configurations..." and select the Maven Build you have problem with. Then click the JRE tab and choose Execution Environment Java 1.8.
If you really need to compile it against Java 8, read this question and answer.
They provide more than one to way to force Maven to use a specific version of Java.

Maven package 2 projects into a single war to deploy to tomcat server

I am trying to create a project that uses a java spring back-end and a javascript front-end. I have a parent pom with 2 modules 'webapp' and 'frontend'. how would i package this all into one war to copy onto a local tomcat server?
I know i would have to create one "uber" WAR but i dont know how to do that using maven, any pointers/ links to tutorials on packaging projects like this?
I dont want to put them into one EAR file.
Parent pom
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>foo</groupId>
<artifactId>barr</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
<modules>
<module>webapp</module>
<module>frontend</module>
</modules>
</project>
You could use a combination of maven-assembly plugin and maven-shade plugin in order to create your final "uber" jar. Although, I think it is a bad idea, according to me you should install TomEE instead of tomcat and deploy a regular EAR it would be painless.
I can see you try to leverage whatever is available on Spring Boot, so it would make sense to work along the way with it, taking advantage of it's automatic configuration /conventions. As far as I know Spring Boot supports the inclusion of static content to an existing war, please see here related question or here.

Maven isn't working with specifying Java JDK?

I am trying to specify which Java JDK version to use in Maven/IntelliJ IDEA. I want to use JDK 7, but the source always seems to compile in JDK 8. I have done quite a few things, this is the screenshot of my Project Structure settings of IntelliJ IDEA:
http://i.stack.imgur.com/wabk2.png
This is my pom.xml. As you can see, I am using properties, and the maven compiler plugin.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven- 4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>me.staticjava</groupId>
<artifactId>VillagerMerchants</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>spigot-repo</id>
<url>http://repo.md-5.net/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.7.9-R0.3-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.7.9-R0.3-SNAPSHOT</version>
</dependency>
</dependencies>
I am not sure why, but the code ALWAYS compiles in 1.8...
Any help?
Thanks,
~StaticJava
You need to go into Settings -> Project Settings -> Maven -> Runner and check the JRE setting.
Mine is set to Use Project JDK (1.7) but it sounds like yours is set to something different.
By the way, I guess you are aware that the "language level" in your pom (1.7) is a different setting to the actual JDK you compile with. For example you can well use JDK 1.8 but compile to language level java 7... :)
Good luck.

Cannot build Spring 4 project with Maven

I am going through this guide:
https://spring.io/guides/gs/rest-service/
I use Maven for building, so I've fetched the pom.xml linked in the official Spring guide:
https://github.com/spring-guides/gs-rest-service/blob/master/initial/pom.xml
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>gs-rest-service</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.0.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
</dependencies>
<properties>
<start-class>hello.Application</start-class>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-build</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/libs-snapshot</url>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>spring-repo</id>
<name>Spring Repository</name>
<url>http://repo.spring.io/release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/libs-snapshot</url>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</project>
I get the following error when running mvn install
[ERROR] Error resolving version for plugin
org.springframework.boot:spring-boot-maven-build' from the
repositories [local (C:\Users\Laszlo_Szucs.m2\repository),
spring-snapshots (repo.spring.io/libs-snapshot), central
repo.maven.apache.org/maven2)]: Plugin not found in any plugin
repository -> [Help 1]
How do I know which version to provide in the pom.xml for this?
Check whether http://repo.spring.io/libs-snapshot is in pom.xml. If not, Add http://repo.spring.io/libs-snapshot to maven repository.
<repository>
<id>spring-repo</id>
<name>Spring Repository</name>
<url>http://repo.spring.io/release</url>
</repository>
And upgrade the maven to 3.0.5 above.
In my case, removing the ~/.m2/repository/org/springframework/boot folder and then cleaning the project resolved the issue. After this issue, I also faced another issue in which STS complained that my maven project was not updated. However, right clicking on the issues in the Markers area and selecting Quick Fix popped up a window which prompted me to update the maven projects. Selecting the projects and clicking the update button in this window resolved the issue.
I specified d goals as "spring-boot:run" (without quote) it works for me
procedure: right click on myproject>run as >run configurations >click on mavenbuild>goals(specify goal name)>run

Maven - No plugin found for prefix 'tomcat7' in the current project

I've created a Maven project with the archetype "webapp" but when I start the command "mvn tomcat7:start", I've the following error :
No plugin found for prefix 'tomcat7' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:\dark\.m2\repository), central (http://repo.maven.apache.org/maven2)] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
My project structure :
-src
-main
-resources
-webapp
-WEB-INF
-web.xml
-index.jsp
-target
-classes
-dependency
- // the 'dependency' directory contains all the jar files
-lbagno
-maven-archiver
-surefire
lbagno.war
My pom.xml contains well the dependency for tomcat.
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myspace</groupId>
<artifactId>lbagno</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>lbagno Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<type>maven-plugin</type>
</dependency>
</dependencies>
<build>
<finalName>lbagno</finalName>
</build>
</project>
I don't understand why it doesn't work.
Do you have any solutions ?
Thank you
I know it was asked a year ago, but my answer might work for somebody other than me.
If creating the build tag in the pom.xml file not works, try editing the settings.xml file at your .m2 directory this way:
<pluginGroups>
...
<pluginGroup>org.apache.tomcat.maven</pluginGroup>
...
</pluginGroups>
I found the solution here:
http://tomcat.apache.org/maven-plugin-2.2/
First, there is no start goal, see the goals page of the doc.
Next, it's a plugin, you declared it as a dependency, this is why you get this error, I suggest you read the usage page of the plugin.
Here is a schematic structure of the pom.xml:
<project>
<!-- ... -->
<dependencies>
<!-- your deps here -->
</dependencies>
<build>
<plugins>
<!-- your default build plugins here -->
</plugins>
<build>
<!-- ... -->
</project>
This worked for me:
mvn clean install tomcat7:run
Run mvn with -X -e params. This should give you more information about the error.
I saw that you don't have any pluginRepositories declared. Add the following lines to your pom.xml:
<pluginRepositories>
<pluginRepository>
<id>apache.snapshots</id>
<name>Apache Snapshots</name>
<url>http://repository.apache.org/content/groups/snapshots-group/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
Try to delete this part from your dependency and put this line of code in plugins on your projects pom.xml.
From dependency delete this line of codes:
<dependency>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<type>maven-plugin</type>
</dependency>
and put this in ....
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
This will surely work.

Categories

Resources