Maven: package net.jcip.annotations does not exist - java

I want to use #net.jcip.annotations.NotThreadSafe in my Java code. I have tried to import it is a dependency in the pom.xml for the project as of below. However, I still get the error: Is something wrong with my import?
package net.jcip.annotations does not exist
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.18</version>
</dependency>
<dependency>
<groupId>net.jcip</groupId>
<artifactId>jcip-annotations</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<configuration>
{...}
</configuration>
</plugin>

If you do it like the above you only add the dependency to the classpath of the maven-surefire-plugin which is not what you intend. You have to give it in your pom like this:
<project...>
<dependencies>
<dependency>
<groupId>net.jcip</groupId>
<artifactId>jcip-annotations</artifactId>
<version>1.0</version>
</dependency>
...
</dependencies>
</project>
Furthermore given the dependency to surefire-juni47 is not necessary, cause surefire plugin handles this on it's own. So this can look like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18</version>
<configuration>
{...}
</configuration>
</plugin>

Related

Can't compile Java 13 and Groovy 2.5.8

I have a project (Spring Boot application), in which I mix Java and Groovy.
I can compile and run the project without problems inside IntelliJ Idea.
But I can't compile it with Maven.
Java 12 works fine, but when switching to 13 version it shows me next errors:
Example of POM.xml configuration:
<properties>
<java.version>13</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<javax.version>1.5.4</javax.version>
<groovy.version>2.5.8</groovy.version>
<lombok.version>1.18.10</lombok.version>
....
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<source>{java.version}</source>
<target>{java.version}</target>
<verbose>true</verbose>
<fork>true</fork>
<compilerArguments>
<javaAgentClass>lombok.launch.Agent</javaAgentClass>
</compilerArguments>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>3.6.0-03</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>${groovy.version}-01</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
Does anyone know which compiler/plugin compiles java and groovy code with the java 13 version?
Java 13 support starts in groovy-eclipse-batch 2.5.8-03, which is based upon Eclipse 4.14. https://www.eclipse.org/eclipse/news/4.13/jdt.php#Java_13
You are using 2.5.8-01. At this time, Groovy 2.5.10 is the latest release and groovy-eclipse-batch:2.5.10-01 matches that. And both offer support for Java 13.

Maven - Using Sigar with Java

I am trying to use Sigar in my Java Maven application, i added the following dependencies:
<dependency>
<groupId>org.fusesource</groupId>
<artifactId>sigar</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>4.4.0</version>
</dependency>
but it was throwing thr following exception:
org.hyperic.sigar.SigarException: no libsigar-amd64-linux.so in java.library.path
at org.hyperic.sigar.Sigar.loadLibrary(Sigar.java:172)
at org.hyperic.sigar.Sigar.<clinit>(Sigar.java:100)
at com.ro.terminal.model.utils.TerminalUtils.<clinit>(TerminalUtils.java:28)
at com.ro.terminal.model.service.SyncModule.init(SyncModule.java:187)
at com.ro.terminal.main.Terminalinitializer.<init>(Terminalinitializer.java:124)
at com.ro.terminal.main.Terminalinitializer$3.call(Terminalinitializer.java:339)
at com.ro.terminal.main.Terminalinitializer$3.call(Terminalinitializer.java:1)
at javafx.concurrent.Task$TaskCallable.call(Task.java:1423)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.lang.Thread.run(Thread.java:748)
after googling i knew that i have to add the needed .ddl and .so files in the application and add the path to java.library.path,
i downloaded the files from here and added them under resources/sigar-lib and tried adding the following to my pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<systemPropertyVariables>
<org.hyperic.sigar.path>${sigar.libs}</org.hyperic.sigar.path>
</systemPropertyVariables>
<parallel>classes</parallel>
</configuration>
</plugin>
___________________________
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<java.library.path>${sigar.libs}</java.library.path>
</systemPropertyVariables>
</configuration>
</plugin>
______________________
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Djava.library.path=${sigar.libs}:${java.library.path}</argLine>
</configuration>
</plugin>
the ${sigar.libs} is defined as follows:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sigar.libs>${basedir}/src/main/resources/sigar-lib</sigar.libs>
<build.timestamp>${maven.build.timestamp}</build.timestamp>
<maven.build.timestamp.format>yyyyMMdd-HHmm</maven.build.timestamp.format>
</properties>
what am i doing wrong? i am running eclipse oxygen on Ubuntu 17.10
project screenshot:

net.ltgt.gwt.maven:gwt-maven-plugin with Lombok

