how to exclude GWT dependency code from OSGI bundle generated by MAven+BND? - maven

I have several Maven modules with Vaadin library dependency in the root pom.xml file.
I'm trying to build a set of OSGI bundles (1 per Maven module) using Maven+BND.
I added this to my "root" pom.xml file:
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin</artifactId>
<version>6.6.6</version>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.osgi.core</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
unfortunately, the resulting JAR files (bundles) include GWT (com.google.gwt) classes. This
1) makes the bundles huge, with lots of duplicated dependencies.
2) generated thousands of build warnings about "split packages".
QUESTION: how to prevent adding GWT classes into my Jar files?
I tried setting "scope" of GWT to "provided", setting "type" to "bundle", and even optional=true - didn't help.
here's the part of my root pom.xml, which is responsible for Vaadin/GWT stuff:
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.5</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>mycompany.*</Export-Package>
<Private-Package>*.impl.*</Private-Package>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<!-- <Bundle-Activator>com.alskor.publicpackage.MyActivator</Bundle-Activator>-->
</instructions>
</configuration>
</plugin>
<!-- Compiles your custom GWT components with the GWT compiler -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<!-- Version 2.1.0-1 works at least with Vaadin 6.5 -->
<version>2.3.0-1</version>
<configuration>
<!-- if you don't specify any modules, the plugin will find them -->
<!--modules>
..
</modules-->
<webappDirectory>${project.build.directory}/${project.build.finalName}/VAADIN/widgetsets
</webappDirectory>
<extraJvmArgs>-Xmx512M -Xss1024k</extraJvmArgs>
<runTarget>clean</runTarget>
<hostedWebapp>${project.build.directory}/${project.build.finalName}</hostedWebapp>
<noServer>true</noServer>
<port>8080</port>
</configuration>
<executions>
<execution>
<goals>
<goal>resources</goal>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Updates Vaadin 6.2+ widgetset definitions based on project dependencies -->
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<configuration>
<!-- if you don't specify any modules, the plugin will find them -->
<!--
<modules>
<module>${package}.gwt.MyWidgetSet</module>
</modules>
-->
</configuration>
<goals>
<goal>update-widgetset</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>

The wildcards in your Export-Package and Private-Package statements strike me as exceedingly dangerous. It's possible that the GWT packages are being dragged in because of the *.impl.* pattern in Private-Package.
Also you should never use wildcards in Export-Package: exports should be tightly controlled and versioned.

use mvn dependency:tree to see where the gwt dependency comes from
Add an <excludes/> element with an appropriate <exclude/> to the dependency in question to suppress it.

I've had similar problem, as final war file exceeded almost 90MB !
One of the culprit was aforementioned jar, so I did this :
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>widgetset</artifactId>
<version>3.2</version>
<exclusions>
<exclusion>
<groupId>com.vaadin.external.gwt</groupId>
<artifactId>gwt-user</artifactId>
</exclusion>
</exclusions>
</dependency>
...
</dependencies>

Related

Jacoco + Surefire Maven plugins always show 0% coverage

