I'm using maven-webstart-plugin to generate 2 JNLP (jnlpA and jnlpB), configured as 2 executions. The project, has 2 dependencies:
dependencyA.jar (that depends of some commons and others as A1.jar, A2.jar, A3.jar...)
dependencyB.jar (that depends of some commons and others as B1.jar, B2.jar, B3.jar...).
I need that jnlpA has as dependencies dependencyA.jar, commons and A1.jar, A2.jar, A3.jar... And jnlpB dependencyB.jar, commons and B1.jar, B2.jar, B3.jar... I don't know how to do this with maven-webstart-plugin.
I have tried with this:
Use the plugin property called "excludeTransitive" to false (default). In this case both JNLP will have all dependencies.
Change "excludeTransitive" to true, in this case both JNLP will only have dependencyA.jar and dependencyB.jar as dependencies.
With "excludeTransitive" to false (default), use the options exclude and include that the plugin allow to use in each execution:
If I use exclude in the execution of jnlpA, and I exclude dependencyB.jar, the jnlpA still has as dependenci B1.jar, B2.jar... I.E. only exclude the dependency and not all its transitive dependencies.
If I use include in the execution of jnlpA, and I include dependencyA.jar, the A1.jar, A2.jar... are not included. I.E. only include this dependency and not all its transitive dependencies.
So, my problem is that I need to include or exclude a dependency in a execution but with all its transitive dependencies.
An example of my pom when I was trying option 3 was:
<?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>
<artifactId>MyJnlp</artifactId>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>webstart-maven-plugin</artifactId>
<version>1.0-beta-3</version>
<executions>
<execution>
<id>install-jnlp</id>
<phase>process-resources</phase>
<goals>
<goal>jnlp-inline</goal>
</goals>
<configuration>
<workDirectory>target/dist</workDirectory>
<jnlp>
<inputTemplate>src/main/jnlp/jnlpA-template.vm</inputTemplate>
<outputFile>jnlpA.jnlp</outputFile>
<mainClass>Start</mainClass>
</jnlp>
<dependencies>
<excludes>
<exclude>xxx:dependencyB</exclude>
</excludes>
</dependencies>
</configuration>
</execution>
<execution>
<id>uninstall-jnlp</id>
<phase>process-resources</phase>
<goals>
<goal>jnlp-inline</goal>
</goals>
<configuration>
<workDirectory>target/dist</workDirectory>
<jnlp>
<inputTemplate>src/main/jnlp/jnlpB-template.vm</inputTemplate>
<outputFile>jnlpB.jnlp</outputFile>
<mainClass>Uninstaller</mainClass>
</jnlp>
<dependencies>
<excludes>
<exclude>xxx:dependencyA</exclude>
</excludes>
</dependencies>
</configuration>
</execution>
</executions>
<configuration>
<excludeTransitive>false</excludeTransitive><resourcesDirectory>${project.basedir}/src/main/jnlp/resources</resourcesDirectory>
<jnlp>
<inputTemplateResourcePath>${project.basedir}</inputTemplateResourcePath>
</jnlp>
<gzip>true</gzip>
<makeArchive>false</makeArchive>
<outputJarVersions>false</outputJarVersions>
<verbose>true</verbose>
<encoding>ISO-8859-1</encoding>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>xxx</groupId>
<artifactId>dependencyA</artifactId>
<version>1.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>xxx</groupId>
<artifactId>dependencyB</artifactId>
<version>1.0</version>
<scope>runtime</scope>
</dependency>
</dependencies>
Related
This question already has answers here:
How can I create an executable/runnable JAR with dependencies using Maven?
(33 answers)
Closed 3 years ago.
How to make Maven include the JDBC driver for Postgres inside my app's .jar file?
I added this dependency element to the <dependencies> element in my POM.
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.8</version>
</dependency>
The IntelliJ IDE shows the driver was successfully downloaded, as it is listed in the "External Libraries" item of my Project pane. And my code can use the JDBC classes such as PGSimpleDataSource.
When I build, if I look inside the resulting .jar file, there is no JDBC driver included.
My project is driven by Maven, using the maven-archetype-quickstart archetype. I did update all the version numbers within the POM to the latest. My only other change was to add the following to get the manifest file of the JAR to specify a main class.
<configuration>
<archive>
<manifest>
<mainClass>work.basil.example.App</mainClass>
</manifest>
</archive>
</configuration>
I thought that Maven by default would bundle all dependencies inside the resulting JAR file. That is the behavior I have seen in building Vaadin web apps. Is that not the case more generally? Or is the JDBC driver special and being omitted for some reason.
If it helps, here is the entire POM.
<?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.example</groupId>
<artifactId>tryjdbc</artifactId>
<version>1.0-SNAPSHOT</version>
<name>tryjdbc</name>
<description>A simple tryjdbc.</description>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>13</maven.compiler.source>
<maven.compiler.target>13</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.6.0-M1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.8</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.8.2</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<archive>
<manifest>
<mainClass>work.basil.example.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<reporting>
<plugins>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
</plugin>
</plugins>
</reporting>
</project>
The .war files, such as those you saw in building Vaadin web apps, do include dependencies by default.
In contrast, the .jar files built by Maven do not include any dependencies by default.
You can use a plugin such as maven-shade-plugin to create a shaded jar, which does include the dependencies:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<!-- put your configurations here -->
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
Further examples can be found on the Apache Maven Shade Plugin project page.
I've been trying to deploy my JavaFX application with the Oracle client (ojdbc6) embedded into the same jar.
The application runs fine and connects to the database if I'm running it through IntelliJ, but once I run the "package" task and try and run the application from double clicking the jar or running:
"java -jar .\maven-Newton-1.0-SNAPSHOT.jar"
The application starts, but it won't connect to the DB:
`
In the code I've tried both:
Class.forName("oracle.jdbc.driver.OracleDriver");
and
Class.forName("oracle.jdbc.OracleDriver");
I'm just starting with maven and I'm not too sure if my configurations are correct:
• I've tried adding the ojdbc6.jar to the global libraries:
• I've tried adding the ojdbc6.jar file to the SDK classpath:
• And I've messed around with the module dependencies:
But my problem may be lying on the POM file because the other jar that I want to embed within my application is not deploying as well (org.reflections)
• 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>Newton</groupId>
<artifactId>maven-Newton</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>Controller.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.11</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<!-- https://mvnrepository.com/artifact/oracle/ojdbc6 -->
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.11</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0</version>
</dependency>
</dependencies>
</project>
Not too sure where to go from here, any help would be very much appreciated.
Thanks
The problem is that the single jar file, you produce with the 'package' goal does not contain the ojdbc.jar in itself.
You will have to run the jar file with a classpath, e.g.
java -cp ojdbc.jar;othernecessary.jar maven-newton-project-1.0.jar
Btw, there is a distinction in maven between dependencies (which are needed for the code to work) and plugins (which are needed for maven to build). You dependency on maven-compiler-plugin and maven-resource-plugin suggests to me you are confusing these two concepts.
I would move these two into the section called <build><plugins> instead alongside the maven-jar-plugin.
If you want an easy to comprehend start, try this: http://www.darrencoxall.com/java/understanding-maven/
Seems like there are couple of questions, which are quite old and things changed from Java 8 support of Jacoco.
My Project contains following structure
pom.xml
|
|
-----sub module A pom.xml
|
|
-----sub module B pom.xml
|
|
-----sub module C pom.xml
I have configured the main pom like this
Main 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.test</groupId>
<artifactId>jacoco-multi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>projectA</module>
<module>projectB</module>
</modules>
<properties>
<jacoco.version>0.5.7.201204190339</jacoco.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit-dep</artifactId>
<version>4.10</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3.RC2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3.RC2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<configuration>
<destFile>${project.basedir}/../target/jacoco.exec</destFile>
<append>true</append>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.16</version>
<executions>
<execution>
<id>default-integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
</plugin>
</plugins>
</build>
</project>
A 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>
<parent>
<artifactId>jacoco-multi</artifactId>
<groupId>com.test</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>projectA</artifactId>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
B 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>
<parent>
<artifactId>jacoco-multi</artifactId>
<groupId>com.test</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>projectB</artifactId>
<dependencies>
<dependency>
<groupId>com.test</groupId>
<artifactId>projectA</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
</plugin>
</plugins>
</pluginManagement>
</build>
I am executing this command mvn clean package. I can see jacoco.exec is getting generated, however I am not able to see any HTML reports are being to verify the data.
Please help me with this.
Another point is, my configuration is correct for Multi-Module projects?
Update
Identified issue.
<destFile>${project.basedir}/../target/jacoco.exec</destFile>
changed to
<destFile>${project.basedir}/target/jacoco.exec</destFile>
Now it's generating reports for individual modules.
Any idea how to generate consolidated report
JaCoCo version 0.7.7 can generate an aggregate coverage report from multiple Maven modules through a new goal jacoco:report-aggregate.
After scanning many solutions I created a simple but complete Jacoco demo project showing:
Multi module project
Unit test (via mvn clean install)
Integration test (via mvn clean install -P integration-test)
Jacoco - test coverage ( both aggregate data file and aggregate reporting)
FindBugs - code quality
Enjoy the simple demo project. In this simple project the README.md file contains information you are looking for. An example is:
The simple demo project contains 3 branches:
Master branch - containing the above functionality
Multi-module-only-unit-tests - contains modules with only unit tests
Multi-module-unit-tests-try2 - contains modules with unit tests, differently.
Follow below-mentioned instructions
Create a new sub-project (usually called maven module). This will be used as report aggregator.
parent pom will be like:
<modules>
<module>A</module>
<module>B</module>
<module>C</module>
<module>ReportAggregator</module>
</modules>
In aggregator module pom- add other subprojects dependencies.
<dependency>
<groupId>xyz</groupId>
<artifactId>A</artifactId>
<version>${project.version}</version>
</dependency>
In aggregator module pom- configure jacoco plugin
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report-aggregate</id>
<phase>verify</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
<configuration>
<dataFileIncludes>
<dataFileInclude>**/jacoco.exec</dataFileInclude>
</dataFileIncludes>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-aggregate</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
In aggregator module pom- configure surefire plugin as
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>**/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
(optional step) If anybody face warning/error like:
Classes in bundle '*' do no match with execution data. For report generation, the same class files must be used as at runtime.**
Then add below mentioned lines in aggregator module pom
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<executions>
<execution>
<id>instrument-ut</id>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>restore-ut</id>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report-aggregate</id>
<phase>verify</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
<configuration>
<dataFileIncludes>
<dataFileInclude>**/jacoco.exec</dataFileInclude>
</dataFileIncludes>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-aggregate</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
run mvn clean install
One problem in multimodule projects is caused, if the aggregator pom is used as parent pom for the modules either, like it is the case in the above example:
- parentAggregator pom
---sub module A pom.xml -> parentAggregator pom
---sub module B pom.xml -> parentAggregator pom
---sub module C pom.xml -> parentAggregator pom
In this case, the build order is:
- parentAggregator
- sub module A
- sub module B
- sub module C
which means, that the parent aggregator can not collect complete information. In my case a transfer of data into sonarQube by mvn sonar:sonar resulted in unexpected and uncomplete results.
Changing the module structure to:
- aggregator pom
-- parent pom
---sub module A pom.xml -> parent pom
---sub module B pom.xml -> parent pom
---sub module C pom.xml -> parent pom
will change the build order to:
- parent
- sub module A
- sub module B
- sub module C
- aggregator
In this case aggregator will be the last one and work with the results of the modules. In my case the results in SonarQube were like expected.
Run Coverage as... Junit for each module separately. Then create a launch group and add each of the run configurations. There is a popup "Launch Mode" with options Inherit, Profile, Coverage, Debug or Run. Choose Coverage for all of them. You probably also want to select "Wait until terminated".
You can now run all the coverage tests in one click. After they complete you need to go into the Coverage View and select merge sessions (double red/green bar) and merge them all into one report.
My Project structure has resources folder inside the src/main/ folder. The resources folder contains the file server.properties. My pom is as follows:
<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.fde</groupId>
<artifactId>Listener</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Listener</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hibernate.version>3.6.10.Final</hibernate.version>
<java.version>1.6</java.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- Hibernate dependencies START -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.9</version>
</dependency>
<!-- Hibernate dependencies END -->
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>resources</directory>
</resource>
</resources>
<testSourceDirectory>src/test/java</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.fde.ListenerServer</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>resources</resource>
<file>server.properties</file>
</transformer>
</transformers>
<artifactSet>
<excludes>
<exclude>junit:junit</exclude>
</excludes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The Jar is created properly and the main class is mentioned in the manifest. I have the following questions :
The target folder contains the classes folder whch has the class files. The jar also contains them so why are they needed. My goal is to have a executable jar with all the dependancies only.
The resources are not getting added in the jar at all. I have added the transformer according to instructions seen on the net but no use!!!
What are the other dir getting created in the target folder (maven-archiver, surefire, surefire-reports etc) ??
Another jar gets created every time i do a maven clean install (original-Listener....jar)
I have absolutely no clue about how to include resources. Any help is appreciated!!
EDIT:::
This is the tag i used for the maven-assembly-plugin:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>attached</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<mainClass>com.fde.ListenerServer</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
This created the Listener-1.0-SNAPSHOT-jar-with-dependencies.jar with all the classes from referred jars in the folders. The manifest also contains the main class.
The problem still is that I cant include the resource bundle in the folder \src\main\resources.
Also I cant understand why jar files referenced from my code are included in the jar as well as inside the META-INF folder.
The problem wasn't in your maven-shade-plugin's configuration, rather that you have explicitly set resource directory to a wrong path:
<!-- wrong -->
<resource>
<directory>resources</directory>
</resource>
As <directory> element's doc says: "Describe the directory where the resources are stored. The path is
relative to the POM."
So if you follow default maven project structure you have to set like this:
<!-- correct -->
<directory>src/main/resources</directory>
or don't set it, then it falls back to same as maven defaults.
I removed the following from the pom.xml and the property files were included at the root dir.
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>resources</directory>
</resource>
</resources>
<testSourceDirectory>src/test/java</testSourceDirectory>
Still havent figured out why there is a repetition of the referred classes in the jar.
Quick briefing on my situation - I'm working on a code base that has JAX-WS annotated interfaces/classes that we generate code-first wsdls from. We are using CXF's cxf-java2ws-plugin to generate wsdls at build time within maven for inclusion within the .jar produced for each module.
What we'd like to do is deploy these wsdl files to a maven repository since the maven repository can act as
a makeshift service repository (such as described here)
give clients an easy way to use the cxf codegen plugin by pointing to the maven coordinates for a wsdl instead of managing the wsdl files themselves
What I've got so far is a pom file that uses dependency:unpack-dependencies to get all of the wsdl files in the project in to one directory within this modules ${project.build.directory} (commonly known as target/ to everyone out there).
What I don't know how to do is to loop through each of these files and invoke deploy:deploy-file mojo on each wsdl. What are my options here since I really want to automate the process of deploying these wsdl files and not have anyone ever deploy them manually?
For completeness sake, here is the pom file:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>rice</artifactId>
<groupId>org.kuali.rice</groupId>
<version>2.0.0-m7-SNAPSHOT</version>
</parent>
<artifactId>rice-dist-wsdl</artifactId>
<name>Rice WSDL Distributions</name>
<packaging>pom</packaging>
<properties>
<wsdl.location>${project.build.directory}/wsdl</wsdl.location>
</properties>
<!-- Depends on all API modules and modules that generate or contain wsdls -->
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rice-core-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rice-kew-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rice-kim-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rice-krms-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rice-ksb-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rice-shareddata-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-wsdls</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includes>**\/*.wsdl</includes>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Which shoves the wsdls in target/wsdl (they are contained within wsdl/ inside each .jar being depended upon):
[whaley#sunspot ~/Repositories/Kuali/rice/dist-wsdl]
> find . -iname '*.wsdl' | head -3
./target/wsdl/CampusService.wsdl
./target/wsdl/CountryService.wsdl
./target/wsdl/CountyService.wsdl
Solution
Thought what I implemented was different than the accepted answer provided by Ryan Steward, I accepted his answer since it led me to write my own.
Basically, here is a maven pom that's a submodule in the multi-module project described above. I'm using dependency:unpack-dependencies and then using an in-line groovy script to call deploy:deploy-file on each of those wsdl files. It's a bit of a hackjob, but I couldn't think of a better way to do this without hardcoding paths to the wsdl files in the module and calling several executions of the deploy:deploy-file mojo on them, leading to a very verbose pom.
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>rice</artifactId>
<groupId>org.kuali.rice</groupId>
<version>2.0.0-m7-SNAPSHOT</version>
</parent>
<artifactId>rice-dist-wsdl</artifactId>
<name>Rice WSDL Distributions</name>
<packaging>pom</packaging>
<properties>
<wsdl.location>${project.build.directory}/wsdl</wsdl.location>
</properties>
<!-- Depends on all API modules and modules that generate or contain wsdls -->
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rice-core-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rice-kew-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rice-kim-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rice-krms-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rice-ksb-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rice-shareddata-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-wsdls</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includes>**\/*.wsdl</includes>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
def repo_url
def repo_id
if ("${project.version}".endsWith("SNAPSHOT")) {
repo_url = "${kuali.repository.snapshot.url}"
repo_id = "${kuali.repository.snapshot.id}"
} else {
repo_url = "${kuali.repository.release.url}"
repo_id = "${kuali.repository.release.id}"
}
def wsdlGroupId = "${project.groupId}.wsdl"
new File("${wsdl.location}").eachFile() { file ->
serviceName = file.name.split("\\.")[0]
log.info("Deploying ${wsdlGroupId}:${serviceName}:wsdl:${project.version} to ${repo_id}")
execString = "mvn deploy:deploy-file -Dfile=${file} -Durl=${repo_url} -DrepositoryId=${repo_id} "
execString += "-DgroupId=${wsdlGroupId} -DartifactId=${serviceName} "
execString += "-Dversion=${project.version} -Dpackaging=wsdl -Dclassifier=wsdl"
def proc = execString.execute()
proc.waitFor()
err = proc.err.text
if (err != null && err.length() > 0) {
log.error(err)
fail("Deployment failed for ${wsdlGroupId}:${serviceName}:wsdl:${project.version} to ${repo_id}. \n Run in verbose mode for full error.")
} else {
log.info("Successfully deployed ${wsdlGroupId}:${serviceName}:wsdl:${project.version} to ${repo_id}")
}
}
</source>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Another possibility: the Maven Ant tasks can deploy files. I've never used it, but I'll bet you could use an antrun configuration and some ant pattern matching to pick up and deploy all the WSDLs.
The Build Helper plugin might help you out. You can make it publish the WSDLs, but you'll have to list each one out explicitly, and they'll all have the artifactId of your pom in their names. Only the classifier can change. For example:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>attach-WSDLs</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.directory}/foo.wsdl</file>
<classifier>foo</classifier>
<type>wsdl</type>
</artifact>
<artifact>
<file>${project.build.directory}/bar.wsdl</file>
<classifier>bar</classifier>
<type>wsdl</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
If your pom's coordinate is myGroupId:myArtifactId:1.1.1, then the artifacts installed and deployed using this config would be named myArtifactId-1.1.1-foo.wsdl and myArtifactId-1.1.1-bar.wsdl. That's the best I know of.