Why can't maven plugin work with eclipse java compiler? - eclipse

I installed m2eclipse plugin in my eclipse.I have a java project in eclipse. Then I add a pom.xml into the root folder of my project. Convert my project into maven project. Now the problem comes: I can download jar contained in pom.xml, but can't import it into my java file.
Always got java compile error in my project. In package explorer view,I can see maven dependencies.
I have tried this:maven clean, restart eclipse, project clean.
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>TomLabs</groupId>
<artifactId>TomLabs</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>test</name>
<description>Tom source code</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.media</groupId>
<artifactId>jmf</artifactId>
<version>2.1.1e</version>
</dependency>
</dependencies>
</project>

One possibility could be the package/class what you are trying to import is not available in the version of the jar file you have mentioned in the pom.xml.

Related

Maven error: Failed to run the ecj compiler: Unrecognized option : --patch-module

I'm using Maven in Eclipse for a modular Java project, and have managed to make Maven use the Eclipse compiler following the answer to this question.
However, the Maven test-compile target fails with the error message
Failed to run the ecj compiler: Unrecognized option : --patch-module
which is quite surprising (actually unbelievable) because Eclipse is well up to patching modules.
Here's the pom.xml for a MVE, consisting of a modular project patchmodule:
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>patchmodule</groupId>
<artifactId>patchmodule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<compilerId>eclipse</compilerId>
<release>16</release>
<compilerArguments>
<properties>${project.basedir}/.settings/org.eclipse.jdt.core.prefs</properties>
</compilerArguments>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>ecj</artifactId>
<version>3.31.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
The error kicks in as soon as you give the project a single test, such as
package patchmodule.test;
import static org.junit.jupiter.api.Assertions.*;
class Test {
#org.junit.jupiter.api.Test
void test() {
fail("Not yet implemented");
}
}
and then do a Maven install, or any target that will invoke testCompile.
Is this a bug (and if so, whose)? More importantly, is there a way to work around it? Any help is much appreciated.

Eclipse: Convert to Maven - unknown packaging: eclipse-plugin

I am trying to convert my Eclipse RCP 3 Product into a Maven Project.
This is the pom.xml it created:
<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>de.dspace.qpm.admintool.coreplugin</groupId>
<artifactId>de.dspace.qpm.admintool.coreplugin</artifactId>
<version>1.4.0.qualifier</version>
<packaging>eclipse-plugin</packaging>
</project>
The error message "Project Build Error: Unknown packaging: eclipse-plugin" comes up. I don't know how to fix that.
You need to tell Maven to enable the Tycho extension (which registers Tycho’s packaging types):
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tychoVersion}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
See the Tycho Reference Card for details.
You should also get in the habit of defining a tychoVersion property, as Tycho will complain if you mix multiple versions of the various Tycho plugins in your build.

Eclipse maven project JDK build path

When importing an existing Maven project into Eclipse, where is the JDK / JRE being driven from? For example, as per below, on import, its being set to J2SE 1.4 however I want it to be JDK 1.8.
How can I set it in the Maven pom so that when other devs get the project, on import Eclipse will point to JDK 1.8 and not 1.4?
My suggestion is to specify the version of Java from the configuration of the maven-compiler-plugin plugin. Please check the following skeleton.
<?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">
...
<properties>
...
<java.version>1.8</java.version>
...
</properties>
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<verbose>true</verbose>
<debug>${debug}</debug>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
...
</plugins>
...
<resources>
...
</resources>
...
</build>
...
</project>

Eclipse could not find artifact on local maven-plugin module

I have a maven project with 1 parent and 5 modules. One of the modules (call it P) is of packaging "maven-plugin", which is configured to be run in the execution phase "process-test-classes of other module (call it T).
The module T has pom.xml as follows. I omitted dependencies, but they don't include P. As in many other cases it all works perfectly in command line.
Question: Whatever I do Eclipse shows "Could not find artifact org.local.enhancer:pom:0.0.2-SNAPSHOT pom.xml /test line 1 Maven Configuration Problem".
Seems like the issue started after installing "m2e-wtp" v0.17 to resolve other issue with offending jars. Configuration is Eclipse Juno SR2, m2e v1.3.1, m2e-wtp v0.17.
<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>
<parent>
<artifactId>parent</artifactId>
<groupId>org.local</groupId>
<version>0.0.2</version>
<relativePath>..</relativePath>
</parent>
<artifactId>test</artifactId>
<dependencies>
...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.local</groupId>
<artifactId>enhancer</artifactId>
<version>0.0.2-SNAPSHOT</version>
<executions>
<execution>
<phase>process-test-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Does anybody have any insight on this? Thanks!

In IntelliJ Scala plugin, can I use scala-compiler.jar retrieved via <dependency> in `pom.xml`?

In IntelliJ, I created a blank Maven project, and added to pom.xml:
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-compiler</artifactId>
<version>2.11.0-M3</version>
<scope>compile</scope>
</dependency>
I then went to Project Settings -> Modules -> + -> Scala, and specified the compiler jar from the drop-down menu as Maven: org.scala-lang:scala-compiler:2.11.0-M3. I receive the error:
Compiler library: no scala-library*.jar found
Of course, scala-library-2.11.0-M3.jar is among the dependencies (transitively), but not stored in the same folder as scala-compiler-2.11.0-M3.jar, which is what seems to be confusing the Scala plugin.
Is there any way to use scala-compiler*.jar downloaded from a pom.xml dependency? Perhaps by manually specifying where to find each JAR?
Before this, I had been using scala-compiler*.jar downloaded via Project Settings -> Libraries -> + -> From Maven. This seems to work because IntelliJ sticks all the downloaded JARs in the same folder, which is what the Scala plugin assumes. Simply for aesthetic reasons I would like to know if it can be done with pom.xml.
You don't need the scala-compiler as a dependency to be able to build the scala project (neither using maven at command line nor by building from Build | Make Project in IntelliJ).
This is a very simple pom.xml that I use for scala projects where I don't have scala installed at all and just point IntelliJ to this pom and then I can compile and run any scala code directly from within IntelliJ.
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.stackoverflow</groupId>
<artifactId>scala-app</artifactId>
<version>1.0-SNAPSHOT</version>
<name>${project.artifactId}-${project.version}</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<scala.version>2.10.1</scala.version>
</properties>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<executions>
<execution>
<id>scala-compile</id>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<args>
<arg>-make:transitive</arg>
<arg>-dependencyfile</arg>
<arg>${project.build.directory}/.scala_dependencies</arg>
</args>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>