theonlygusti theonlygusti -5 years ago 205
Java Question

How to install with maven?

I am working on a Java project, following this tutorial for bukkit plugins.

In eclipse, when I navigate through Run As > 7 Maven install (as in the below picture) everything works fine and a .jar is created as expected.

However,when I run

mvn install
from the command line it doesn't work, it throws these errors:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project WizardServer: Compilation failure
[ERROR] An unknown compilation problem occurred
[ERROR] -> [Help 1]
[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.
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1]

Why can I not build this project using maven at the command line? Does eclipse use a different command to just
mvn install

If it is helpful, I put my source into this github repository so you can browse the file tree too.

I have included what I believe are important files below though:


<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">

package io.github.theonlygusti.wizardserver;


public final class WizardServer extends JavaPlugin {
public void onEnable(){

public void onDisable(){"Disabled :(");

And here is what
mvn install -X
tells me my system is:

Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T16:41:47+00:00)
Maven home: /usr/local/Cellar/maven/3.3.9/libexec
Java version: 1.8.0_91, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.11.4", arch: "x86_64", family: "mac"

See also this pastebin for the full output of
mvn clean install -X

Which is pretty correct as far as I can tell.

Answer Source

Eclipse can indeed use a different process to build your Maven project. Eclipse relies on the M2Eclipse plugin that integrates it to Maven and, by default, uses an embedded Maven installation, which is 3.3.9 for Eclipse Mars.

To fix your command line issue

First of all, your POM declares


Having twice the <source> element with the same value isn't that much of a problem. Maven will disregard one of them. However, it means that <target> will default to 1.5. And you can't compile a 1.8 source file using 1.8 specific features to a 1.5 byte-code.

As such, you need to declare both <source> and <target> as such:


With that change, you will have another slight error, because the method onDisable isn't calling the getLogger() method properly:

public void onDisable(){
  getLogger().info("Disabled :(");

To fix what seems to compile with Eclipse

Running "Run as... > Maven install" in Eclipse does not clean the previous builder folder. It is entirely possible that Maven is relying on previous built data and, thus, not detecting properly the non-compiling code. In such situation, I always recommend to clean before installing, i.e. running mvn clean install. From Eclipse, you can do that by:

  1. Doing "Run as... > Maven clean" then doing "Run as... > Maven install"
  2. Creating a special "Run Configuration" for a Maven build, that invokes the goals "clean install". This way, you can run that configuration without launching two distinct builds.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download