Can Maven Deploy a Module to JBoss? - java

We have a Maven project that we are using to deploy several wars to a JBoss server. We recently noticed that one of the jars that a couple of our wars depend on, uses Xerial. When Xerial starts it tries to load up a native driver, but only the first one successfully loads the native driver and the rest fail and fall back on a pure Java implementation because the native driver is already in a classloader. We would really like to gain the performance back by being able to load the native driver on all the wars.
It looks to me like the best way to do this would be add the jar we depend on to the JBoss server as a module, and then have the services depend on it.
My question is, is there a way we can get our Maven build to do this? Or are we going about this in the completely wrong way?

After a few days of looking, and talking to a couple of people who were much more familiar with JBoss-Maven interaction than me, it turns out the answer to my question is that it cant currently be done. There is no Maven plugin capable of deploying a Module to JBoss. This is largely in part to the fact that the modules are only loaded by JBoss when it starts, although if anyone is feeling particularly ambitious and wants to write their own Maven plugin, it could theoretically be worked around.
The answer #Robert Scholte left is a good one, and I learned from it, however it didn't actually answer my question.

First and most of all Apache Maven is a build management tool. It will "package" a project and will normally upload it to a repository so it can be used by other projects.
However, there are plugins available, which can deploy to JBoss:
http://mojo.codehaus.org/jboss-maven-plugin/ (maybe combined with http://mojo.codehaus.org/jboss-packaging-maven-plugin/ )
http://cargo.codehaus.org/
The first is JBoss specific, the latter a generic Java EE-container deploy plugin

I'd suggest to put your jar in the lib folder of the jboss server. This way, the jar is loaded in the shared classpath when the server starts. This will definitively serve the purpose.
Here is the jboss folder structured expleained.
http://docs.jboss.org/jbossas/guides/installguide/r1/en/html/dirs.html

I know this question has been marked as answered and the answer is that this currently is not possible, but I want to provide an alternative view. I am currently deploying Jboss modules to EAP 6.1 with Maven at my job. What we have done is use the maven-wagon plugin to scp the module to the tmp directory on the jboss server. I then use the maven-wagon plugin to issue a ssh command to the server to call the jboss-cli.sh script and tell it to perform a module installation. Here is a sample config:
<profile>
<id>uat</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>switchEnv</name>
<value>uat</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>1.0-beta-5</version>
<executions>
<execution>
<id>upload-file-qa-server-one</id>
<phase>deploy</phase>
<goals>
<goal>upload-single</goal>
</goals>
<configuration>
<fromFile>${project.build.directory}/${project.build.finalName}.${project.packaging}</fromFile>
<url>scp://jboss#jboss-server-1/tmp/</url>
<toFile>${project.name}.${project.packaging}</toFile>
</configuration>
</execution>
<execution>
<id>upload-file-qa-server-two</id>
<phase>deploy</phase>
<goals>
<goal>upload-single</goal>
</goals>
<configuration>
<fromFile>${project.build.directory}/${project.build.finalName}.${project.packaging}</fromFile>
<url>scp://jboss#jboss-server-2/tmp/</url>
<toFile>${project.name}.${project.packaging}</toFile>
</configuration>
</execution>
<execution>
<id>install-module-qa-server-one</id>
<phase>deploy</phase>
<goals>
<goal>sshexec</goal>
</goals>
<configuration>
<serverId>jboss-server-1</serverId>
<url>scp://jboss#jboss-server-1/tmp</url>
<commands>
<command>/opt/jboss/bin/jboss-cli.sh -c --command="module add --name=${project.name} --resources=/tmp/${project.name}.${project.packaging} --dependencies=javax.api,javax.transaction.api"</command>
<command>sleep 5</command>
<command>rm -f /tmp/${project.build.finalName}.${project.packaging}</command>
</commands>
</configuration>
</execution>
<execution>
<id>install-module-qa-server-two</id>
<phase>deploy</phase>
<goals>
<goal>sshexec</goal>
</goals>
<configuration>
<serverId>jboss-server-2</serverId>
<url>scp://jboss#jboss-server-2/tmp</url>
<commands>
<command>/opt/jboss/bin/jboss-cli.sh -c --command="module add --name=${project.name} --resources=/tmp/${project.name}.${project.packaging} --dependencies=javax.api,javax.transaction.api"</command>
<command>sleep 5</command>
<command>rm -f /tmp/${project.build.finalName}.${project.packaging}</command>
</commands>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>

