How to exclude maven plugin configuration (unrecognized parameter -encoding) - java

I am using jaxws-maven-plugin to generate some JAX-WS clients based on WSDL files.
I need to use JDK 1.6 so I am executing with JAX-WS Tools 2.1.7
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-tools</artifactId>
<version>2.1.7</version>
</dependency>
If I use recent versions of jaxws-maven-plugin 2.2.1 or 2.3 over the 2.1.7 jaxws-tools my build doesn't work because an invalid -encoding parameter is added to the command line.
unrecognized parameter -encoding
Full command is
[DEBUG] cmd.exe /X /C ""C:\Program Files\Java\jdk1.6.0_45\jre\bin\java.exe" -Xbootclasspath/p:.m2\repository\javax\xml\bind\jaxb-api\2.1\jaxb-api-2.1.jar;.m2\repository\javax\xml\soap\saaj-api\1.3\saaj-api-1.3.jar;.m2\repository\javax\xml\ws\jaxws-api\2.1\jaxws-api-2.1.jar org.jvnet.jax_ws_commons.jaxws.Invoker com.sun.tools.ws.wscompile.WsimportTool -keep -s <some dir> -d <some dir> -encoding UTF-8 -p <some package> file:<some wsdl file>"
The following pom.xml is working fine, I use 2.2 which does not send the encoding parameter.
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.2</version> <!-- This version works fine -->
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<wsdlDirectory>src/wsdl</wsdlDirectory>
<sourceDestDir>src/main/java</sourceDestDir>
<wsdlFiles>
<wsdlFile>ConsultarStatusNfe.wsdl</wsdlFile>
</wsdlFiles>
<!-- for JDK 6 compilation compatibility -->
<xnocompile>false</xnocompile>
</configuration>
<dependencies>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-tools</artifactId>
<version>2.1.7</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

I was able to use the latest versions by setting the <target>2.1</target> configuration.
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase/>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<wsdlDirectory>src/wsdl</wsdlDirectory>
<sourceDestDir>src/main/generated</sourceDestDir>
<wsdlFiles>
<wsdlFile>myfile.wsdl</wsdlFile>
</wsdlFiles>
<packageName>com.souzacruz.pwnfeintegrator</packageName>
<!-- for JDK 6 compilation compatibility -->
<xnocompile>false</xnocompile>
<target>2.1</target>
</configuration>
<dependencies>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-tools</artifactId>
<version>2.2.10</version>
</dependency>
</dependencies>
</plugin>

the version 2.1.1 of the plug in jaxws-tools does not support the parameter "-encoding". Use a later version, for example 2.2.6 that it does.

Related

Java Sql Driver Class Not Found Jar With Command Line Run

