install war file at server deploy directory - maven-2

I'm want to have the war file deployed in the server deploy directory (or any directory of my choice) along with the one deployed in the repository. Also, can I control the name of the war file deployed like, I don't want the war file to be projectname-1.0.war I just want the name of the war file be projectname.war.
Thanks,
Ravi

Thanks guys,
I got it working. here is what I did.
I added this in my pom.xml file
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>mavenproject1</warName>
<outputDirectory>C:\jboss-5.1.0.GA\server\default\deploy</outputDirectory>
</configuration>
</plugin>
</plugins>
This solved both my naming and placing the war file.
Ravi

A first option would be to use the JBoss Maven Plugin that allows to start/stop JBoss and deploy/undeploy applications via JMX.
Your configuration must set the location to your JBoss Home directory. This can be done by setting the home directory with the jbossHome tag in the plugin configuration:
<project>
...
<build>
<defaultGoal>package</defaultGoal>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jboss-maven-plugin</artifactId>
<configuration>
<jbossHome>C:/jboss-5.1.0.GA</jbossHome>
</configuration>
</plugin>
...
</plugins>
...
</build>
...
</project>
Then, just use one of the goal defined here, like:
$ mvn jboss:deploy
Another option would be to use the Cargo Maven Plugin. Below an example of plugin configuration that you could add to your war project:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<wait>false</wait>
<container>
<containerId>jboss5x</containerId>
<home>C:/jboss-5.1.0.GA</home>
</container>
<configuration>
<type>existing</type>
<properties>
...
</properties>
</configuration>
</configuration>
<plugin>
Then, to deploy a "deployable" (here, your war) to a running container:
$ mvn cargo:deploy

'Deployment' may sound very technical but its just copying file to the deployment directory. In some cases you may have to restart the server.

To change what it deploys the file as, use the tag in the build section of your pom.xml to specify the package name.
http://maven.apache.org/plugins/maven-jar-plugin/sign-mojo.html

Related

IntelliJ - How to set the default jar file name in artifact

Each one of my modules has same version in their pom files:
<version>1.0-SNAPSHOT</version>
I would like for my artifact to strip the version part when exploding folders to Tomcat application.
I know I can rename them manually:
But I have to do this every time I deploy my application.
Does anyone know if there is a way around this, so I keep the jar names in artifact by default?
You can set the name of your JAR file by configuration of the Maven Jar Plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<finalName>YourName</finalName>
</configuration>
</plugin>
For more details, have a look at the docs.

Using jar libraries with Jboss and Openshift

I'm trying to deploy a simple REST Webservice on Openshift, using Jboss and Eclipse.
I have a Jar library cointaining some classes, I put that in the path:
src/main/webapp/WEB-INF/lib/
of the project. Deploying the application locally and testing it is ok, but when I try to deploy on Openshift I get an error at build time:
ClassNotFoundException
Reading the log I noticed that Jboss (on Openshift) doesn't find my Jar: why?
Check if library exists in war (you can unzip this file)
Check if war is deployed in remote server and unzip war to view libraries: ssh 5fcd6........#yourappname-yourdomain.rhcloud.com
Check path: /var/lib/stickshift/5fcd6......../app-root/runtime/repo/deployments
View Readme in folder deployments (in local)
You should use Maven. Sample:
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<archive>
<manifestEntries>
<Dependencies>org.slf4j,org.apache.commons.logging,org.joda.time</Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>openshift</id>
<build>
<finalName>yourapp</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<outputDirectory>deployments</outputDirectory>
<warName>ROOT</warName><!-- ROOT -->
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

Is there any way to tell maven war plugin to use folder other than target/classes

when i use maven war plugin, by default, this plug-in will copy all class files(*.class) from target/classes to {warfile}/web-inf/classes.
The problem is if i have compiled classes (*.class) that stay in another folder : basedir/other-classes (they are *.class file not *.java file, i know, it is weird. But those classes is generated from 3rd party).
Is there any way to tell maven war plugin to copy all classes in (basedir/other-classes) and (target/classes) into {warfile}/web-inf/classes
This might work for you. Make sure the directory and targetPath are what you need.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<webResources>
<resource>
<directory>${project.build.directory}/other-classes</directory>
<targetPath>WEB-INF/classes</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>

How to exclude pom.xml from Maven generated war?

Using Maven war plugin, I generate WAR which includes following directory:
META-INF
-- maven
-- com.abc.def
-- myServlet
-- pom.xml
-- pom.properties
In release, I want to exclude this maven directory. How can I do that?
I tried latest maven-war-plugin (2.1-beta-1), it has configuration "packagingExcludes", but it doesn't work as I wish.
Any suggestions?
I'm not sure but I think that the Maven Archiver (which is mainly used by plugins to handle packaging) can be configured to achieve this.
About the <addMavenDescriptor> element, the Maven Archiver Reference says:
Whether the generated archive will contain these two Maven files:
The pom file, located in the archive in META-INF/maven/${groupId}/${artifactId}/pom.xml
A pom.properties file, located in the archive in META-INF/maven/${groupId}/${artifactId}/pom.properties
The default value is true.
So a pom configured like this should do the trick:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0</version>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
</plugin>
...
</plugins>
</build>
...
</project>
Using the standard Maven packaging you can't omit the file to my knowledge. It is possible however to use the maven-assembly-plugin to construct the war, in this case you have much finer grained control over the contents of the artifact, and can omit the pom.xml.
However I have personally found it useful to keep the pom.xml for diagnostic purposes. It can be handy to know what was used to build and assemble the war when trying to figure out what is wrong with your app.
Update: in a bizarre bit of synchronicity to Pascal's answer, I've just been reading up on the Archiver reference and it appears that this can be done by setting the addMavenDescriptor property to false. Personally I would still avoid doing this for reasons given above. But you may want to change your acceptance to Pascal's answer.
Putting a META-INF folder in a resources directory or in the root of your source directory will destroy the META-INF content created by Maven. For WAR files, putting a META-INF in your web content directory will do the same.
Adding other content to that custom META-INF will override what maven would create.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1</version>
<configuration>
<warSourceExcludes>pom.xml</warSourceExcludes>
</configuration>
</plugin>
or
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1</version>
<configuration>
<warSourceExcludes>here/there/everywhere/a/pom.xml</warSourceExcludes>
</configuration>
</plugin>

maven javaee application client plugin

I am pretty new to maven.
Is there any plugin or packaging type suitable for building application client jar file ?
I want to add the application-client.xml file to the META-INF folder inside the jar.
The normal jar packaging doesn't include the file.
You should only need to define the project with jar packaging (and as it is the default you don't need to declare it).
If you define the application-client.xml in the src/main/resources/META-INF folder it will be included in the META-INF folder of the final jar.
To define additional information you need to configure the jar plugin as below.
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<configuration>
<archive>
<manifest>
<mainClass>com.mycompany.app.App</mainClass>
<addClasspath>true</addClasspath>
</manifest>
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
Check out the guide to working with manifests for full details
I'm not very familiar with the JavaEE support in Maven, but it looks like the ejb plugin can generate a client jar as well if configured properly. Check this page out:
Maven EJB Plugin - Generating an EJB client