Ignore jars while creating final jar for production - maven

I am using some jars like junit which are required only for testing purposes. I am using maven dependency plugin to copy all the jars to the final zip file created using maven. Is there a way to avoid junit jars from getting copied?

In configuration put includeScope = runtime
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!-- exclude junit, we need runtime dependency only -->
<includeScope>runtime</includeScope>
<outputDirectory>${project.build.directory}/dependency-jar/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>

Related

Is it possible to generate a client jar that also includes classes from dependency jars if they are being used in any of the Interfaces?

I am using maven-ejb-plugin with generateClient property set to true, I tried maven-assembly-plugIn but that includes all the libraries that are being used. I only want the classes that are being used from dependency jars in the Interfaces to be included in the client jar.
Is there any setting/configuration in Maven appc (https://docs.oracle.com/middleware/1213/wls/WLPRG/maven.htm#WLPRG614) that I can use to achieve this?
I not sure if what you try to do is a good way but maybe you can use the maven dependency plugin to extract the required classe from your dependent jars.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<excludeTransitive>true</excludeTransitive>
<includes>yourClass.class</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

maven javadoc generation issue of viewing on local tomcat server

I have managed to generate javadocs for my maven java project.
I use the following in
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</execution>
</executions>
</plugin>
I use the goal javadoc:javadoc when building.
Is there a way I can start my tomcat server and view the generated javadocs via a URL on my tomcat server? Something like localhost:8080/...
Thanks

Wildfly, fat jar and jndi-registration

When I build a fat jar with my ejb and dependencies, all the dependent libs/jars are unpacked, and when deployed to wildfly, jodi-registration is performed, and entries like
java:global/template-service-1.0.0-SNAPSHOT-jar-with-dependencies/ReceptionService
are reported on the console. I can then add a module dependency to my war-project manifest and use the ejb.
When I build the exact same ejb using one-jar plugin, the dependent libraries are not unpacked, and jndi-registration is not performed. Hence the ejb is not reachable.
From what I can se the jar files are otherwise similar, and it seems wildfly behaves different depending if included jars are unpacked or not. Is this so, and why? Or does the one-jar plugin create a fat jar that is different in some way that I have not figured out?
The pom.xml is listed below, with the one-jar config that I use commented out:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Includes the runtime dependencies -->
<!--
<plugin>
<groupId>org.dstovall</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<configuration>
<attachToBuild>true</attachToBuild>
</configuration>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
</executions>
</plugin>
-->

Multiple maven generate-sources

I have two plugins generating Java files. One generates code from a WSDL file and the other from an XSD schema file. Only the code from the schema is generated.
If I have separate Eclipse projects for each plugin, then all the source code is generated correctly. But I want to have in one project both plugins generating the code.
Here is my pom file:
<plugins>
<!-- generate Java classes from schema files (binding files optional) -->
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.2</version><!--$NO-MVN-MAN-VER$ -->
<executions>
<execution>
<id>xsd_phase</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<bindingDirectory>${project.basedir}/xsd/</bindingDirectory>
<schemaDirectory>${project.basedir}/xsd/</schemaDirectory>
<generateDirectory>${project.basedir}/target/src/generated/java/</generateDirectory>
<generatePackage>com.abc.xyz.jaxb</generatePackage>
<forceRegenerate>true</forceRegenerate>
<episode>false</episode>
<removeOldOutput>true</removeOldOutput>
</configuration>
</execution>
</executions>
</plugin>
<!-- generate Java classes from wsdl files -->
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<id>wsdl_phase</id>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<encoding>UTF-8</encoding>
<packageName>com.abc.xyz.ws</packageName>
<wsdlDirectory>${project.basedir}/wsdl/</wsdlDirectory>
<sourceDestDir>${project.basedir}/target/src/generated/java/</sourceDestDir>
<xnocompile>false</xnocompile>
</configuration>
</execution>
</executions>
</plugin>
Just include both in the build/plugins configuration of your project. There is nothing in the POM format preventing a binding of two different goals from different plugins to the same phase (generate-sources in your case).
The only caveat you have to be mindfull of is that, when two executions are bound to the same phase, they will be executed in the order they are defined in the POM. In other words, if you were to copy-paste your snippet into the POM as it stands, during generate-sources, the xsd_phase would run first, and then wsdl_phase.

remove jar created by default in maven

I am using maven assembly plugin. in my pom.xml, pakaging type: jar and i dont use maven jar plugin.
Whenever i run mvn clean package, it create 2 jar files: one is from maven assembly, another one is created by default (due to packaging type =jar). I want to keep only the jar file created by assembly plugin only. How to do that?
You may have your reasons but I doubt that it is a good solution to skip the default jar being built and deployed.
Anyhow here is how you can disable the default jar being built.
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<id>make-assembly</id>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- some configuration of yours... -->
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>default-jar</id>
<!-- put the default-jar in the none phase to skip it from being created -->
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>

Resources