I've been trying to run my Maven Kotlin Ktor project with command line. The project contains the MySQL configuration too. Every time I tried to hit the following command, I got the following error.
Here is my command.
kotlin -cp mysql-connector-java-8.0.30.jar:dev_meet_dev_api.jar MainClassKt
The dev_meet_dev_api.jar file is my project jar and mysql-connector-java-8.0.30 is for MySQL connection with the database. My project is dependent on MySQL connector that's why I added the external dependency for MySQL connector.
As soon I hit the above command on terminal I've got the following error.
Caused by: java.lang.ClassNotFoundException: java.sql.Driver
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
Edit 1: Added the maven 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>spartons.com.devMeetdevApi</groupId>
<artifactId>KtorTesting</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<kotlin.version>1.7.10</kotlin.version>
<ktor.version>2.1.1</ktor.version>
<junit.version>4.12</junit.version>
<serialization.version>1.4.0</serialization.version>
<coroutines.version>1.6.4</coroutines.version>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
<kotlin.compiler.jvmTarget>11</kotlin.compiler.jvmTarget>
<kotlin.code.style>official</kotlin.code.style>
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
</properties>
<dependencies>
<!-- Kotlin language dependencies -->
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
<version>${kotlin.version}</version>
<scope>runtime</scope>
</dependency>
<!-- Kotlin's coroutines dependency -->
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core</artifactId>
<version>${coroutines.version}</version>
</dependency>
<!-- Ktor dependencies -->
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-core-jvm</artifactId>
<version>${ktor.version}</version>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-jetty-jvm</artifactId>
<version>${ktor.version}</version>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-content-negotiation-jvm</artifactId>
<version>${ktor.version}</version>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-serialization-kotlinx-json-jvm</artifactId>
<version>${ktor.version}</version>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-status-pages-jvm</artifactId>
<version>${ktor.version}</version>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-cors-jvm</artifactId>
<version>${ktor.version}</version>
</dependency>
<!-- Kotlin serialization version -->
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-serialization-json</artifactId>
<version>${serialization.version}</version>
</dependency>
<!-- MySQL connector dependency -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.30</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<finalName>dev_meet_dev_api</finalName>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<compilerPlugins>
<plugin>kotlinx-serialization</plugin>
</compilerPlugins>
<args>
<arg>-opt-in=kotlin.RequiresOptIn</arg>
</args>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-serialization</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
</executions>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<artifactSet>
<excludes>
<exclude>mysql:mysql-connector-java:jar:</exclude>
</excludes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</plugin>
</plugins>
</build>
</project>
Edit 2: Added the java-11 modules
P.S I'm using Java 11. Projects works fine if I try to run with the IntelliJ.
You can do this directly in Maven! In your pom.xml add the driver as a dependency.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.30</version>
</dependency>
Then you shade the dependency into the jar
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>mysql:mysql-connector-java</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Then directly execute the jar. If this does not help may I know which Java version you are using?
Kotlin applications need the Kotlin runtime to run (mainly kotlin-stdlib.jar). It can be included
in the application jar or not.
If the runtime is not included, you must add it to the classpath:
java -cp /path/to/kotlin-stdlib.jar:app.jar MainClassKt
You can also use the kotlin script, which automatically adds it:
kotlin -cp app.jar MainClassKt
In your case, the runtime is included thanks to the maven-shade-plugin, so you can run the app like this:
java -cp mysql-connector-java-8.0.30.jar:dev_meet_dev_api.jar MainClassKt
Possibility 1
It is possible that some dependency that you manually added has a different version of java.sql.Driver.
It is overriding the java.sql.Driver dependency version that your code flow needs.
To debug if this is actually the cause of your problem, you can use IntelliJ maven dependency plugin.
It can show if there is any conflict in dependency causing the needed class to not load.
https://www.jetbrains.com/help/idea/work-with-maven-dependencies.html#maven_dependency_diagram
Also, please note that in my experience, If multiple dependencies are loading different versions of same class, then you may get different results in different setup, since order of class loading may differ. This can result in your code working in IntellijIdea, but not when running from terminal.
Possibility 2
Check if the jdbc driver version is compatible with java and database versions that you are using. Try upgrading or downgrading the jdbc version to see if that resolves issue.
Debug approach 1: if above ways don't fix the issue
Since you say that your code works in Intellij, start your application in debug mode and put a debug point in java.sql.Driver.
See which the library which contains this class and the dependency which contains this library.
That can help you debug the cause of problem.
Debug approach 2: if above ways don't fix the issue
Use remote debugging.
Start your jar application in console with remote debug enabled.
Refer this on steps to do it.
https://www.jetbrains.com/help/idea/tutorial-remote-debug.html#ecd9fef1
Using this, you can find the code flow and the cause of problem for program that runs in console.
I hope that this helps you.

Java 11 Hibernate Validator module not found error

I am having trouble migrating my project to Java 11 from Java 8 with Hibernate validator.
I get the following error while attempting to build my project with maven:
[INFO] --- maven-processor-plugin:3.3.3:process (default) # maple-orm ---
[ERROR] diagnostic: ...\module-info.java:19: error: module not found: org.hibernate.validator
requires org.hibernate.validator;
The plugin in the pom for maven-processor-plugin is defined as follows:
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>3.3.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>process</goal>
</goals>
<configuration>
<processors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</processors>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.4.10.Final</version>
</dependency>
</dependencies>
</plugin>
And the module-info.java looks like this:
module test.module {
...
requires org.hibernate.validator;
}
Is there something specific that I am missing in order to fix this issue with JPMS?
As per documentation from Github repository, Release 3.3.3. maven-processor-plugin supports targets is 9
--release release
Compiles against the public, supported and documented API for a specific VM version.
Supported release targets are 6, 7, 8, and 9.
I was able to get a solution to this problem following fabfas answer. I would suggest upgrading to version 4.0 of maven-processor-plugin and specify the proper plugin to run. Please also keep in mind I am using the jakarta suffixed libraries so this may require some fine tuning.
The module name is indeed org.hibernate.validator
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>4.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>process</goal>
</goals>
<configuration>
<processors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</processors>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen-jakarta</artifactId>
<version>${hibernate.version}</version>
</dependency>
</dependencies>
</plugin>

