How to deploy a maven web project using Wildfly to Heroku? - maven

I've built a Java EE 7 web app on Wildfly 10.
I'm trying to deploy it to Heroku, but I can't make the application work.
All I could do, so far, was to get Wildfly to work, but it seems to be running without my application.
I pushed the application using git:
git push heroku master
And it is running the unpack goal.
The Procfile:
web: target/wildfly-10.1.0.Final/bin/standalone.sh -Djboss.http.port=$PORT -b 0.0.0.0
The pom.xml
<!-- Commented to keep it simple -->
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${version.wildfly.maven.plugin}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-dist</artifactId>
<version>${version.wildfly}</version>
<type>zip</type>
<overWrite>false</overWrite>
<outputDirectory>target</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<outputDirectory>target/wildfly-${version.wildfly}/standalone/deployments</outputDirectory>
<warName>${project.artifactId}</warName>
</configuration>
</plugin>
</plugins>
</build>

You need to add your ear/war into your wildfly deployment folder. To do that you need a separate plugin or something that will do that.
I want to try this too, so I will for example use this plugin under ear pom:
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>${version.ear.plugin}</version>
<configuration>
<outputDirectory>../pathto/deployments</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
You might need to use something else for a war.
To test it works just try compiling it and watch if your app is in the deployment folder.

Related

Spring boot Maven rpm

I have a spring boot application. Today maven creates jar out of the project. Below is my build section of pom.xml
<build>
<finalName>xsmartadapter</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
With adding below in the above build section I'm able to generate rpm.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>rpm-maven-plugin</artifactId>
<version>2.1.5</version>
<extensions>true</extensions>
<executions>
<execution>
<id>generate-rpm</id>
<goals>
<goal>rpm</goal>
</goals>
<phase>prepare-package</phase>
</execution>
</executions>
<configuration>
<group>Application</group>
<packager>SWWDC</packager>
<mappings>
<mapping>
<directory>${basedir}/target</directory>
<sources>
<source>
<location>target/classes</location>
</source>
</sources>
</mapping>
</mappings>
<name>xsmartadapter</name>
<executable>rpmbuild</executable>
<workingDirectory>${basedir}</workingDirectory>
</configuration>
</plugin>
But when I try to install and start the service sudo service 'name' start. It says service not found.
But when I create a tar.gz file and generate a rpm using rpmbuild -ba target/filename.spec I'm able to start the service.
My goal is to generate a rpm (out of maven), install it and start the service.
Please provide some suggestion.

Auto deploy maven project war file in company's server

I have created a maven project in netbeans and there i manually build a war file and upload to server.
My pom file only contains:
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
...
<dependency>
<dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-maven-plugin</artifactId>
<version>4.0.0-release</version>
<configuration>
<log4jConfiguration>${basedir}/log4j.properties</log4jConfiguration>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
<!--<plugin>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-maven-plugin</artifactId>
<version>2.9.0</version>
<executions>
<execution>
<goals>
<goal>export</goal>
</goals>
</execution>
</executions>
<configuration>
<jdbcDriver>com.mysql.jdbc.Driver</jdbcDriver>
<jdbcUrl>jdbc:mysql://localhost:3306/login</jdbcUrl>
<jdbcUser>root</jdbcUser>
<packageName>com.titas.model</packageName>
<targetFolder>${project.basedir}/target/generated-sources/java</targetFolder>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
</dependencies>
</plugin>-->
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.mysema.query.apt.jdo.JDOAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Now i want to auto deploy war file in company's server whenever i will build in netbeans.
Is there any tag to auto deploy in server in pom.xml? Like if i use any plugin where i will specify my server folder war file will auto deploy there and replace previous one.
Thanks in advance!!
I don't have experience deploying to Tomcat specifically, and apparently it's different based on the version.
Tomcat 6/7
For Tomcat 6 replace "tomcat7" with "tomcat6" in the following lines.
Use the tomcat7-maven-plugin by putting this in the <build><plugins> section of your pom.xml:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<url>http://www.example.com:1234/mymanager</url>
</configuration>
</plugin>
Obviously change the url to match the URL of the server/manager you're trying to deploy to. If you need to specify credentials add a <server>servername</server> tag to the configuration block and put this in your maven settings.xml (under path <settings><servers>):
<server>
<id>servername</id>
<username>myusername</username>
<password>mypassword</password>
</server>
For other configuration changes see the plugin page linked above.
Once it's configured you should be able to run mvn package tomcat7:deploy to deploy to your server. Other maven goals are here.
Tomcat 8
The best I'm finding is this question: Tomcat 8 integration with Maven
The accepted answer uses the cargo-maven2-plugin, but looking at how it's configured I don't think that will go to a remote machine.
Alternately you can try the tomcat7 plugin as detailed above, I did see this blog post that suggests it works for 8 too.

