I am trying to use Maven for a Java Application I am writing and am trying to use Java2WSDL with
<plugin>
<groupId>org.apache.axis2.maven2</groupId>
<artifactId>axis2-java2wsdl-maven-plugin</artifactId>
<version>${java2wsdl.version}</version>
<configuration>
<className>com.barclays.hypercube.marketdata.Model.PointSeriesClient</className>
</configuration>
<executions>
<execution>
<goals>
<goal>java2wsdl</goal>
</goals>
</execution>
</executions>
</plugin>
It seems that there is a dependency on
org.apache.ws.commons.axiom:axiom-api:jar:SNAPSHOT
Unsurprisingly this is not available from my Maven repository.
Is there any way to override this? Perhapos with a value in my settings.xml file.
You can exclude that unwanted jar from this maven. But first make sure you do not need this jar. Like here
<project>
...
<dependencies>
<dependency>
<groupId>sample.ProjectA</groupId>
<artifactId>Project-A</artifactId>
<version>1.0</version>
<scope>compile</scope>
<exclusions>
<exclusion> <!-- declare the exclusion here -->
<groupId>sample.ProjectB</groupId>
<artifactId>Project-B</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
Related
How to create a fat jar with specific dependencies.
I have spark project which need 2 external jar which I wanted to add in application jar. when I am creating executable jar then no dependency is included in jar and when I create fat jar all the dependencies are getting added including spark etc.. I wanted to add only those 2 jars in my jar. below is the pom file I created using maven assembly plugin.
<dependencies>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.11</artifactId>
<version>2.2.0</version>
</dependency>
<!-- Below dependencies need to be added in Application jar -->
<dependency>
<groupId>netacuity</groupId>
<artifactId>common-netacuity-db</artifactId>
<version>3.1.2</version>
</dependency>
<dependency>
<groupId>netacuity</groupId>
<artifactId>common</artifactId>
<version>2.1.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<!-- get all project dependencies -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<!-- MainClass in mainfest make a executable jar -->
<archive>
<manifest>
<mainClass>com....App</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- bind to the packaging phase -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
You can use the scope for this. By default scope is compile and so all the jars will be included when you package it.
To include a jar you can either provide scope as compile and keep the default
<dependency>
<groupId>netacuity</groupId>
<artifactId>common-netacuity-db</artifactId>
<version>3.1.2</version>
<scope>compile</scope>
</dependency>
To exclude the jar, you can change the scope to provided. These jars should be available during runtime.
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.11</artifactId>
<version>2.2.0</version>
<scope>provided</scope>
</dependency>
I come from Gradle and I am switching one of my projects to Maven. Gradle automatically created the jar for those dependencies that had <scope>compile</scope>, but it seems Maven does not do that? Is there a way to tell Maven to create jars for my scope compile dependencies?
Here is a snippet of my pom.xml for which I would expect jars created somewhere in my target folder
<dependencies>
<dependency>
<groupId>com.yubico</groupId>
<artifactId>yubico-validation-client2</artifactId>
<version>3.0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.unboundid</groupId>
<artifactId>unboundid-ldapsdk</artifactId>
<version>4.0.8</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.4.9</version>
<scope>compile</scope>
</dependency>
<dependencies>
Looks like there is no way to handle this elegantly like Gradle does. I had to manually import dependencies using maven-dependency-plugin to create jars for each and every dependency I found I needed when I launched the application (i.e. all those that had compile scope).
So fo every block of <dependency> scoped compile I had to use an <artifactItem> inside maven-dependency-plugin, here's an example for rollbar:
<dependency>
<groupId>com.rollbar</groupId>
<artifactId>rollbar-java</artifactId>
<version>1.4.0</version>
<scope>compile</scope>
</dependency>
This is what worked for me:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
</execution>
</executions>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.rollbar</groupId>
<artifactId>rollbar-java</artifactId>
<version>1.4.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</plugin>
I'm working on a maven based web project. In one module that generates .war file i have some dependencies in POM file, some jars are added to WEB-INF/lib folder. i don't have added jar: commons-dbcp-1.3.jar into POM nor in lib folder, but when i build my project using maven, commons-dbcp-1.3.jar added .war file also i can view it to lib folder in target directory.
Can anyone help me to explain how this jar is being added to war or lib folder in target directory.
I have also checked the "build path" and this jar is not added as an external jar.
I'm using Eclipse(Indigo).
Here is the POM file.
<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.company</groupId>
<artifactId>rpt</artifactId>
<version>4.0.2</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts-core</artifactId>
<version>1.3.5</version>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.4.2</version>
</dependency>
<dependency>
<groupId>struts</groupId>
<artifactId>struts</artifactId>
<version>1.1</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20131018</version>
</dependency>
<dependency>
<groupId>com.mind</groupId>
<artifactId>mind-common-framework</artifactId>
<version>1.3.1</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
<optional>false</optional>
</dependency>
</dependencies>
<organization>
<name>OrgName</name>
</organization>
<build>
<defaultGoal>package</defaultGoal>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>${project.artifactId}-${project.version}-r${prefix.revision}</finalName>
<attach>false</attach>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<archive>
<manifestEntries>
<Implementation-Build>${project.version}</Implementation-Build>
<Build-Time>${maven.build.timestamp}</Build-Time>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<targetJdk>1.7</targetJdk>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.build.timestamp.format>yyyy/MM/dd HH:mm</maven.build.timestamp.format>
</properties>
</project>
This jar can possibly be one of the dependencies for running your project and Maven automatically downloads and packages the required dependencies(jars) for the project at the time of compilation and packaging.
DBCP commons jar is provided by Apache for maintaining the pool of connection objects . It is basically used in the applications involving database connections where many users can simultaneously try to access the DB(eg: Web Base Applications involving DB operations) to improve the performance of the application and the system.
If you don't wish to bundle this jar with your package and such a capability will be provided by the web container where your application will be deployed(connection pooling), you can set the scope of this dependency to be 'provided'.
The scope you should use for this is "provided". This indicates to Maven that the dependency will be provided at run time by its container or the JDK, for example.
Dependencies with this scope will not be passed on transitively, nor will they be bundled in an package such as a WAR, or included in the runtime classpath.
https://maven.apache.org/general.html#scope-provided
I am trying to configure maven to build a runnable jar.
The project that this is about contains a couple of dependencies as well as embedded jetty.
I want to embed all dependencies (which works) and have one executable jar.
I can run the project fine from eclipse but once I try to run the jar I get ClassNotFoundExceptions on org.eclipse.jetty.servlet.ServletContextHandler.
However, when I use the maven-plugin and run exec:java the program starts without problems.
What am I doing wrong?
Here is a copy of my 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>comms</groupId>
<artifactId>comms-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Air</name>
<properties>
<jettyVersion>9.2.7.v20150116</jettyVersion>
<gsonVersion>2.3.1</gsonVersion>
<logjVersion>2.1</logjVersion>
<lombokVersion>1.16.2</lombokVersion>
</properties>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jettyVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gsonVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${logjVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${logjVersion}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombokVersion}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals><goal>java</goal></goals>
</execution>
</executions>
<configuration>
<mainClass>comms.Loader</mainClass>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<mainClass>comms.Loader</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
I noted that you declared jetty-maven-plugin as a dependency, not a plugin declaration. The jetty-maven-plugin depends on Jetty and that (i.e. the transitive dependency on Jetty) is how the Jetty classes get pulled into the Maven classpath.
However that dependency is declared as 'provided', which basically says: "my code is dependent on this, but normally it will be provided by the deployment environment". Maven will pull in the dependency because it needs it for building your source (which is probably why the exec plugin does work), but will not include it in your jar, because you specifically told it to do so.
Seems to me your pom simply does not reflect the situation:
If your code depends on Jetty classes (not the plugin), remove the
jetty-maven-plugin dependency and declare Jetty itself as an
explicit dependency.
Do not define the scope as 'provided' unless
the deployment environment really does provide the Jetty classes
(which it doesn't, given the error).
Hope this helps!
I'm using the JAX-WS maven plugin (org.jvnet.jax-ws-commons:jaxws-maven-plugin version 2.2) to generate classes from a bunch of WSDL files in my project, and as the WSDLs never really change I would like to disable this code generation by default, and only enable it for a particular maven profile I've created. The element of this plugin supports a element, but setting this to true seems to do nothing. Am I doing something wrong here? Or is this a known bug, and is there something else I could do to avoid this code generation?
My plugin configuration looks like this:
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>import-wsdld</id>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlFiles>
<wsdlFile>MyWSDL.wsdl</wsdlFile>
</wsdlFiles>
</configuration>
</execution>
</executions>
<configuration>
<skip>true</skip>
<packageName>com.my.package</packageName>
<wsdlDirectory>src/main/resources/wsdl</wsdlDirectory>
<keep>true</keep>
<xnocompile>true</xnocompile>
<sourceDestDir>src/main/java</sourceDestDir>
<verbose>false</verbose>
</configuration>
<!-- Necessary to revert back to 2.1.7 -->
<dependencies>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-tools</artifactId>
<version>2.1.7</version>
<exclusions>
<exclusion>
<groupId>org.jvnet.staxex</groupId>
<artifactId>stax-ex</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jvnet.staxex</groupId>
<artifactId>stax-ex</artifactId>
<version>1.2</version>
<exclusions>
<exclusion>
<groupId>javax.xml.stream</groupId>
<artifactId>stax-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</plugin>
Many thanks,
Joseph.
Well, just do it (I mean plugin declaration with all its stuff) in <profile> block. I wouldn't rely on some magic plugin-specific solutions. Just use what Maven offers out-of-the-box and create <profile> with your <plugin> stuff.
Based on the documentation of the plugin it has not "skip" parameter which of course means it will not support. The best solution is to put that into a profile as mentioned before.