I am looking into migrating to net.ltgt.gwt.maven:gwt-maven-plugin, and I use Lombok. So in my projects I had to have following in the plugin configuration:
<extraJvmArgs>-javaagent:${org.projectlombok:lombok:jar}=ECJ</extraJvmArgs>
How does one achieve that with net.ltgt.gwt.maven:gwt-maven-plugin?
Use jvmArgs:
<jvmArgs>
<arg>-javaagent:${org.projectlombok:lombok:jar}=ECJ</arg>
</jvmArgs>
Or if you add dependency with maven in *-client module:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>
You have to edit pom.xml in this way in plugins settings:
<plugin>
<groupId>net.ltgt.gwt.maven</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>1.0.0</version>
<extensions>true</extensions>
<configuration>
<sourceLevel>1.8</sourceLevel>
<failOnError>true</failOnError>
<jvmArgs>
<arg>-javaagent:${settings.localRepository}/org/projectlombok/lombok/1.18.12/lombok-1.18.12.jar=ECJ</arg>
</jvmArgs>
</configuration>
</plugin>

How to exclude dependencies in Maven <reporting> plugins?

How do I exclude dependencies from a reporting Maven plugin? The cobertura-maven-plugin annoyingly pulls in ch.qos.logback:logback-classic which causes mulitple SLF4J bindings warning during build and run. I tried inserting <dependencies> with <exclusions> to the plugin but maven for some reason does not allow that in the <reporting> section. Any help is appreciated. The relevant POM is below.
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.8</version>
<configuration>
<dependencyLocationsEnabled>false</dependencyLocationsEnabled>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<formats>
<format>html</format>
<format>xml</format>
</formats>
</configuration>
</plugin>
</plugins>
</reporting>
This is old but I'll give my solution in case someone else has this exact issue. In my poms I inserted the following
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.7</version>
</dependency>
</dependencies>
Inside the definition for my Cobertura plugin.
Cobertura is using 1.1.7 anyway (in my case) check your artifacts to confirm, you just need to explicitly tell maven to pull that version when creating the plugin otherwise it will still pull the conflicting version and display the error
I have solved this issue including the "scope" tag inside logback dependencies.
This is my POM section:
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback-classic-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback-core-version}</version>
<scope>runtime</scope>
</dependency>

Maven build has missing package linkages

I am having problems using Maven. I have an Apache Flink project and wanted to run it on my server. Locally it runs fine but on the server it aborts with the error:
java.lang.NoClassDefFoundError: org/apache/flink/examples/java/ml/util/LinearRegressionData
In my Java project I imported the class with
import org.apache.flink.examples.java.ml.util.LinearRegressionData;
And I used the correct class at the import:
After the build I had a look into the Jar file. The following classes were included:
The /util/ folder is completely missing. My dependency-section in the pom file looks like the following:
<dependencies>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-java</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-core</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-clients</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-table</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-runtime</artifactId>
<version>0.9.0</version>
</dependency>
</dependencies>
When I have seen the package organization in the repository located at https://github.com/apache/flink/tree/release-0.9, I thought it would be possible to add the following lines to flink:
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-examples</artifactId>
<version>0.9.0</version>
</dependency>
But these dependencies cannot be resolved. Since Maven does not throw an error when performing a clean install, I think this is a dependency issue. I thought Maven would include all used imports automatically. How can I make this runnable on my server?
You should include ML example as follows:
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-java-examples</artifactId>
<version>0.9.0</version>
</dependency>
flink-examples is a parent pom module; not a jar module. How do you build your jar file? Using maven-jar-plugin? A regular mvn package or mvn install does not packages dependencies.
Using maven-jar-plugin requires to specify what you need to include using <include>. See here: https://maven.apache.org/plugins/maven-jar-plugin/examples/include-exclude.html
In your case it should be something like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Main-Class>org.apache.flink.examples.java.ml.LinearRegression</Main-Class>
</manifestEntries>
</archive>
<includes>
<include>org/apache/flink/examples/java/ml/*.class</include>
<include>org/apache/flink/examples/java/ml/util/*.class</include>
</includes>
</configuration>
</plugin>
You can also compare with https://github.com/apache/flink/blob/master/flink-examples/flink-java-examples/pom.xml
You also need to "pull" and unpack your dependencies into your project such that they can be re-packages using maven-dependency-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.9</version><!--$NO-MVN-MAN-VER$-->
<executions>
<execution>
<id>unpack</id>
<phase>prepare-package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.apache.flink</groupId>
<artifactId>flink-java-examples</artifactId>
<version>0.9.0</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>

Categories