I got a multi-module maven project on which i want to generate a jacoco report with the unit coverage. Currently i am using arqullian surefire and jacoco maven plugins, which both are defined in only one module. The tests run on a JBoss EAP 7.2
Although the jacoco report is generated, i always get a 0% coverage on all my test classes which are deployed as an archive org.jboss.shrinkwrap.api.spec.WebArchive on my JBoss server even though there are several methods covered by the Unit tests.
Important: Other unit tests performed without a deployment, do show some coverage on the report
Below is my maven configuration
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<skip>${skipTests}</skip>
<argLine>${surefireArgLine}</argLine>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Below my dependencies used:
<dependency>
<groupId>org.dbunit</groupId>
<artifactId>dbunit</artifactId>
<version>2.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-api-maven</artifactId>
<version>3.1.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
<version>3.1.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-spi</artifactId>
<version>3.1.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.core</artifactId>
<version>0.8.5</version>
<scope>test</scope>
</dependency>
Arqulian XML
<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.org/schema/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<!-- Force the use of the Servlet 3.0 protocol with all containers, as it is the most mature -->
<defaultProtocol type="Servlet 3.0" />
<!-- Example configuration for a remote JBoss EAP 7 instance -->
<container qualifier="jboss" default="true">
<!-- If you want to use the JBOSS_HOME environment variable, just delete the jbossHome property -->
<configuration>
<!-- <property name="javaVmArguments">${jacoco.agent}</property> -->
</configuration>
</container>
</arquillian>
On one of my configurations (not the above), i remember seeing a warning that the ${jacoco.agent} was not used. So i did comment it out again.
When running the mvn clean install goal, in my console logs i see following variables set to the surefireArgLine
[INFO] --- jacoco-maven-plugin:0.8.5:prepare-agent (pre-unit-test) # alis-ejb ---
[INFO] surefireArgLine set to -javaagent:C:\\Users\\user\\.m2\\repository\\org\\jacoco\\org.jacoco.agent\\0.8.5\\org.jacoco.agent-0.8.5-runtime.jar=destfile=c:\\Projects\\Projectname\\ejb-module\\target\\coverage-reports\\jacoco-ut.exec
All my tests are executed normaly and i am able to generate a surefire report command with surefire-report that lists all the unit test executions. I am thinking if am missing a mvn goal for jacoco that calculates the coverage, but it looks that i am still missing something
Update 1: I start to believe that the issue is created due to the usage of Arquilian, and i should use the pre-integration-test phases instead. But not sure yet.
Update 2: I just noticed that for one of my Unit tests i see some coverage. The difference between this unit test and the rest is the one Class containing the tests of which a coverage as shown, are simple Unit tests, whereas for the rest of my Test classes on which i do not get a coverage report from Jacoco a org.jboss.shrinkwrap.api.spec.WebArchive deployment is created. Some more details on this. 90% of my tests, are of this structure. A webarchive is created and deployed on JBoss EAP 7.

How to execute JAVA FX 11 JAR without providing VM args via CMD

Java : JDK 12
Build Tool : Maven
IDE : Eclipse
OS : Windows
I have a simple piece of java FX 11 code which displays a simple blank screen.
I have made deployed an executable jar using eclipse.
It works fine when i give the following command using CMD:
As it is visible that i need to provide the modules at time of execution of JAR file.
If we skip this step we get JAR direct execution error:
As I have already tried using maven as :
---Maven pom.xml
<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>com.proj1</groupId>
<artifactId>Proj1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<type>maven-plugin</type>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>13-ea+7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<compilerArgs>
<arg>--add modules</arg><arg> javafx.controls,javafx.fxml,javafx.graphics</arg>
</compilerArgs>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.1</version>
<configuration>
<mainClass>org.openjfx.App</mainClass>
</configuration>
</plugin>
</plugins>
</build>
But even when this is done the exported executable JAR still demands the arguments.
Is it possible to somehow avoid this through CMD and make the JAR executable by simply double clicking it using Maven.
I am not asking on how to solve the javaFx runtime exception but on how to solve it by adding dependencies so that when the JAR is distributed the client does not have to pass the runtime arguments and get the job done by simple clicks.
With the JavaFX maven plugin you can execute two goals: run and jlink. The former will just run the project with the required arguments (--module-path, --add-modules), so you can run on command line:
mvn clean javafx:run
Of course, this is not intended for distribution.
javafx:jlink
However, if your project is modular (i.e you have a module-info.java file), you can set your plugin like:
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.2</version>
<configuration>
<mainClass>hellofx/org.openjfx.App</mainClass>
<launcher>app</launcher>
<jlinkImageName>appDir</jlinkImageName>
<jlinkZipName>appZip</jlinkZipName>
</configuration>
</plugin>
and run:
mvn clean javafx:jlink
It will generate a custom runtime image with your project that you can distribute, and you can add a launcher or even zip it. Once extracted you will only need this to run it:
target/appdir/app
See the plugin options here.
Shade plugin
You can also use the maven-shade-plugin.
As explained here you will need a main class that doesn't extend from Application:
Launcher.java
package org.openjfx;
public class Launcher {
public static void main(String[] args) {
App.main(args);
}
}
And now you can add the shade plugin to your pom:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation=
"org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.openjfx.Launcher</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
Run mvn clean package, and it will generate your fat jar that you can distribute and run as:
java -jar target/hellofx-1.0-SNAPSHOT.jar
Cross platform
Note that in both cases (jlink or shade plugin), you will have a jar that you can distribute only to run on the same platform as yours.
However you can make it multiplaform if you include the dependencies for other platforms as well:
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>12.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>12.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>12.0.1</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>12.0.1</version>
<classifier>linux</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>12.0.1</version>
<classifier>mac</classifier>
</dependency>