It´s not possible beause you have to use an OSGI approach.
To use maven try to work with OSGI within EAP, but it depends what you looking for. OSGI is supported since JBoss EAP 6.1.
If you are trying to work with EAI try to work with JBoss Fuse instead of EAP.
Then you will work with maven repositories, nexus or similar, hot deploy and all OSGI bundles stuff.

Related

Can we configure Spring Boot Executable Jar?

I have a spring boot application based on maven and has several modules. I do use a spring-boot-maven-plugin, however, this plugin is only used on one of the modules. Even though the individual jar files for each modules are pretty small, the executable produced by the main module where I use this plugin with "repackage" goal is pretty large (About 750 MB).
I expanded the jar file that is created and was a little surprised to see that that it has bundled the jar files for several operating systems such as windows, linux, android etc.
If you see the opncsv jar file in the screenshot below, it appears it has bundled those jars for 13 different Operation systems !!
I understand that the executable created this way will be runnable in cross platforms, but just wondering if there is a way to configure this executable creation so that it only packages for certain OS only such as linux where I am running this app on.
The large executable just seems like an overkill in my situation.
Here is the plugin
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
<mainClass>org.blabla.products.webapp.Application</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Here are the dependency versions of different jars that i am using.
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<mysql-connector-java.version>5.1.40</mysql-connector-java.version>
<!--CHECKED FOR CURRENCY AND UPGRADED AS NEEDED ON 1/27/2019-->
<findbugs-maven-plugin.version>3.0.5</findbugs-maven-plugin.version>
<jacoco-maven-plugin.version>0.8.2</jacoco-maven-plugin.version>
<springfox-swagger2.version>2.9.2</springfox-swagger2.version>
<org.jsoup.version>1.11.3</org.jsoup.version>
<opencsv.version>4.4</opencsv.version>
<httpclient.version>4.5.6</httpclient.version>
<dl4j.version>1.0.0-beta3</dl4j.version>
<spring-web.version>5.1.4.RELEASE</spring-web.version>
<gson.version>2.8.5</gson.version>
<ehcache.version>3.6.3</ehcache.version>
<guava.version>27.0.1-jre</guava.version>
<thymeleaf-extras-springsecurity4.version>3.0.4.RELEASE</thymeleaf-extras-springsecurity4.version>
</properties>
I guess you can try to exclude it with maven. This was already answered here.

Multiple java version in maven build

I am working on one of the modules of a multi-module project. I am developing a java plugin to deploy my gigaspace application in pre-integration-test phase in maven.
The build happens on Teamcity and current JAVA_HOME points to Java 6 on which whole repository is built. Now, when deploying the application in pre-integration-test phase, it needs Java 7 because it uses some 3rd party libraries which were compiled in Java 7.
Is there any way I can somehow use Java 7 for deploying my application in pre-integration-test phase, but use Java 6 for compilation?
It seems that this is not straightforward. If you look at the plugin goal that gets associated with the lifecycle phase named pre-integration-test, then perhaps you can control its execution configuration:
<plugin>
...
<execution>
<id>...</id>
<phase>pre-integration-test</phase>
<goals>
<goal>...</goal>
</goals>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</execution>
</executions>
</plugin>
I haven't tried it myself. Also, see another somewhat similar question and its answer here. It's also useful to run mvn help:effective-pom to see what is going on.
If the purpose is to generate JAVA 6 bytecode, then you can use JAVA 7 (JAVA_HOME points to JAVA 7) for the whole lifecycle that include integration tests, but configure the maven-compiler-plugin with the version 1.6:
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>

How to run a multiple module project using Maven on NetBeans [duplicate]

