Deploying spring boot app using Heroku Maven Plugin - spring-boot

I would like to deploy my spring-boot app to Heroku.
I got it working just fine using heroku-cli-deploy plugin with the command:
heroku deploy:jar "my-app.jar" --app {my-app-name}
But now I would like to use heroku-maven-plugin to do this deployment.
I have my pom.xml build section:
<build>
<finalName>${artifact-name}-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
<version>3.0.4</version>
<configuration>
<appName>${heroku.appName}</appName>
<includeTarget>false</includeTarget>
<includes>
<include>${project.build.directory}/${project.build.finalName}.jar</include>
</includes>
<jdkVersion>${java.version}</jdkVersion>
<processTypes>
<web>java $JAVA_OPTS -jar
${project.build.directory}/${project.build.finalName}.jar</web>
</processTypes>
</configuration>
</plugin>
</plugins>
</build>
And I'm using mvn clean heroku:deploy to deploy the app. The deployment fails showing the following error:
Error: -jar requires jar file specification
What am I missing?

This change made it work:
<processTypes>
<web>java $JAVA_OPTS -jar ./target/${project.build.finalName}.jar</web>
</processTypes>

Related

Google Cloud SDK App-Engine project priority

To deploy my app I use this in bash:
mvn appengine:deploy -Dproject=projectname1
This is my pom.xml:
<build>
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>1.3.1</version>
<configuration>
<project>projectname2</project>
</configuration>
</plugin>
</plugins>
</build>
At the moment, my app is deployed in projectname2 while I want it to ignore pom's project configuration and give priority on the sh one.
I red the Cloud SDK documentation but I didn't notice how to do.
I need this to choose where Jenkins will deploy the app on, regardless the pom's plugin setting.

using spring-boot-maven-plugin with exec classifier, but can't run the app from IDE anymore

I am working on Spring Boot 1.5.9 application, and I am generating a jar that contains a Spring Boot application, but that can also be imported as part of another project.
Therefore, I am using below config to generate 2 jars : the exec, and the regular lib ones.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
However, now that I have this, I am not able to run the application from my IDE (Intellij) anymore, as it's not finding the application.yml.
I am sure there's a trick, but I can't find anything.. Any idea ?
I ended up using Maven profiles :
<profiles>
<profile>
<id>makeRelease</id>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
When I make the release, I am calling this profile (maven with argument -P makeRelease) so that it generates the 2 jars.
The rest of the time, the regular behavior applies.

Openshift 3 WAR

In the Openshift 2 I had such a profile in a pom.xml file:
<profile>
<!-- openshift red hat cloud build profile -->
<id>openshift</id>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<outputDirectory>webapps</outputDirectory>
<warName>${project.artifactId}</warName>
</configuration>
</plugin>
</plugins>
</build>
</profile>
and this was responsible for putting a WAR file to directory from where it was automatically deployed to Tomcat-like-jboss.
Now - in Openshift 3 - by using browser-embeded ssh console I checked that WAR files were build and put into /tmp/src/webapps directory. Where should I move it (how should I modify the Maven profile) to make new Openshift 3 Tomcat-like-jboss deploy it and host it?
I've found the answear - the correct outputDirectory is target, so the WAR plugin looks now:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<outputDirectory>target</outputDirectory>
<warName>ROOT</warName>
</configuration>
</plugin>
I've found it there: https://github.com/gshipley/book-helloworld/blob/master/pom.xml - in a sample OpenShift app. Now my WAR are being deployed to the WildFly!
Moreover - this free e-book is really heplful: https://www.openshift.com/promotions/for-developers.html.

Deploy Java EE Wildfly REST Application to Openshift

I am new to Openshift and having trouble with deploying my Java EE project to it. I have made REST API for a simple webstore. Locally it works fine on Wildfly 9.0.2 I want to deploy it on openshift. I 've made new wildfly9 + mysql5.5 application using eclipse openshit jboss plugin and added a profile to root pom.xml:
<profiles>
<profile>
<id>openshift</id>
<build>
<finalName>webstore</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<outputDirectory>deployments</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
My root project consist of several maven modules including store-ear (EAR), store-jpa (JAR), store-rest (WAR), store-web (WAR), store-services (EJB), store-rest-interfaces (JAR),store-service-interfaces (JAR).
I have changed datasourse in JPA configuration (persistence.xml) to use MysqlDB on Openshift.
After pushing back to openshift the build is succesfull, but when it gets deployed it is missing some dependancies (ClassNotFoundException), and fails to deploy main war file.
You use a maven-war plugin in your openshift maven profile.
But you say that your project is packaged as en ear. So you should probably deploy this ear which contains all your project modules (wars, ejbs, libs...) instead of a specific war of your project.
To achieve this, you have to use a maven-ear plugin instead of the maven-war one in your openshift profile which would look like this:
<profile>
<id>openshift</id>
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10</version>
<configuration>
<outputDirectory>deployments</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</profile>

How to deploy Spring Boot application to different URL on Tomcat?

I am building and deploying my Spring Boot application into Tomcat with mvn tomcat:deploy and with this configuration:
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://127.0.0.1:8080/manager/text</url>
<server>tomcat</server>
<path>/${project.build.finalName}</path>
<username>admin</username>
<password>password</password>
</configuration>
</plugin>
</plugins>
</build>
Application runs then at /${project.artifactId}. I would like to deploy the application to the another URL, ideally to set target URL while I call Maven deploy command. Is it possible? If so, how can I achieve it?
You can override maven properties from command line with -D option.
To specify another url for your app the interesting properties are maven.tomcat.port and maven.tomcat.path.
The following command line should do the trick :
mvn -Dmaven.tomcat.port=8181 -Dmaven.tomcat.path=/custom tomcat:deploy

Resources