Manually creating a deployable JAR for Liferay

I created a liferay workspace in gradle format and it basically only contains a theme and a TemplateContextContributor-module.
Now I want to build a maven "wrapper" around both artifacts to make them compatible with some other maven-processes/-plugins while keeping the original gradle structure. I dont want to use the liferay-maven-plugin or maven-tools to build those artifacts, because it seems to behave differently from the gradle/gulp toolset when it comes to compiling scss for example.
So I created some POMs from scratch for
Theme
TemplateContextContributor-Module
First off I will take about the mechanism for the theme, which is already working:
That wrapper uses the maven-war-plugin to bundle the contents of the build/-folder, where the previously built gradle artifact resides, into a WAR-file that can be deployed by Liferay without problems.
theme pom.xml:
<properties>
<src.dir>src</src.dir>
<com.liferay.portal.tools.theme.builder.outputDir>build</com.liferay.portal.tools.theme.builder.outputDir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
[...]
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<webResources>
<resource>
<directory>${com.liferay.portal.tools.theme.builder.outputDir}</directory>
<excludes>
<exclude>**/*.sass-cache/</exclude>
</excludes>
</resource>
</webResources>
</configuration>
</plugin>
However, I am having difficulties creating a OSGI-Compatible JAR-File for the module contents. It seems that only the META-INF/MANIFEST.MF does not contain the right information and I seemingly cannot generate it in a way that Liferay (or OSGI) understands.
this is the module pom.xml dependencies and plugins that I tried:
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.ds-annotations</artifactId>
<version>1.2.10</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay</groupId>
<artifactId>com.liferay.gradle.plugins</artifactId>
<version>3.9.9</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>com.liferay.portal.kernel</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
[...]
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<goals>
<goal>bnd-process</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bndlib</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>com.liferay</groupId>
<artifactId>com.liferay.ant.bnd</artifactId>
<version>2.0.48</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<version>1.25.0</version>
<executions>
<execution>
<id>generate-scr-scrdescriptor</id>
<goals>
<goal>scr</goal>
</goals>
</execution>
</executions>
</plugin>
I was able to create a JAR using the above but its' META-INF/MANIFEST.MF is not identical to the one produced by the gradle build:
I guess that's why Liferay does not deploy it. The log says "processing module xxx ....", but that never ends and the module does not work in Liferay.
These are the plugins I have tried in different combinations so far:
maven-build-plugin
maven-scr-plugin
maven-jar-plugin
maven-war-plugin
maven-compiler-plugin
Any help in creating a liferay-deployable module JAR would be great.
I'm not sure why you're manually building a maven wrapper for the Template Context Contributor. The Liferay (blade) samples are available for Liferay-workspace, pure Gradle as well as for Maven. I'd just go with the standard and not worry about re-inventing the wheel.
To make this answer self-contained: The current pom.xml listed in the Template Context Contributor plugin is:
<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>
<artifactId>template-context-contributor</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<parent>
<groupId>blade</groupId>
<artifactId>parent.bnd.bundle.plugin</artifactId>
<version>1.0.0</version>
<relativePath>../../parent.bnd.bundle.plugin</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>com.liferay.portal.kernel</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>com.liferay.blade.template.context.contributor-${project.version}</finalName>
</build>
</project>

How to exclude a dependency defined in the pom.xml from a plugin defined in the same pom

I have a pom.xml in which I have a dependency defined as:
<dependency>
<groupId>abc.xyz.pig</groupId>
<artifactId>pig</artifactId>
<version>10</version>
<scope>provided</scope>
</dependency>
I want to define a new plugin in the same file, for which I need a higher version of the same dependency. How do I make my plugin use a higher version of the dependency and ignore the lower version defined above?
I tried adding the dependency of the newer version in my plugin definition like this, but it didn't work:
<plugin>
<groupId>my_plugin</groupId>
<artifactId>my_plugin_artifact</artifactId>
<version>0.1.1</version>
<executions>
<execution>
<goals>
<goal>my_plugin_goal</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>abc.xyz.pig</groupId>
<artifactId>pig</artifactId>
<version>11</version>
</dependency>
</dependencies>
</plugin>

How can I compile and run my Custom Doclet class in my project?

I'm trying to dump all class javadoc comment (preferabbly subclasses of a libraries WebPage class) at compile time into a .properties file in the format classname=comment.
So far I have:
created doclet class SiteMapDoclet
the class is defined to scan all the javadocs in the project and dump them to a .properties file
Added the necessary configs to my pom.xml for it to work.
Versions: Java 1.6.0.21, Maven 2.2.1
Problem:
mvn site returns:
Embedded error: Error rendering Maven report:
Exit code: 1 - java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at us.ak.state.revenue.cssd.Personnel.utils.SiteMapDoclet.<clinit>(SiteMapDoclet.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
I tried setting the jars as AdditionalDependencies even though they are normal dependencies for my project.
I also tried adding the paths to the jars I expect my class to need as part of the bootclasspath.
the reporting section of my pom.xml looks like this:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<reportSets>
<reportSet>
<id>html</id>
<reports>
<report>javadoc</report>
</reports>
</reportSet>
<reportSet>
<id>siteMap</id>
<configuration>
<doclet>
us.ak.state.revenue.cssd.Personnel.utils.SiteMapDoclet
</doclet>
<docletPath>${project.build.outputDirectory}</docletPath>
<destDir>SiteMap</destDir>
<author>false</author>
<useStandardDocletOptions>false</useStandardDocletOptions>
<!-- there has got to be a better way to do this! -->
<!-- how can I fix the CSSD-Web - Base to use a proper manifest file? -->
<bootclasspath>
${bootClassPath};
${env.CLASSPATH};
${m2Repository}/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar;
${m2Repository}/org/apache/wicket/wicket-core/${wicket.version}/wicket-core-${wicket.version}.jar;
${m2Repository}/us/ak/state/revenue/cssd/CSSD-Web/${CSSDWebBase.version}/CSSD-Web-${CSSDWebBase.version}.jar
</bootclasspath>
<additionalDependencies>
<additionalDependency>
<groupId>us.ak.state.revenue.cssd</groupId>
<artifactId>CSSD-Web</artifactId>
<version>${CSSDWebBase.version}</version>
</additionalDependency>
<additionalDependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-core</artifactId>
<version>${wicket.version}</version>
</additionalDependency>
<additionalDependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</additionalDependency>
<additionalDependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</additionalDependency>
</additionalDependencies>
<name>SiteMapDoclet</name>
<description>Page Descriptions for SiteMap generation</description>
</configuration>
<reports>
<report>javadoc</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
NOTE:
${m2Repository} is defined as a property higher up the file,
defined as ${env.USERPROFILE}/.m2/repository
${bootClassPath} is defined as a property higher up the file,
defined as ${env.JRE_6_HOME}\lib\rt.jar;${env.JAVA_HOME}\lib\tools.jar;
How can i fix the NoClassDefFoundError?
Additionally I would like my SiteMap file to run as a part of the normal build process,
after compile but before package.
I've tried defining this in build, but the javadoc doesn't get created and I don't see any logging output from my Doclet.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>build-siteMap-Descriptions</id>
<phase>process-classes</phase>
</execution>
</executions>
</plugin>
UPDATE:
Thanks to #ben75 's suggestion. I've removed the <reporting> section of my pom.xml and now have the process failing during build. I added <goals> and copied the <configuration> section from <reporting>.
It's still throwing the NoClassDefFoundError but it's happening on build where I want it to. I tried adding:
<includeDependencySources>true</includeDependencySources>
<dependencySourceIncludes>
<dependencySourceInclude>org.apache.wicket:wicket-core:*</dependencySourceInclude>
<dependencySourceInclude>org.apache.commons.logging:*</dependencySourceInclude>
<dependencySourceInclude>us.ak.state.revenue.cssd:CSSD-Web:*</dependencySourceInclude>
</dependencySourceIncludes>
To the configuration section, but that didn't work.
You can try to put your <additionalDependencies> as plugin dependendencies:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<dependencies>
<dependency>
<groupId>us.ak.state.revenue.cssd</groupId>
<artifactId>CSSD-Web</artifactId>
<version>${CSSDWebBase.version}</version>
</dependency>
...
To attach javadoc plugin to your normal build process, I think you just need to specify the goal and preferably attaching it to prepare-package phase (so that javadoc is not generated when you simply run the test phase):
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>attach-javadoc</id>
<phase>prepare-package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Building upon #ben75s Excellent Advice I was able to get it to finally run.
This "works". It feels wrong and I'd love to see a better method.
Here's what I did:
Defined the plugin in the build section with the javadoc goal.
made sure tools.jar and rt.jar are in the <bootclasspath>
defined the <docletPath> as \;.;${project.build.outputDirectory};
the \;.; are necessary because maven doesn't append correctly
also had to explicitly add the path to some of the packages here to prevent inheritence of conflicting versions. (Specifically of Log4J)
defined <docletArtifacts> with the packages for the classes throwing the NoClassDefFoundError
My plugin now looks like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>build-siteMap-Descriptions</id>
<phase>process-classes</phase>
<goals>
<!--<goal>aggregate</goal>-->
<goal>javadoc</goal>
</goals>
<configuration>
<doclet>
us.ak.state.revenue.cssd.Personnel.utils.SiteMapDoclet
</doclet>
<!-- the initial '\;.;' is required
because maven doesn't separate the path statements properly
The 5 packages are necessary
because otherwise slf4j complains about multiple bindings
-->
<docletPath>
\;.;${project.build.outputDirectory};
${m2Repository}/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar;
${m2Repository}/log4j/log4j/1.2.16/log4j-1.2.16.jar;
${m2Repository}/log4j/apache-log4j-extras/1.1/apache-log4j-extras-1.1.jar;
${m2Repository}/us/ak/state/revenue/cssd/CSSD-Web/${CSSDWebBase.version}/CSSD-Web-${CSSDWebBase.version}.jar;
${m2Repository}/org/apache/wicket/wicket-core/${wicket.version}/wicket-core-${wicket.version}.jar;
${m2Repository}/org/apache/wicket/wicket-util/${wicket.version}/wicket-util-${wicket.version}.jar;
</docletPath>
<docletArtifacts>
<!--
<docletArtifact>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</docletArtifact>
-->
<docletArtifact>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.2</version>
</docletArtifact>
<!-- how do I fix the download errors? -->
<!--
<docletArtifact>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.2</version>
</docletArtifact>
-->
<!--
<artifact>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</artifact>
-->
<!--
<docletArtifact>
<groupId>log4j</groupId>
<artifactId>apache-log4j-extras</artifactId>
<version>1.1</version>
</docletArtifact>
<docletArtifact>
<groupId>us.ak.state.revenue.cssd</groupId>
<artifactId>CSSD-Web</artifactId>
<version>${CSSDWebBase.version}</version>
</docletArtifact>
<docletArtifact>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-core</artifactId>
<version>${wicket.version}</version>
</docletArtifact>
-->
</docletArtifacts>
<!-- the initial '\;.;' is required
because maven doesn't separate the path statements properly -->
<bootclasspath>
\;.;
${bootClassPath};
${env.CLASSPATH};
</bootclasspath>
<destDir>SiteMap</destDir>
<author>false</author>
<!-- don't print the packages/classes it's running on -->
<quiet>true</quiet>
<debug>true</debug> <!-- save options -->
<useStandardDocletOptions>false</useStandardDocletOptions>
<name>SiteMapDoclet</name>
<description>Page Descriptions for SiteMap generation</description>
</configuration>
</execution>
</executions>
</plugin>

Resources