karaf-assembly 4.0.5 - zip ard tar.gz files are not generated at the end of a successful maven build

I am an inexperienced Java and Maven developer, although I have got karaf-assembly builds to work a couple of years ago using the Karaf 3.0.1 release.
When attempting to generating a karaf-assemby 4.0.5 for a customised product build, the zip and tar.gz files are not created at the end of the maven build. The ../target/assembly directory is created each time the maven build is run and the completion status is always "BUILD SUCCESS".
I suspect this this is because the POM file has an error highlighted by the Eclipse IDE at the section for the karaf-maven-plugin directly on the line, which is as follows:
Plugin execution not covered by lifecycle configuration: org.apache.karaf.tooling:karaf-maven-plugin:4.0.5:assembly (execution: default-assembly, phase: process-
resources)
I can resolve this error in the IDE on the line by removing the "extensions" line, but then I get a "Project build error: Unknown packaging: karaf-assembly" error on the "packaging" line.
<plugins>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
**<!-- <extensions>true</extensions> -->**
<configuration>
<startupFeatures></startupFeatures>
<bootFeatures>
<feature>standard</feature>
<feature>management</feature>
<feature>jms</feature>
</bootFeatures>
<installedFeatures>
</installedFeatures>
</configuration>
</plugin>
The POM file I am using is as follows:
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.custom</groupId>
<artifactId>my.distribution</artifactId>
<version>1.0</version>
<packaging>karaf-assembly</packaging>
<!-- PIP Operations Aspect Assembly properties -->
<properties>
<maven-compiler-plugin-version>2.3.2</maven-compiler-plugin-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<assembly.directory>${project.build.directory}/assembly/karaf-4.0.5</assembly.directory>
<karaf.name>karaf</karaf.name>
<karaf.version>4.0.5</karaf.version>
<pip.name>Operations Aspect</pip.name>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>framework</artifactId>
<version>4.0.5</version>
<type>kar</type>
</dependency>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>framework</artifactId>
<version>4.0.5</version>
<classifier>features</classifier>
<type>xml</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>standard</artifactId>
<classifier>features</classifier>
<version>4.0.5</version>
<type>xml</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>enterprise</artifactId>
<classifier>features</classifier>
<version>4.0.5</version>
<type>xml</type>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>process-resources</id>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<version>4.0.5</version>
<extensions>true</extensions>
<configuration>
<startupFeatures></startupFeatures>
<bootFeatures>
<feature>standard</feature>
<feature>management</feature>
<feature>jms</feature>
</bootFeatures>
<installedFeatures>
</installedFeatures>
</configuration>
</plugin>
</plugins>
</build>
Any suggestions would be gratefully received.
You might be missing the execution settings:
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
<execution>
<id>package</id>
<goals>
<goal>archive</goal>
</goals>
</execution>
</executions>

JAXB mixed versions? undefined 'required' attribute

