I want to create ear application with one ejb project and dependencies (without war file). Is it possible to specify build configuration in one pom.xml to avoid unnecessary multiplication of application modules (I have about 8 projects witch will be packaged this way and if I would do this "standard" way I would have to create 8*3=24 modules/poms). I don't want to put all my applications into one ear, because I need to could undeploy/redeploy them separately.
Right now I have two solutions:
Create ear in standard way with module structure:
project
ejb
src
pom.xml
ear
pom.xml
pom.xml
But as I mentioned it's creating multiplication of modules.
Create jar with dependencies using maven-shade-plugin
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals><goal>shade</goal></goals>
<configuration>
<finalName>project</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
But with this solution I get jar instead of ear and my dependencies are mixed with my code.
Is there any other way to create deployable application with only ejb and dependencies with maven using single pom.xml?
Related
I have a maven plugin and I'd like to configure it by providing a path to a file/directory which is inside a dependency jar.
Here is a sample of my maven projects pom.xml. It has a plugin with a dependency which has a property as part of its execution called templateDirectory. I would like to put a path here to the plugins dependency mylang-swagger-codegen to a file/directory inside of the dependency
{ Some path }/src/resources/api/
How can I get to this path? I understand references like ${project.basedir} work to get to the project. Is there a way I can reference to the dependency and inside the jar to get to the file / directory I want?
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.4.19</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/api/swagger.yaml</inputSpec>
<language>myLang</language>
<templateDirectory> <!-- Path here to api.mustache --> </templateDirectory>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>mylang-swagger-codegen</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
Jar files are built on .zip. Maybe a Maven plugin that unwraps dependencies can help with what you want to accomplish.
Take a look at this to unpack a specific artifact: https://maven.apache.org/plugins/maven-dependency-plugin/examples/unpacking-artifacts.html
Or this, to unpack the project dependencies: https://maven.apache.org/plugins/maven-dependency-plugin/examples/unpacking-project-dependencies.html
After running this plugin, you can access the path where you unpacked the jar. In the examples above, the plugin runs in the "package" phase of maven. If you want to change the order, take a look at the maven build phases: https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
I'm trying to configure my multimodule maven project like this :
Parent Project
web
dao
core
<modules>
<module>../dao</module>
<module>../core</module>
<module>../web</module>
</modules>
My "web" module have one dependency to my "core" project and my core project to my "dao" project.
For example, my web pom contain :
<dependency>
<groupId>com.groupid</groupId>
<artifactId>core</artifactId>
<version>${project.version}</version>
<classifier>jar-with-dependencies</classifier>
</dependency>
When I build my parent project all build work fine but there is a very strange dependency copy. In fact, my parent project contains all child dependencies
For example, joda-time is in my web pom.
When I try to uncompress my web.war, it contains my core-jar-with-depency.jar and all the dependency.
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<skipAssembly>false</skipAssembly>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
How can I configure my parent project to disable dependency inclusion?
Any specific reason for using classifier jar-with-dependencies? Looking at your need, I think you can do this ---
dao --> module with packaging jar
core --> module with packaging jar & dependency of dao without any classifier.
web --> module with packagingc war & dependency of core without any classifier.
Eventually your web war file will 'transitively' get core & dao & all its dependencies. See if this helps.
--- Update:
I just created one sample project with core module & web module in my GIT hub.
https://github.com/Ravikharatmal/MyGitRepo/tree/master/MultiModuleMavenProject
Web is dependent on Core. Core has a dependency on third party library commons-lang. When I do 'mvn install', you can see that the final web.war file has core.jar as well as commons-lang.jar i.e. transitive dependency of core.jar.
https://github.com/Ravikharatmal/MyGitRepo/tree/master/MultiModuleMavenProject/web/target/web-0.0.1-SNAPSHOT/WEB-INF/lib
I hope this is what you are looking for.
Got some issues with axis generation from wsdl
Once generated, classes are not visible eclipse /target folder (I can see them in a terminal...)
I cannot include them and use them.
I guess I'm missing something here, axis and soap are such a pain...
The project jar contains the generated classes, I can add it to build path manually and that works.
If I'm including the maven module in another module, maven complains "
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>1.5.4</version>
<executions>
<execution>
<id>generate 1</id>
<goals>
<goal>wsdl2code</goal>
</goals>
<configuration>
<packageName>com.test</packageName>
<wsdlFile>path.to.wsdl</wsdlFile>
</configuration>
</execution>
</executions>
</plugin>
The issue here is that axis2-wsdl2code-maven-plugin is putting the JAR in a non standard place - this is why maven complains when you try in add it as a dependency.
Can you see the JAR being installed into your local maven repo?
I need to create two WAR files with two different web.xml files using Maven. The WAR files are the same otherwise.
The WAR files are created as expected, however, the second file has the same web.xml file as the first.
How can I force the Maven WAR plugin to use the second file for the second WAR? I cannot use profiles since I need both files created in one pass.
My current code:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<warSourceDirectory>${basedir}/WEB</warSourceDirectory>
<warName>main</warName>
<webXml>${basedir}/CONF/web.xml</webXml>
</configuration>
<executions>
<execution>
<id>hist-war</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
<configuration>
<warName>hist</warName>
<warSourceDirectory>${basedir}/WEB</warSourceDirectory>
<webXml>${basedir}/CONF/hist.web.xml</webXml>
</configuration>
</execution>
</executions>
</plugin>
Use the overlay feature of the Maven WAR plugin.
You need two WAR projects. The first is your original one, with its web.xml file in the correct place. This doesn't have any specific needs in terms of configuration. Just ensure that it builds as you expect.
The second only contains its POM and the alternate web.xml in the WEB-INF directory. This project's POM must contain a dependency on the first project with type specified as war and scope specified as runtime. You should not need to explicitly configure the Maven WAR plugin.
seems there are a variety of gotchas using the war plugin. in this case, i would just use 2 separate sub-modules to build the appropriate wars.
Is there a way to pack the dependencies of a maven ejb project in with the final jar?
I typically use a separate ear project and include the ejb as a dependency - it will fill out the lib folder automatically this way. However, this seems a bit wasteful - to have a project just to build the ear.
Right now I have:
<artifactId>projectname</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>ejb</packaging>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<!-- without this, the datetime stamp unique id's will be appended to classpath items -->
<!-- see: http://maven.apache.org/shared/maven-archiver/examples/classpath.html#Snapshot -->
<useUniqueVersions>false</useUniqueVersions>
</manifest>
</archive>
</configuration>
</plugin>
Do I need to set the packaging type to ear? Can I include transitive dependencies in a standalone ejb jar? If I set it to ear, how do I config the ear plugin?
Thanks in advance!
The Maven Shade Plugin can package dependencies in with the JAR. It will extract the classes/resources from all the project's dependencies on package them in with the final JAR.
This should be enough to package all your dependencies:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
There are disadvantages to doing this, however.
Multiple resources with the same name in different JARs can cause problems (e.g. /META-INF/services/...). You can use Shade's resource transformers, but it can get messy.
Not as easy to track what JARs are dependencies in your project once deployed (you'd have to refer back to the POM instead of just looking at the EAR).
Unless you have good reason not to, I'd recommend you stick with building an EAR.
I don't think there is a direct way to do this. Instead, what can be done is to create it as a module project with an ear and an ejb module. It isn't exactly what I wanted, but it works and is better than separate projects.