Eclipse uses it's own compiler (ECJ) to compile Java code. Debugging a program compiled with Eclipse is easier, because simple code changes can be applied instantly (by the hot code replacement).
Maven on the other hand uses (by default) oracle JDK, that generates different byte code preventing hot code replacement in a Eclipse debug session.
So I would like to use Eclipse ECJ compiler with my maven build, if I plan to debug the program. A convenient way for me would be a "ecj" profile:
Compile release
$ mvn package
Compile snapshot with enabled hot code replacement
$ mvn -P ecj package
Also the profile activation can be specified in settings.xml
or even Eclipse project properties.
My questions are:
The default Java compiler version used by Maven is Java 1.5 .
Building the Maven Project in Eclipse First of all, select the project and go to “Run As -> Maven Build”. The “Edit Configuration” popup window will open. Enter the “Goals” as “package” to build the project and click on the Run button.
Java Compilation in EclipseThe Eclipse IDE comes bundled with its own Java compiler called Eclipse Compiler for Java (ECJ). This is an incremental compiler that can compile only the modified files instead of having to always compile the entire application.
It is possible to change the default javac
compiler that is used by the maven-compiler-plugin
. The Eclipse compiler is bundled in the artifact plexus-compiler-eclipse
and it is declared by setting eclipse
to the compilerId
attribute of the maven-compiler-plugin
.
If you want to activate this change for a custom profile, you could have the following configuration:
<profile>
<id>ecj</id>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<compilerId>eclipse</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>2.8.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
The plugin is maintained in the plexus-compiler
GitHub repository. Version 2.8.1 uses 3.11.1.v20150902-1521 of JDT, although you could use your own version by adding a dependency on org.eclipse.tycho:org.eclipse.jdt.core
after the Plexus Compiler dependency.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With