Reputation: 2606
I try to compile a Java project using Maven. The same projects compiles fine on my Windows machine but it errors on my Linux server:
# mvn package :(
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building X 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.3:resources (default-resources) @ X ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 15 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.4:compile (default-compile) @ X ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 19 source files to /root/X/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] Failure executing javac, but could not parse the error:
javac: invalid target release: 2.4
Usage: javac <options> <source files>
use -help for a list of possible options
[INFO] 1 error
This is the pom.xml I use:
# cat 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>
<packaging>jar</packaging>
<properties>
<jdk.version>1.8</jdk.version>
</properties>
<name>X</name>
<repositories>
<repository>
<id>clojars</id>
<url>http://clojars.org/repo/</url>
</repository>
</repositories>
<groupId>X</groupId>
<artifactId>X</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>de.sciss</groupId>
<artifactId>weblaf-ui</artifactId>
<version>1.28</version>
</dependency>
<dependency>
<groupId>kryonet</groupId>
<artifactId>kryonet</artifactId>
<version>2.21</version>
</dependency>
<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>com.intellij</groupId>
<artifactId>forms_rt</artifactId>
<version>5.0</version>
</dependency>
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>[0.4, 0.5)</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.4</version>
<configuration>
<source>2.4</source>
<target>2.4</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>src/</classpathPrefix>
<mainClass>MainServer</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>res</directory>
</resource>
</resources>
</build>
</project>
I assume this is somehow related to maven-jar-plugin
, since that is the only thing in pom.xml
with a version number of 2.4
. What is the difference here to my Windows machine? Why does it fail to compile?
Upvotes: 0
Views: 1418
Reputation: 5487
You set the wrong Java source and target versions:
<configuration>
<source>2.4</source>
<target>2.4</target>
</configuration>
there you're telling Java that your sources are for the version 2.4 of the language :)
Just change that to
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
Or whatever matches your installed jdk and language features you're using.
Just as a general rule, by the way, what you put in your POM is not the all that Maven is going to use; the final POM that Maven uses is a mix and merge of the super POM, the POMs in the hierarchy plus various sources for defaults (i.e. the settings.xml
file, etc).
Upvotes: 3
Reputation: 10423
The source and target versions of the java compiler (maven-compiler-plugin
) refer to java versions, it supports 1.4 - 1.9 only. And you need to run maven with a Java which is as least as new as the target. I would simply remove the <configuration>
of this plugin if you dont know what it is used for.
Upvotes: 2