Using jar libraries with Jboss and Openshift - jboss7.x

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>

Related

remote deployment to wildfly using cargo fails

I am trying to deploy an application to a remote wildfly 8.1.0.Final using the cargo maven plugin and it fails with error Operation failed: Could not connect to remote://10.0.0.165:9990 in 5000ms.
The application is the default application generated by the maven archetype cargo-archetype-remote-deployment. This application can be successfully deployed to jboss 7.1.1.Final without modification to the pom. I have added the following profile to the pom
<profile>
<id>wildfly8x</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<container>
<containerId>wildfly8x</containerId>
</container>
<properties>
<!--<cargo.jboss.management-native.port>9999</cargo.jboss.management-native.port>-->
<cargo.jboss.management-http.port>9990</cargo.jboss.management-http.port>
</properties>
</configuration>
<!--
The JBoss remote deployer requires some additional dependencies. Read more on:
http://cargo.codehaus.org/JBoss+Remote+Deployer
-->
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-controller-client</artifactId>
<version>7.0.2.Final</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
which is a copy of the jboss7x profile with the changes for wildfly.
The properties at the beginning have been changed to correct hostname and username and passwords. I can log into the 10.0.0.165:9990 using http and access the web interface I can also us the jboss-cli interface to login to 10.0.0.165:9990 and deploy the application to the server using the command line. I have also increased the time out as recommended but without success.
It would appear that the remote:// protocol is not available in wildfly or the name is incorrect and cargo is expecting to be able to connect using it.
I have had problems with wildfly and the changes made to interfaces in the past when I connected Netbeans 8 to it. I did eventually find the solution to that by adding back the native management interface which was removed in one of the beta versions.
Does anybody have any knowledge on how to get this working? A copy of a pom from a working example would be good. Before replying please make sure that your reply is relevant to the versions specified as jboss/redhat make changes between dot point releases with very little documentation.
Hy,
I just have the same issue, i gues you copy the example from:
http://cargo.codehaus.org/JBoss+Remote+Deployer
And I found that the example is for JBOSS 7...
For Wildfly this is what worked for me:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.4.12</version>
<configuration>
<container>
<containerId>wildfly8x</containerId>
<type>remote</type>
</container>
<configuration>
<type>runtime</type>
<properties>
<cargo.remote.username>consoleUser</cargo.remote.username>
<cargo.remote.password>consolePassword</cargo.remote.password>
<cargo.hostname>IP_ADDRESS</cargo.hostname>
<cargo.jboss.management-http.port>9990</cargo.jboss.management-http.port>
</properties>
</configuration>
</configuration>
<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-controller-client</artifactId>
<version>8.2.0.Final</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
The shame on this is the documentation and that no java people community have answer this post... have to be a .NET guy... what a shame....

Maven: clean the webapp directory before war:exploded?

quoting from maven war plugin usage page :
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<webappDirectory>/sample/servlet/container/deploy/directory</webappDirectory>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
How do i clean the content of the directory defined in the <webappDirectory>/sample/servlet/container/deploy/directory</webappDirectory> before exploding the war file ?
In my experience, the folder defined as the webappDirectory wont get cleaned, and so will have nonrelated files that was part of the webapp.
It'll be cool if i can add something to the current command im currently using to clean the webappDirectory, which is something like this :
mvn -o clean <cleanWebappDirectory here?> install war:exploded
Thank you !
You may want to look at adding the maven clean plugin, specifying the requisite folder to be cleaned. Something like below... Note that the directory should be relative.
<build>
[...]
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<filesets>
<fileset>
<directory>sample/servlet/container/deploy/directory</directory>
<includes>
<include>*</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
[...]
</build>

Maven: specify the outputDirectory only for packaging a jar?

How can I specify the outputDirectory only for packaging a jar?
http://maven.apache.org/plugins/maven-jar-plugin/jar-mojo.html this shows all parameters, but how can I set them in the commandline or pom.xml?
on command line
-DoutputDirectory=<path>
and in pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<outputDirectory>/my/path</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
Parameter Expressions
About command line usage:
The parameter documentation specifies that the parameter is initialized to the value of the property ${project.build.directory} (which is the property referring to the target folder)
Here's what this means:
For mojos that are intended to be
executed directly from the CLI, their
parameters usually provide a means to
be configured via system properties
instead of a <configuration/> section
in the POM. The plugin documentation
for those parameters will list an
expression that denotes the system
properties for the configuration. In
the mojo above, the parameter url is
associated with the expression
${query.url}, meaning its value can be
specified by the system property
query.url as shown below:
mvn myquery:query -Dquery.url=http://maven.apache.org
Reference:
Guide to Configuring Plug-ins > Generic Configuration
Configuring ${project.build.directory}
However, ${project.build.directory} is not a system property, it's a property of the Project's Build object.
You can't set maven's internal properties directly on the command line, but you can get there with a little trick by adding placeholders in your pom.xml:
<build>
<directory>${dir}</directory>
</build>
Now, the output directory is set via the property from the command line (using -Ddir=somedirectory). Downside: now you always have to use the -Ddir parameter on the command line.
Using Profiles
But there's help here, too. Just use a profile when you want to configure the directory:
<profiles>
<profile>
<id>conf</id>
<build>
<directory>${dir}</directory>
</build>
</profile>
</profiles>
Now you can either do
# everything goes in someOtherDir instead of target
mvn clean install -Pconf -Ddir=someOtherDir
or plain old
# everything goes in target
mvn clean install
Configuring the Jar Plugin
Now if you just want to change the jar outputDirectory from the command line without redirecting everything from target, we'll modify the profile to configure the plugin from a command line property:
<profiles>
<profile>
<id>conf</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<outputDirectory>${dir}</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
The usage is identical to above:
# everything goes in someOtherDir instead of target
mvn clean install -Pconf -Ddir=someOtherDir
Thanks #Sean Patrick Floyd for the excellent explanation.
Instead of creating a profile and using mvn always by -P switch, I'd like to use another way that making a default value of property ${dir}.
Just define ${dir}'s default value as ${project.build.directory}
<properties>
<dir>${project.build.directory}</dir>
</properties>
and same as #Sean Patrick Floyd, set outputDirectory.
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<outputDirectory>${dir}</outputDirectory>
</configuration>
</plugin>
</plugins>
Now you can either do
# everything goes in someOtherDir instead of target
mvn clean install -Ddir=someOtherDir
or plain old
# everything goes in target
mvn clean install
If you wish copy dependency jars as well to a target folder, use maven-dependency-plugin.
<project>
...
...
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

how to ask maven war plugin to copy particular jar file into warfile/web-inf/lib

I have a simple.jar file that stay in c:/JAR.
When i used maven war plugin to create a war file, it will copy all the dependencies into lib folder.
How can i ask maven to copy simple.jar into lib folder as well.
I believe this will work for you. I'm not 100% sure the C:\\JAR is correct though. You might have to fiddle with this syntax.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<webResources>
<resource>
<directory>C:\\JAR</directory>
<targetPath>WEB-INF/lib</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>

install war file at server deploy directory

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