Is it possible to get the maven install plugin to deploy the ejb client jar? - maven

After years of working with Spring, I'm working on a Java EE 7 application with EJB 3.2 and Maven. One thing I would like is to deploy the EJB Jars separately from the web application so I can develop independently. Including the EJB Jars in the WAR causes the app server to redefine the EJBs in the context of the WAR, which I don't want to happen.
The prescribed method is to have maven create a client jar with this directive:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<ejbVersion>3.2</ejbVersion>
<generateClient>true</generateClient>
<clientExcludes>
<clientExclude>**/*Impl.class</clientExclude>
</clientExcludes>
</configuration>
</plugin>
I'm excluding any Impls from the Client JAR.
The issue I'm having is that maven isn't installing the client jar during the install phase.
I can install it manually by doing this:
mvn install:install-file -Dfile=foo-1.0-client.jar -DgroupId=com.awesome -DartifactId=foo -Dversion=1.0 -Dpackaging=jar -Dclassifier=client
I fiddled around a lot and came up with this
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<ejbVersion>3.2</ejbVersion>
<generateClient>true</generateClient>
<clientExcludes>
<clientExclude>**/*Impl.class</clientExclude>
</clientExcludes>
</configuration>
<executions>
<execution>
<id>package</id>
<phase>package</phase>
<goals>
<goal>ejb</goal>
</goals>
</execution>
<execution>
<id>install</id>
<phase>install</phase>
</execution>
</executions>
</plugin>
</plugins>
However, this isn't proper. This installs the client as a new artifact, not as the same artifact with classifier client. When you include the client in another application, you are supposed to use ejb-client. This looks in your folder that contains the normal artifact, foo-1.0.jar, and looks for something with classifier client.
<dependency>
<groupId>com.awesome</groupId>
<artifactId>foo</artifactId>
<version>${com.awesome.version}</version>
<type>ejb-client</type>
</dependency>
Stumped here, any ideas?

Related

Simple Java Mail dependencies not in the jar file

I used simplejavamail in my maven project. The program can send out the email if I run it from Intellij IDE. But when I create a jar file, and run it from the jar file, then I got class not found for all the simplejavamail classes. And I open the jar, I find out that they are not included in the jar. But all the other dependency classes are there. Any one have meet this issue before?
parts of my pom.xml
<dependency>
<groupId>org.simplejavamail</groupId>
<artifactId>simple-java-mail</artifactId>
<version>6.4.3</version>
</dependency>
<build>
<finalName>my-project-name</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I'm having the same problem. It appears that the dependencies (Ex. Email, Mailer, EmailBuilder, etc) appear in the org.simplejavamail.api repository. I'll update you if I find a working solution with v6.4.3 but I have a feeling we may need to include additional dependencies.
Edit: To at least patch your problem,
<dependency>
<groupId>org.simplejavamail</groupId>
<artifactId>simple-java-mail</artifactId>
<version>5.5.1</version>
</dependency>
The 5.5.1 version still has the classes in the jar. You can reference this for yourself here:
https://www.javadoc.io/doc/org.simplejavamail/simple-java-mail/5.5.1/index.html
Then click on the different versions to see what classes exist.
I think something went wrong in their builds since v6.
Let me know if this helps!

Preventing Maven Modules from being Deployed

