Error generating maven documentation - java

When I run mvn site I get the error:
java.lang.NullPointerException
at org.codehaus.mojo.versions.ordering.MavenVersionComparator.innerGetSegmentCount(MavenVersionComparator.java:5
1)
at org.codehaus.mojo.versions.ordering.AbstractVersionComparator.getSegmentCount(AbstractVersionComparator.java:
27)
This appears to be a Maven bug, which according to the JIRA ticket has been resolved in version 1.2. I'm assuming this means version 1.2 of a particular plugin (probably the site plugin).
Does anyone know whether this fix has been released, and if so, how can I force Maven to use the version of the plugin that includes this fix?
Update
As suggested below, I added
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>1.2</version>
</plugin>
to my pom.xml. But I now get the following error instead:
java.lang.NullPointerException
at org.codehaus.mojo.versions.PluginUpdatesDetails.isDependencyUpdateAvailable(PluginUpdatesDetails.java:68)
at org.codehaus.mojo.versions.PluginUpdatesRenderer.renderSummaryTotalsTable(PluginUpdatesRenderer.java:132)
at org.codehaus.mojo.versions.PluginUpdatesRenderer.renderBody(PluginUpdatesRenderer.java:71)
Thanks,
Don

It's the Codehaus Versions Maven Plugin.
Here's the config with the version you need:
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>1.2</version>
<reportSets>
...
</reportSets>
</plugin>
</plugins>
</reporting>
Edit:
For the new error, this source code line (68) suggests that a dependency is referenced without a version. Try looking for a plugin without a <version>.
63 public boolean isDependencyUpdateAvailable()
64 {
65 for ( Iterator i = dependencyVersions.values().iterator(); i.hasNext(); )
66 {
67 ArtifactVersions versions = (ArtifactVersions) i.next();
68 if ( versions.getAllUpdates( UpdateScope.ANY, includeSnapshots ).length > 0 )
69 {
70 return true;
71 }
72 }
73 return false;
74 }

Related

maven dependency plugin throwing error even if I add flag ignoreunuseddeclareddependecy

I am trying to build my code and I am getting this error:
[WARNING] Unused declared dependencies found:
[WARNING] com:test-client:jar:v1.0-SNAPSHOT:compile
This is the configuration of the dependency plugin in my pom:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>analyze</id>
<goals>
<goal>analyze-only</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- <usedDependencies>-->
<!-- <usedDependency>com:test-client</usedDependency>-->
<!-- </usedDependencies>-->
<failOnWarning>true</failOnWarning>
<ignoreNonCompile>true</ignoreNonCompile>
<ignoredUnusedDeclaredDependencies>
<!-- <ignoredUnusedDeclaredDependency>*:test-client:*</ignoredUnusedDeclaredDependency>-->
</ignoredUnusedDeclaredDependencies>
</configuration>
</plugin>
I tried to add the test-client to the flag ignoredUnsedDeclaredDependecy (see the commented part) but still getting error.
I tried to set the failOnWarning flag to false but also I get same warning.
When I added this section it works.
<usedDependencies>
<usedDependency>com:test-client</usedDependency>
</usedDependencies>
But why the 2 other flags are not being taken?
Note that I am working in a multi module project and this is a child pom of a parent pom.
failOnWarning makes the maven build fail if a warning was generated, it doesn't remove or prevent the warnings. See https://maven.apache.org/plugins/maven-dependency-plugin/examples/failing-the-build-on-dependency-analysis-warnings.html
Regarding the configuration of exlusions, see https://maven.apache.org/plugins/maven-dependency-plugin/examples/exclude-dependencies-from-dependency-analysis.html
That gives an example like so;
<configuration>
<failOnWarning>true</failOnWarning>
<!-- ignore jsr305 for "used but undeclared", "declared but unused", and "non-test scoped" -->
<ignoredDependencies>
<ignoredDependency>com.google.code.findbugs:jsr305</ignoredDependency>
</ignoredDependencies>
<!-- ignore annotations for "used but undeclared" warnings -->
<ignoredUsedUndeclaredDependencies>
<ignoredUsedUndeclaredDependency>com.google.code.findbugs:annotations</ignoredUsedUndeclaredDependency>
</ignoredUsedUndeclaredDependencies>
<!-- ignore annotations for "unused but declared" warnings -->
<ignoredUnusedDeclaredDependencies>
<ignoredUnusedDeclaredDependency>com.google.code.findbugs:annotations</ignoredUnusedDeclaredDependency>
</ignoredUnusedDeclaredDependencies>
<!-- ignore annotations for "non-test scoped" warnings -->
<ignoredNonTestScopedDependencies>
<ignoredNonTestScopedDependency>com.google.code.findbugs:annotations</ignoredNonTestScopedDependency>
</ignoredNonTestScopedDependencies>
</configuration>
So your syntax should be correct.
Do you depend on the latest version of the plugin? If not, try to update the version number to the most recent one you have access to: https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-dependency-plugin
ignoredUnusedDeclaredDependencies was added in the plugin version 2.10 and ignoredNonTestScopedDependencies since 3.3.0.
Also check if your wildcard filter syntax is correct according to https://maven.apache.org/plugins/maven-dependency-plugin/examples/filtering-the-dependency-tree.html
I figured out what was the issue! my settings were override by the parent pom, why so? because in the parent pom the configuration is written under execution, however in my pom the configuration is outside execution (directly under plugin) when I moved the configuration in my plugin under the execution, my settings were taken into consideration

