Problem with building jar file with dependencies - java

I need to export a jar file which could be execute in server. I try many of answers in this site and other site, but I guess my main problem is :
[ERROR] Failed to parse plugin descriptor for mybot:energyBot:0.0.1-SNAPSHOT (/Users/narges/.m2/repository/bot/mBot/0.0.1-SNAPSHOT/energyBot-0.0.1-SNAPSHOT.jar): No plugin descriptor found at META-INF/maven/plugin.xml -> [Help 1]
Here is part of my pom.xml:
<plugins>
<plugin>
<groupId>mybot</groupId>
<artifactId>myBot</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>$/Users/narges/eclipse-workspace/Bot/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

Use this in your pom.xml, plugin works fine with boot applications as well.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<outputDirectory>/your/path</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>

You probably wrote myBot/energyBot yourself? You added it as a Maven plugin, but it seems like it is not a Maven plugin, but maybe just a plain jar.
If you want to put all dependencies into your jar, you need the assembly plugin or the shade plugin.

Related

Configuring the maven java-docs plugin for multi module projects(Aggregate)

I would like to set up the maven java-docs plugin in my project to create an aggregated report that includes only some classes from some of the modules and output the report to a folder of choice.
I have already tried to work with the Maven documentation here however whats indicated there does not seem to work for me.
I have tried the following configuration in the past and ran it as:
mvn javadoc:javadoc, or even javadoc:aggregate with the following parent/child pom configurations:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.0</version>
<inherited>false</inherited>
<configuration>
<!-- Default configuration for all reports -->
</configuration>
<executions>
<execution>
<id>aggregate</id>
<goals>
<goal>aggregate</goal>
</goals>
<phase>package</phase>
<configuration>
</configuration>
</execution>
</executions>
</plugin>
I have used something like this in the past:
parent pom.xml
<pluginManagement>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</pluginManagement>
...
<build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<!-- Default configuration for all reports -->
</configuration>
<executions>
<execution>
<id>aggregate</id>
<goals>
<goal>aggregate</goal>
</goals>
<phase>site</phase>
<configuration>
<skip>false</skip>
</configuration>
</execution>
</executions>
</plugin>
</build>
Desired child module pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<skip>false</skip>
<noqualifier>all</noqualifier>
<sourceFileIncludes>
<include>**\/\Class1.java</include>
<include>**\/\Class2.java</include>
<include>**\/\Interface3.java</include>
<include>**\/\Class4.java</include>
</sourceFileIncludes>
<reportOutputDirectory>${project.parent.basedir}/..</reportOutputDirectory>
<destDir>java-docs</destDir>
</configuration>
</plugin>
</plugins>
</build>
This configuration works fine if I am only generating from one single module, however once another child module is picked and configured as the one shown before, running mvn javadoc:aggregate continues to generate the docs for module 1 only, and module 2 gets ignored(or maybe even overriden)
Has anyone worked with a similar scenario, a multi module project structured like so:
ParentFolder
. . . module1
pom.xml
. . . module3
pom.xml
. . . module4
pom.xml
pom.xml
and have succeeded generating an aggregated java docs report using the maven java docs plugin, while excluding some classes and outputting the results to a folder of their choice?
Any help with this would be greatly appreciated!
Do you have one parent POM that contains both plugin config for the child POMs, and module definitions? If so, you may want to consider separating this POM into a separate aggregator (module definitions) and parent (anything else in the current POM that should be shared with children).
This answer goes into a lot more detail about Maven build order and why the behavior occurs.
The aggregator POM will also hold the configuration for child module data that should be aggregated, such as Javadoc.

Java google checkstyle Maven

I'm trying to configure my Maven project to use google java check style with the following configuration:
google_checks.xml: https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml
pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<id>checkstyle</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<configLocation>google_checks.xml</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<configuration>
<configLocation>google_checks.xml</configLocation>
<failOnViolation>false</failOnViolation>
<enableFilesSummary>false</enableFilesSummary>
</configuration>
</plugin>
</plugins>
</reporting>
It seems to run mvn checkstyle:check fine at first. But after a few runs I start getting the following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check
(default-cli) on project PROJECT: Failed during checkstyle configuration: cannot initialize
module TreeWalker - Token "METHOD_REF" was not found in Acceptable tokens list in check
com.puppycrawl.tools.checkstyle.checks.whitespace.SeparatorWrapCheck -> [Help 1]
What does that mean? Why does it only happen some times and how do I get rid of it?
Token "METHOD_REF" was not found in Acceptable tokens list in check
com.puppycrawl.tools.checkstyle.checks.whitespace.SeparatorWrapCheck
You are trying to use a newer configuration with an old version of Checkstyle.
The configuration at https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml is in master which is dependent on the snapshot version of checkstyle.
If you are using google configuration without any modifications, you need to use the one that comes embedded in checkstyle. See https://stackoverflow.com/a/35486365/1016482
Otherwise you can integrate a newer version of checkstyle to work with maven. See https://stackoverflow.com/a/27359107/1016482
I was using version 3.0.0 (which is the newest one right now) of the maven-checkstyle-plugin and I still got the error. I solved it by adding the following dependency to the plugin.
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.11</version>
</dependency>

maven generated jaxb classes - ClassNotFoundException