I am new to maven. So I have a project with pom.xml file. So I ran that with maven and the build was successful. I have glassfish. Glassfish is already running separately. So now what is the next step to run the project with Glassfish? My IDE is eclipse.
You have to first tell Maven to build the WAR, check out this plugin for that: http://maven.apache.org/plugins/maven-war-plugin/.
Then you need to tell maven how to deploy to glassfish, you can either configure a Maven execution plugin to do this (see here: https://www.mojohaus.org/exec-maven-plugin/). Or you can look around for a custom plugin devoted to integrating maven with glassfish. This one looks promising, but I have not used it: http://maven-glassfish-plugin.java.net/.
Maven provides a lot of basic functionality out of the box, but most of the cooler stuff with build automation is done through plugins.
Update
Just updating to add a very simple Pom that will do a auto-deployment. Note: if you just run a "mvn clean install", with the packaging set to 'war', maven will build the .war file for you and place it in the target/ folder. You can take this and deploy it to glassfish manually if you just want to get started.
Below is part of a very simple pom that uses the Maven execution plugin to auto-deploy to glassfish as a function of the build:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
<phase>install</phase>
</execution>
</executions>
<configuration>
<executable>${path-to-asadmin-util}</executable>
<arguments>
<argument>deploy</argument>
<argument>--user=${username}]</argument>
<argument>--passwordfile=${password-file}</argument>
<argument>--host=localhost</argument>
<argument>--port=4848</argument>
<argument>target/${project.name}</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
This basically just calls the deploy command on the glassfish asadmin utility[1]. You need to fill in the following variables:
${path-to-asadmin-util} --> this is the path to your asadmin utility
(normally in the glassfish_home/bin)
${username} --> glassfish admin username
${password-file} --> password file for logging into glassfish
admin[2]
${project.name} --> name of your war
If you want to get more complicated I suggest taking a look at this thread: GlassFish v3 and glassfish-maven-plugin (Mac).
[1] - http://docs.oracle.com/cd/E18930_01/html/821-2433/deploy-1.html#SJSASEEREFMANdeploy-1
[2] - http://docs.oracle.com/cd/E18930_01/html/821-2435/ghgrp.html#ghytn
Additonnaly, you should have a glance at this StackOverflow thread, dealing with maven deployement in glassifsh : https://stackoverflow.com/a/1836691/1047365.
For further understanding of Maven, you should REALLY read this (free) book : http://www.sonatype.com/books/mvnref-book/reference/. This is THE reference for Maven.
We can explain you what Maven is doing, producing, etc ... but Sonatype made a great work and you'll probably learn more reading it than we could ever do !
Regards.
I found this tutorial useful: http://tshikatshikaaa.blogspot.com/2012/05/introduction-to-maven-concepts-crash.html

Issue setting the class path in Maven exec plugin when running a Main Class

I have embedded Jetty in my application. In order to automatically execute my integration tests on my build server I'd like Maven to start my application in the pre-integration-test phase. The integration tests are in another project than the application te be tested, because the tests are of a quite complex nature and should be seperated from production code.
I have tried to set up my application using the Maven exec plugin, but keep running into ClassNotFoundErrors. I use the maven-dependency-plugin to copy all dependencies to target/lib/. Until now, I haven't been able to figure out how to tell the exec plugin to add that lib folder to the class path.
This is my current exec plugin configuration:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>default-cli</id>
<phase>pre-integration-test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.zertificon.managementCenter.adminUi.server.WebApp</mainClass>
<!-- this does not work: -->
<classpath>${project.build.directory}/${libFolder}/</classpath>
</configuration>
</execution>
</executions>
</plugin>
The WebApp class I am trying to run originates from another Project and is installed in the local repository. I would highly apreciate any help.
Found the error: I have been using Jetty together with a Selenium Library that itself bundles Jetty, too. This lead to a wrong Jetty Version being loaded wich gave me class not found errors. Go figure.

How to build an MSI using WIX, JAVA and MAVEN

I'm trying to build an Msi from a java application which is using the spring and maven frameworks. From all the reading up i have done it would seem Wix is the best option. With some further research i started seeing mention of a Wix Maven plugin. The problem is following the websites and what i should place into the pom I don't get the Jar file being found.
has anyone succeded in this or know where to find the jar file?
Below is the Wix maven information.
<plugin>
<groupId>npanday.plugin</groupId>
<artifactId>wix-maven-plugin</artifactId>
<version>${version}</version>
<configuration>
<sourceFiles>
<sourceFile>installer/Kiddo.wxs</sourceFile>
</sourceFiles>
<outputDirectory>target</outputDirectory>
<objectFiles>
<objectFile>target/Kiddo.wixobj</objectFile>
</objectFiles>
<outputFile>target/Kiddo.msi</outputFile>
</configuration>
<executions>
<execution>
<id>wix</id>
<goals>
<goal>candle</goal>
<goal>light</goal>
</goals>
</execution>
</executions>
</plugin>
<dependency>
<groupId>org.apache.npanday.plugins</groupId>
<artifactId>wix-maven-plugin</artifactId>
<version>1.4.0-incubating</version>
</dependency>
these are wrapped with the additional maven tags and
Nathan
Still a work in progress, but you might also be interested in a more fully featured WiX maven lifecycle. There is more than just candle and light.
com.github.wix-maven:wix-maven-plugin
sourced from github

Categories

Resources