Is there a way to Debug why my executable JAR of a JavaFX-Project runs on my Computer but not on others ? (Using jdk 1.8._051)

I exportet a Jar of a JavaFX2 Project. It works fine, but when I run it on another machine there will be a
classDefNotFoundExeption: javafx.application.Application
Any hints how to tackle this Problem ?
This is my Manifest:
Class-Path: .
Main-Class: proj.view.Launcher
I also programmed Launcher that starts a Swing GUI in case JavaFX is not found.
Here is my Launcher Class
public class Launcher {
public static void main(String[] args) {
try {
Class c = javafx.application.Application.class;
proj.main.App.main(args);
}catch (NoClassDefFoundError e) {
String[] t = {"Swing Backup","Application start Error"};
MainFrame.remote(t);
}
}
}
The other computers are running on a Java installation that doesn't include JavaFX. It works on your machine because you do have JavaFX installed.
To test if javafx.application.Application is available, you need to use reflection, i.e.
boolean hasJavaFX;
try {
Class.forName("javafx.application.Application");
hasJavaFX = true;
} catch (ClassNotFoundException e) {
hasJavaFX = false;
}
if (hasJavaFX) {
MainFrame.remote(new String[] {"Swing Backup","Application start Error"});
} else {
proj.main.App.main(args);
}
You might get classDefNotFoundExeption: javafx.application.Application when you are running on machine having jdk above 11.
oracle has removed javaFX form JDK 11, hence need to provide dependency on javafx-controls module.
`<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>12-ea+9</version>
</dependency>`
add this to your dependency.
https://openjfx.io/
To me it looks like runnable jar issue if then same code is working through IDE's on those machines. You can try maven assembly plugin to pack your jar.
The Apache Maven Assembly Plugin allows users to aggregate the project output along with its dependencies, modules, site documentation, and other files into a single, runnable package.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>
package.your_main_class
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
I figured it out:
It was the User Path variable that pointed to a JDK10 bin.
We changed the Path. Now it works with "java -jar programm.jar"
but not with "java programm.jar"
but not with a Regular click on the file. But we wrote a batchFile that Starts the Application with "java -jar" and it works fine.
Has anyone a explanation for that behavior ?

Standalone Java Websocket client NoClassDefFoundError by ContainerProvider