I have a maven model project, where I am generating jaxb class by maven command - clean install
and the jaxb classes are generated under target folder and jar file is generating under .m2 repository folder.
Now on my other project adding this jar as a dependency with proper group id and artifactId.
But I am getting ClassNotFoundException and compile error for those generated jaxb classes.
I am updating my question to add more details.
The Pom File of Model Project.
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.3</version>
<executions>
<execution>
<id>spf-ssp-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<generateDirectory>${project.build.directory}/jaxbclasses/pqr/xyz</generateDirectory>
<generatePackage>abc.vo.apply.v1</generatePackage>
<schemaIncludes>
<include>MyXSD.xsd</include>
</schemaIncludes>
</configuration>
</execution>
</executions>
<configuration>
<schemaDirectory>src/main/resources</schemaDirectory>
<extension>true</extension>
<args>
<arg>-XtoString</arg>
<arg>-Xequals</arg>
<arg>-XhashCode</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.4</version>
</plugin>
</plugins>
</configuration>
</plugin>
</plugins>
</build>
On clean install it generates the class files under.
target
jaxbclasses
pqr
xyz
with the package name - abc.vo.apply.v1
I have another Two Maven project(jar), suppose as, A & B.
Now I can use the jaxb model project as a maven dependency, and it compile fine.
Now My Web project is not a Maven project - it is a Liferay based on Ant.
I manually copy the A, B and The Jaxb Model project in to lib folder.
It compile fines. but I am getting ClassNotFoundException.
I am adding another answer, which I think is more accurate.
In order to make your JAXB project compile, I had to add this dependency:
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.5</version>
</dependency>
which obviously won't be automatically part of your classpath for Liferay.
When I ran mvn dependency:list, I got this:
org.jvnet.jaxb2_commons:jaxb2-basics-tools:jar:0.6.4:compile
org.jvnet.jaxb2_commons:jaxb2-basics:jar:0.6.4:compile
commons-lang:commons-lang:jar:2.2:compile
commons-logging:commons-logging:jar:1.1.1:compile
com.google.code.javaparser:javaparser:jar:1.0.8:compile
org.jvnet.jaxb2_commons:jaxb2-basics-runtime:jar:0.6.4:compile
commons-beanutils:commons-beanutils:jar:1.7.0:compile`
which means that you need to put these in the lib directory of your Liferay installation as well.
This is most likely due to the fact that the target directory is never included in the jar file by default. Try configuring the JAXB classes to be generated under (say) target/generated. Then, add this to the build plugin section of the POM:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>add-java-sources</id>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

JavaDoc will not publish on jenkins

I have an aggregator project built in jenkins and I want to publish javadocs. So I installed javadoc plugin and changed my parent pom as follows:
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<aggregate>true</aggregate>
<outputDirectory>${project.build.directory}/apidocs</outputDirectory>
</configuration>
I tried different configurations but this is the only one that won't fail the build. With this configuration the build doesn't fail but no javadocs are to be found. Am I missing something here? Does anyone has the same problem?
First you should use the aggregate goal instead of the parameter cause it's marked deprecated.
Furthermore you should configure javadoc plugin like the following in your root pom like this:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<!-- Default configuration for all reports -->
...
</configuration>
<executions>
<execution>
<id>aggregate</id>
<goals>
<goal>aggregate</goal>
</goals>
<phase>package</phase>
<configuration>
<!-- Specific configuration for the aggregate report -->
...
</configuration>
</execution>
...
</executions>
</plugin>
...
</plugins>
</build>
...
</project>
Afterwards you should be able just by:
mvn clean package
This will result in a folder in the root target/apidoc which contains the created aggregated javadocs.
I found a way to publish the javadocs as .jar. I used the above pom configuration with the small change:
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
It publishes javadocs as .jars for every sub-module. The javadocs are to be found in the sub-module directory not in the parent directory.

Maven Javadoc aggregate-jar plugin fails because of unresolved dependencies

I have multi-module Maven project in which I run the maven-javadoc-plugin to generate javadoc. In my parent pom.xml I have defined the plugin build as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<!-- Default configuration for all reports -->
</configuration>
<executions>
<execution>
<id>aggregate</id>
<goals>
<goal>aggregate-jar</goal>
</goals>
<phase>install</phase>
<configuration>
<!-- Specific configuration for the aggregate report -->
</configuration>
</execution>
</executions>
</plugin>
When I run mvn clean install the build fails with unresolved dependencies, but I see the following warning:
[WARNING] The dependency:
[my.application:my-module:jar:1.7.1] can't be resolved but
has been found in the reactor (probably snapshots). This dependency
has been excluded from the Javadoc classpath. You should rerun javadoc
after executing mvn install.
As I am currently building my-module 1.7.1, I would assume Maven to detect this and run the aggregate-jar after building my-module, but for some reason it expects my-module to already be installed in a repo.
My Maven version is 3.0.4. Please keep in mind that I am new to Maven builds so this may be a very simple question, but I was not able to find any answer.
Some observations:
The build succeeds if I first run mvn clean install without the javadoc plugin aggregate-jar goal
The javadoc plugin aggregate goal runs fine.
This bug refers exactly to my issue, but should have been solved in Maven 3 (2010)
I run this command in my parent pom and this is how I do it without issues:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
When I want to generate the docs, I do mvn javadoc:aggregate

Categories