I followed this tutorial to created a Maven build that can publish artifacts to Maven Central.
It works, and most of the tutorial is for authentication of some sort, so the only relevant part of it might just be:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
Now I wanted to only deploy two of the seven modules in total, so I added this to the parent POM:
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
And <skip>false</skip> to the two modules I actually want to deploy.
This doesn't work. All modules get deployed.
I checked the effective POM, and it clearly shows skip=false for the two modules I want to deploy and skip=true for the other five modules.
Since deploying to Maven Central isn't really a reversible process, I don't want to trial and error my way through this problem, hence the question: How do I prevent Maven modules from deploying to Maven Central?
If you are deploying to Maven Central, it is the Nexus Staging Plugin that is doing the deployment instead of the Deploy plugin, so the configuration of the deploy plugin has no effect. To make the Nexus deploy plugin skip, set skipNexusStagingDeployMojo in its configuration to true.
For a complete example, you can look at one of my projects I deployed to Maven Central with the same problem - I want to deploy everything except the integration test modules.
In the parent POM, the Nexus deploy plugin is defined like normal as described in the tutorial (https://bitbucket.org/prunge/shoelaces/src/2347535282c9f5bb58d33cca22d9dd65c9db2c2b/pom.xml#pom.xml-200):
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>false</autoReleaseAfterClose>
</configuration>
</plugin>
and in the integration tests project (which itself has children that inherit this configuration) the staging plugin is skipped (https://bitbucket.org/prunge/shoelaces/src/2347535282c9f5bb58d33cca22d9dd65c9db2c2b/integration-tests/pom.xml#pom.xml-28):
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<skipNexusStagingDeployMojo>true</skipNexusStagingDeployMojo>
</configuration>
</plugin>
This results in everything by default being deployed to Central except the integration tests project and everything underneath that.

Build a site zip with Maven

actually, I generate a maven site containing the documentation of my project. It works very well, in fact if works so well that my customers wants to get that site as a deliverable (for obvious documentation purpose).
How can I tell Maven to build a zip of the whole site and deploy it to my artifacts manager (Nexus)? I've tried several things, but if I understand correctly, deploying artifacts and generating the site are using different livecycle, and the site generation occurs after the deployment of the artifacts..
I could obviously get the generated site from the location it's deployed during site-deploy, but I would greatly appreciate an automatic and centralized way...
PS: giving access to the customer to our internal site is NOT an option.
Here is a working solution delegated to a Maven profile to isolate the behavior (and speed-up normal builds), but which could also be integrated in the default build if required (although not recommended).
<profiles>
<profile>
<id>site-zip</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.4</version>
<executions>
<execution>
<id>pack-site</id>
<phase>prepare-package</phase>
<goals>
<goal>site</goal>
<goal>jar</goal>
</goals>
<configuration>
<attach>false</attach>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<id>rename-file</id>
<phase>prepare-package</phase>
<goals>
<goal>rename</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/${project.build.finalName}-site.jar</sourceFile>
<destinationFile>${project.build.directory}/${project.build.finalName}-site.zip</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.10</version>
<executions>
<execution>
<goals>
<goal>attach-artifact</goal>
</goals>
<phase>package</phase>
<configuration>
<artifacts>
<artifact>
<file>${project.build.directory}/${project.build.finalName}-site.zip</file>
<type>zip</type>
<classifier>site</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
What the profile is actually doing:
Configuring an execution of the Maven Site Plugin, attached to the prepare-package phase and running the site and jar goals (as also suggested by #khmarbaise).
Renaming the file from jar to zip via the Copy Rename Maven Plugin
Attaching the zip to the build via the Build Helper Maven Plugin and its attach-artifact goal
As such, running
mvn clean install -Psite-zip
Will also install in your local Maven cache the zipped site. The deploy phase would do the same on your target Maven repository then.
Note that the Maven Site Plugin and the Copy Plugin must be declared in the order above to follow the required flow within the same phase.
Also note that if zip is not a strong requirement, you can then just skip the Copy and Build Helper executions and only use the Maven Site execution. By default the jar created providing the site is already attached to the build (and hence it will be installed and deployed automatically). In order to have the zip, we had to disable this behavior (<attach>false</attach>) and re-attach it via the Build Helper plugin.
The generated zipped has automatically a classifier, which is site in this case.
You can use the maven-site-plugin.

Unpack an EAR file using maven

I have an EAR file from some build. I want to extract the contents of this EAR file into another folder. I am confused how to do this. I have looked and tried
http://maven.apache.org/plugins/maven-ear-plugin/
and
http://maven.apache.org/plugins/maven-dependency-plugin/usage.html
but either maven is unable to find the file or it has dependency issues.
Since I am new to maven I don not understand how to set these plugins up.
I got the following error on using the below plugin.
Failure to find ECM:ECM:ear:1.0 in http://repo.maven.apache.org/maven2 was cached in the local repository
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>ECM</groupId>
<artifactId>ECM</artifactId>
<version>1.0</version>
<type>ear</type>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/earoutput</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
You can do it using dependency:unpack-dependencies. I just modify my answer because according to your comments, your ear is generated by some other build. If you do not have an Enterprise repository that you can deploy your ear artifact, you have to use "system" scope, but please note that it is usually discouraged.
Add below dependency to your pom.xml
<dependency>
<groupId>ECM</groupId>
<artifactId>ECM</artifactId>
<version>1.0</version>
<type>ear</type>
<scope>system</scope>
<systemPath>/path/to/your/abc.ear</systemPath>
</dependency>
Add the below plugin to your postBuild module pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeArtifactIds>ECM</includeArtifactIds>
<outputDirectory>${project.build.directory}/earoutput</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Have you looked at this example of Maven EAR plugin for Unpacking a module yet?
The Maven Dependency Plugin and its unpack goal can do this.
Sample configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>myear</groupId>
<artifactId>myear</artifactId>
<version>1.0</version>
<type>ear</type>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/earoutput</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
This takes the 'myear.ear' artifact and extracts it to the 'target/earoutput' directory. This also works with JARs, WARs and any other zip-like file. The phase this executes under is 'package' - this may be too late if you need to use these resources in other parts of the build. Change the phase to something earlier such as 'generate-resources' if needed.
You mentioned that you already tried using the dependency plugin. Is the EAR file from another Maven project, and has it been installed in the local Maven repository? If it still doesn't work post the plugin configuration you tried to use.
(edit: update information on dependencies and local repository)
For this to work, your EAR file needs to be put into your local Maven repository (this is just a directory on your disk). But if other people need to build your project as well, you have a few options:
import the EAR into your local repository, and also deploy to a remote repository so everyone can get it (recommended, but requires you to set up a corporate Maven repository)
give the EAR to everyone and have them put it into their local repository using a couple of Maven commands (might be OK for a few developers, less overhead than setting up a whole repository server)
check the dependent EAR into source control under your project and unpack it (not the recommended way of doing things) in a goal in your project
Importing into your local repository is easy. It's very similar to these instructions.
Use the following command:
mvn install:install-file -Dfile=<path-to-EAR-file-on-local-filesystem> -DgroupId=myear
-DartifactId=myear -Dversion=1.0 -Dpackaging=ear
(modify path, groupId, artifactId and version as needed)
Group ID and artifact ID are there simply to uniquely identify artifacts.
Once you install this in the local repository, the dependency plugin should work and find the artifact.

Deploy a web-application on Websphere 8.5 using maven 3

I´m trying to make a Maven Project from an existing web application using JSF. The Project
should be deployed on Web Sphere 8.5.
Since i'm new to Web Sphere, don´t know how to build the "ear" Module, in order to be deployable on Web Sphere 8.5.
Does anyone know, where i can find further Information about deploying a web application on Web Sphere 8.5 using Maven 3.0.3?
Thanking you in anticipation,
Mosen
I've never worked with WebSphere Application Server 8.5; but in the days I was playing with IBM WAS 6.1 the WAS6 Maven plugin worked pretty well (it seems it works with WAS7 too). Here's a POM fragment from the plugin site that allows automatic EAR deployment:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>was6-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>installApp</goal>
</goals>
</execution>
</executions>
<configuration>
<wasHome>${was61home}</wasHome>
<host>deploymentmanager.your.domain</host>
<username>admin</username>
<password>adminpassword</password>
<targetCluster>nameOfCluster</targetCluster>
<profileName>Dmgr01</profileName>
<conntype>SOAP</conntype>
<port>8879</port>
<verbose>true</verbose>
<updateExisting>false</updateExisting>
</configuration>
</plugin>
That plugin is for deployment and other administrative task, for EAR generation you can use the Maven EAR Plugin as described in 20InchMovement answer.
Hope this could helps:
<plugin>
<groupId>com.orctom.mojo</groupId>
<artifactId>was-maven-plugin</artifactId>
<version>1.0.8</version>
<executions>
<execution>
<id>deploy</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<wasHome>${env.WAS_HOME}</wasHome>
<applicationName>${project.build.finalName}</applicationName>
<host>${local or remote address}</host>
<server>server01</server>
<node>node01</node>
<virtualHost>default_host</virtualHost>
<verbose>true</verbose>
</configuration>
</execution>
</executions>
</plugin>
From https://github.com/orctom/was-maven-plugin
in order to package an *.ear, you don't need Websphere.
This can be accomplished with maven itself.
pom.xml:
<project>
...
<artifactId>YourApp</
<packaging>ear</packaging>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<modules>
<jarModule>
<groupId>${project.parent.groupId}</groupId>
<artifactId>configurationApp</artifactId>
</jarModule>
<ejbModule>
<groupId>${project.parent.groupId}</groupId>
<artifactId>AnEjbModule</artifactId>
</ejbModule>
</modules>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
...
</project>
Then you add your dependencies.
On command line go to your project and run mvn package.
Because of the package defined in you pom.xml, the ear will be created and can be found in the YourApp/target directory.
On the websphere admin console you can simply install the ear.
After login, goto:
Applications->Websphere enterprise applications and install a new application.
Select your YourApp.ear and go for easiness through the fast path to install the app.
The port to check is probably
yourServerName:9080/YourApp.
Good luck.
See http://code.google.com/p/websphere-maven-plugin/
Websphere Maven Plugin provides goals to:
deploy ear on websphere 7
start application
stop application
uninstall
require websphere application client.

Resources