I'm new to Java, but I have to use it to do a small WebSocket related project.
So, I installed JDK 1.8.0 and NetBeans 8.1 on my CentOS 7 in a VirtualBox.
I added the tyrus-standalone-client-jdk 1.12 plug-in in the pom.xml to make the standalone Websocket client, and it built fine. However, I ran into the error below:
[root#cet7 ~]# java -jar "/root/NetBeansProjects/Switchclient/target/Switchclient-1.0-SNAPSHOT.jar"
Exception in thread "main" java.lang.NoClassDefFoundError: javax/websocket/ContainerProvider
at org.sample.switchclient.Switchclient.main(Switchclient.java:21)
Caused by: java.lang.ClassNotFoundException: javax.websocket.ContainerProvider
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
[root#cet7 ~]# java -version
java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)
I did a bit more searching and found that the "fully qualified classname of the container implementation of ContainerProvider must be listed in the META-INF/services/javax.websocket.ContainerProvider file in the implementation JAR file" for the ServiceLoader API according to Oracle documentation. So, I added the serviceloader-maven-plugin to the pom.xml. The result was that it did generate the META-INF/services/javax.websocket.ContainerProvider file, but without any content, and the runtime error continued to persist. I tried to modify the contents bellow manually and re-pack it into a JAR but it did not worked:
org.glassfish.tyrus.container.inmemory.InMemoryContainerProvider
org.glassfish.tyrus.client.ClientManager
I've attached the Java file and the pom.xml. I've worked for hours and haven't a clue what the issue is, so any response to this thread will be appreciated.
Thank you very much.
===========LIST1: pom.xml===========
<?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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sample</groupId>
<artifactId>Switchclient</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>org.sample.switchclient.Switchclient</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>eu.somatik.serviceloader-maven-plugin</groupId>
<artifactId>serviceloader-maven-plugin</artifactId>
<version>1.0.6</version>
<configuration>
<services>
<param>javax.websocket.ContainerProvider</param>
</services>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.glassfish.tyrus.bundles</groupId>
<artifactId>tyrus-standalone-client-jdk</artifactId>
<version>1.12</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
===========LIST2: Switchclient.java===========
package org.sample.switchclient;
import java.net.URI;
import javax.websocket.ClientEndpoint;
import javax.websocket.ContainerProvider;
import javax.websocket.OnMessage;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;
#ClientEndpoint
public class Switchclient {
#OnMessage
public void onRemoteMessage (String message) {
System.out.println("Received msg: "+message);
}
public static void main(String[] args) {
WebSocketContainer container = null;
Session session = null;
try{
container = ContainerProvider.getWebSocketContainer();
session = container.connectToServer (Switchclient.class, URI.create("ws://localhost:8080/Switchserver/"));
}catch (Exception e) {
e.printStackTrace();
}
}
}
Basically, Tyrus requires Java EE. It's the reason you have to list a lot of dependencies in pom.xml. If you use Java SE and want to keep your project small, use another different WebSocket client library that depends on only Java SE. For example, nv-websocket-client (mine).
Just add the following dependency to pom.xml,
<dependency>
<groupId>com.neovisionaries</groupId>
<artifactId>nv-websocket-client</artifactId>
<version>1.13</version>
</dependency>
then try:
import com.neovisionaries.ws.client.*;
public class Switchclient
{
public static void main(String[] args) throws Exception
{
WebSocket websocket = new WebSocketFactory()
.createSocket("ws://localhost:8080/Switchserver/")
.addListener(new WebSocketAdapter() {
#Override
public void onTextMessage(WebSocket ws, String message) {
System.out.println("Received msg: " + message);
}
})
.connect();
// Don't forget to call disconnect() after use.
// websocket.disconnect();
}
}
I'm not sure what exactly caused the problem since I kept trying and problems kept jumping out during the past day. But finally here is it:
Client dependencies:
<dependency>
<groupId>javax.websocket</groupId>
<artifactId>javax.websocket-client-api</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.tyrus.bundles</groupId>
<artifactId>tyrus-standalone-client</artifactId>
<version>1.12</version>
</dependency>
<dependency>
<groupId>org.glassfish.tyrus</groupId>
<artifactId>tyrus-container-grizzly-client</artifactId>
<version>1.12</version>
</dependency>
at a first glance it seems javax.websocket-client-api should be enough but finally cyber said that ContainerProvider is not impediment.
Then, all built OK. (with different java codes from my original post, I tried a lot on including the source codes, but codes themselves don't matter that match here while the environment setup matters. They mostly based on the examples of Tyrus 1.9 user guide however.)
And the run from the NetBeans by maven was OK, but when I went to use "java -jar Switchclient.jar", same/similar problem jumped out saying problem with "Endpoint".
Finally (as a last try) I copied all those tar files included in the classpath (witch was generated by maven-jar-plugin by specifying "<addClasspath>true<addClasspath>" into one directory, and also copied the generated jar file in, then it worked:
[root#cet7 neededjars]# ls
grizzly-framework-2.3.22.jar tyrus-client-1.12.jar
grizzly-http-2.3.22.jar tyrus-container-grizzly-client-1.12.jar
grizzly-http-server-2.3.22.jar tyrus-core-1.12.jar
javax.websocket-api-1.1.jar tyrus-spi-1.12.jar
javax.websocket-client-api-1.1.jar tyrus-standalone-client-1.12.jar
Switchclient-1.1-SNAPSHOT.jar
[root#cet7 neededjars]# java -jar Switchclient-1.1-SNAPSHOT.jar
Received message: Hello world
That's it, dirty and but worked. and I'm at a new start. Again, I'm really new to java (one of those non-hard-tech guys, just pick it up in case of need); and it showed me the complicity of the community based development, especially in the case the technology is relatively new. dependencies and pitfall everywhere. That's is one part of the nature I guess...

Maven Pax Runner cannot parse provision file

if I have a profile defined as follows in the Maven plugin:
<plugin>
<groupId>org.ops4j</groupId>
<artifactId>maven-pax-plugin</artifactId>
<configuration>
<provision>
<param>--log=debug</param>
<param>--platform=felix</param>
<param>--profiles=compendium,web,war</param>
</provision>
</configuration>
</plugin>
then I get the following error:
Caused by: org.ops4j.pax.scanner.UnsupportedSchemaException: Provisioning scheme is not specified
at org.ops4j.pax.scanner.ProvisionSpec.<init>(ProvisionSpec.java:87)
at org.ops4j.pax.scanner.composite.internal.CompositeScanner.scan(CompositeScanner.java:156)
... 41 more
The plugin does not understands web an war profile. Why??

Getting maven project version and artifact ID from pom while running in Eclipse

I was looking up how to get the application name(artifact id) and version from maven pom or manifest when I came across this question Get Maven artifact version at runtime.
The above works for me when I package the project but I can't seem to get anything to work when I try to run the program using eclipse. I tried using the .properties method when building since I assumed that is not package dependent but I am still not getting a result. If anyone has an idea or solution to this problem it would be greatly appreciated.
My last attempt is below. This uses the manifest when packaged(which works) and trying to get the .properties file when running in eclipse.
String appVersion = getClass().getPackage().getImplementationVersion();
if(appVersion == null || "".equals(appVersion)) {
appVersion = Glob.getString(appVersion);
if(appVersion == null || "".equals(appVersion)) {
System.exit(0);
}
}
Create a property file
src/main/resources/project.properties
with the below content
version=${project.version}
artifactId=${project.artifactId}
Now turn on maven resource filtering
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
so that this file is processed into
target/classes/project.properties
with some content similar to this
version=1.5
artifactId=my-artifact
Now you can read this property file to get what you want and this should work every time.
final Properties properties = new Properties();
properties.load(this.getClassLoader().getResourceAsStream("project.properties"));
System.out.println(properties.getProperty("version"));
System.out.println(properties.getProperty("artifactId"));
An easy solution with maven 4 is now to add a VersionUtil static method in your package:
package my.domain.package;
public class VersionUtil {
public static String getApplicationVersion(){
String version = VersionUtil.class.getPackage().getImplementationVersion();
return (version == null)? "unable to reach": version;
}
}
The thing is you need this ´mave-war-plugin´ in the project's pom, saying you want to add addDefaultImplementationEntries:
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
...
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
...
Then call the VersionUtil.getApplicationVersion() from some place in your code.

Categories