Im generating some classes from WSDL files with wsimport maven plugin # Mule Anypoint Studio 3.5 with JDK 1.7_55
I'm using jaxb 2.2.7 and remove version 2.1.9 from mule libs and replaced by 2.2.7.
When i compile, sometines works fine but others i take this error multiple times:
The attribute required is undefined for the annotation type XmlElementRef
I tried to create an endorsed folder in JDK and include .jars needed,
Do you know any way to avoid this error or replace this libs correctly?
I include this dependencies in pom.xml
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-tools</artifactId>
<version>2.2.7</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.7</version>
</dependency>
<!-- xjc -->
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>2.2.7</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.7</version>
</dependency>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>idlj-maven-plugin</artifactId>
<version>1.2.1</version>
</dependency>
wsimport is 2.2.7 to
wsimport settings:
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>wsdl-AMANSequenceService-exec</id>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<args>
<arg>-version</arg>
<arg>-B-nv</arg>
<arg>-Xdebug</arg>
<arg>-B-XautoNameResolution</arg>
<arg>-Xendorsed</arg>
</args>
<extension>true</extension>
<sourceDestDir>${basedir}/src/main/java</sourceDestDir>
<destDir>${basedir}/src/main/java</destDir>
<extension>true</extension>
<wsdlDirectory>${basedir}/src/main/resources/SICG/AMANSequenceService</wsdlDirectory>
<wsdlFiles>
<wsdlFile>AMANSequenceService.wsdl</wsdlFile>
</wsdlFiles>
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/SICG/external/binding.xjb</bindingFile>
</bindingFiles>
</configuration>
</execution>
We can fix the above behavior by replacing the following jars in Mule CE Runtime Folder (C:\AnypointStudio\plugins\org.mule.tooling.server.3.5.0_3.5.0.201405141856\mule\lib\opt):
jaxb-api-2.1 with jaxb-api-2.2.jar
jaxb-impl-2.1.9 with jaxb-impl-2.2.7.jar
jaxb-xjc-2.1.9 with jaxb-xjc-2.2.7.jar
It would be useful if Mule developers updated these packages to the newest distributions.
The location of your endorsed jars is incorrect. It should be:
%JAVA_HOME%\jre\lib\endorsed
which in your case is:
C:\Java\jdk1.7.0_55\jre\lib\endorsed
Put the jaxb jars here, remove all others and re-try.
This is for people who find this old posting from the search engines.
I was getting the same error message in a new project that I created in Eclipse. The solution was to:
1.) create a new JAXB project instead of some other project type,
2.) specify JDK7,
3.) Specify version 2.2 of JAXB
In Mule specific case, if you are stuck with JAXB2.1, you can force Apache CXF WSDL2Java to generate JAXB2.1 compliant client code
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.1.6</version>
<executions>
<execution>
<id>generate-sources-file1</id>
<phase>generate-sources</phase>
<configuration>
<defaultOptions>
<frontEnd>jaxws21</frontEnd>
</defaultOptions>
<sourceRoot>${project.build.directory}/generated/service-file1</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/some.wsdl</wsdl>
<wsdlLocation>classpath:some.wsdl</wsdlLocation>
<extraargs>
<extraarg>-client</extraarg>
<extraarg>-verbose</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
the key part is
<defaultOptions>
<frontEnd>jaxws21</frontEnd>
</defaultOptions>

Adding AspectJ to pom.xml changed Java version with Maven, why?

UPDATE: here is my maven-compiler-plugin configuration:
<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>
I work on a multi-project application that I build with Maven. We decided to add AspectJ so I added the following code to pom.xml in the top level project: (from the official documentation)
<project>
...
<dependencies>
...
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.3</version>
</dependency>
...
</dependencies>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>compile</goal> <!-- use this goal to weave all your main classes -->
<goal>test-compile</goal> <!-- use this goal to weave all your test classes -->
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
<build>
...
</project>
and the following fragments to each subordinate projects:
</project>
...
<build>
....
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
...
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
</dependency>
....
</dependencies>
...
</project>
Somehow this modification has overridden the Java version I use. If I run build I get multiple errors like this:
Syntax error, annotations are only available if source level is 1.5 or greater
That gives me the suspicion that my Java version (originally 1.6) was somehow reverted to 1.4. I did nothing - at least not knowingly - that could influence the Java version, so I suspect that the above mentioned AspectJ related code is responsible for the change.
My question is how can AspectJ change the Java version and what should I do to fix this problem. Or do I misunderstand something completely and am I on the wrong track?
I think the problem is with the default source, target and complianceLevel settings of the aspectj-maven-plugin (according to the documentation linked previously, 1.4, 1.2 and 1.4 respectively). You should set these explicitly in your parent pom:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.5</version>
<!-- new configuration is here -->
<configuration>
<complianceLevel>1.6</complianceLevel>
<source>1.6</source>
<target>1.6</target>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
<build>
I was missing
<complianceLevel>${java.level}</complianceLevel>
in my pom.xml
If you don't have define the version, the compiler plugin assumes that your Java source conforms to Java 1.3 and that you are targeting a Java 1.1 JVM.
Maybe, you should define it:
http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html
You can find last versions of dependecy and plugin for aspectj.
I was missing the java version with jdk version at the top of my pom properties.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.2</version> <!-- 1.5 dint work for me -->
<dependencies>
<!-- You must use Maven 2.0.9 or above or these are ignored (see MNG-2972) -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>process-sources</phase> <!-- or any phase before compile -->
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<outxml>true</outxml>
<source>${jdk.version}</source> <!-- I was missing this -->
<target>${jdk.version}</target> <!-- jdk.version property -->
</configuration>
</plugin>
and at the top of my pom.xml I had set jdk.version property like,
<properties>
<jdk.version>1.7</jdk.version>
</properties>

Categories