Modifying jar filename using maven

I have a requirement that all the artifacts created by maven bear a build number.
The build number is stored in a properties file. I'm successful with controlling the names of generated EAR and WAR artifacts but not the JAR. Here are the relevant excerpts from pom.xml.
I expected the maven-jar-plugin configuration to work but it does not, I end up with jar always named SelfService-2.jar, whereas when buildNumber.properties contains buildNumber=40, maven generates SelfService-2.40.war and SelfService-2.40.ear.
How do I get the build number into the jar name?
Thanks in advance.
<artifactId>SelfService</artifactId>
<name>SelfService</name>
<packaging>war</packaging>
<version>2</version>
<build>
<finalName>${project.artifactId}-${buildNumber}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<finalName>${project.artifactId}-${buildNumber}</finalName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<finalName>${project.artifactId}-${buildNumber}</finalName>
</configuration>
</plugin>
....
I got what I was after by using the following configuration of maven-jar-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<finalName>${project.artifactId}-${buildNumber}</finalName>
</configuration>
</execution>
</executions>
<configuration>
<finalName>${project.artifactId}-${buildNumber}</finalName>
</configuration>
</plugin>

Can I produce both jar and war of a project in maven?

I have a project(A) in maven that has packaging of war. One other project(B) depends on A and it needs project A jar file but in phase of compile, the war of project A will produce and no jar is available for project B.
How can I create a jar of project A in phase of compile so that project B can use it?
I would suggest to go a different way and use the maven-war-plugin which can produce a separate artifact for the classes which can be used like the following:
<dependency>
<groupId>myGroup</groupId>
<artifactId>myArtifact</artifactId>
<version>myVersion</myVersion>
<classifier>classes</classifier>
</dependency>
This can be achieved by using the following configuration in your war module:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<attachClasses>true</attachClasses>
</configuration>
</plugin>
...
</plugins>
I found the solution : :)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>make-a-jar</id>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<packaging>jar</packaging>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<file>
${project.build.directory}/${project.artifactId}-${project.version}.jar
</file>
</configuration>
</execution>
</executions>
</plugin>

How to Deploy only the sub-modules using maven deploy?

How do i deploy only the sub-modules of the project?
i have a project as;
ProjectA
- Submodule B
- Submodlue C
- Submodule D
The submodules are packaged as jar and is deployed to maven repo.how can only the sub -modules be deployed to the maven repository and not the main project?
Put this in module(s)(or module's pom.xml) that you don't want to deploy:
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>
Since this is inherited by submodules, you have to put this in submodules that you do want to deploy:
<properties>
<maven.deploy.skip>false</maven.deploy.skip>
</properties>
Another suggestion could be doing the following:
mvn deploy -pl SubModuleB
This worked for me. Similar to other answer except added missing plugins element. Add to parent POM.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.4</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
You can use the technique described in my blog.
In this case, you'd disable default-deploy (or what the name is) in the root pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<id>default-deploy</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
And then enable it for submodules:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
</execution>
</executions>
</plugin>
This is working on my side
Put the plugin declaration in the parent pom , skip=true, but set inherited=false.
This prevents from repeating the on each child modules.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<skip>true</skip>
</configuration>
<inherited>false</inherited>
</plugin>
You can configure the maven-deploy-plugin in the POM of a module to exclude it from the deploy:
<build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.4</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
...
</build>

Resources