Deploy Java app to Heroku using Git - java

My project written using the Spark framework has this build config.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<verbose>true</verbose>
<fork>true</fork>
<compilerVersion>1.7</compilerVersion>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
<plugin>
<groupId>org.avaje</groupId>
<artifactId>ebean-maven-enhancement-plugin</artifactId>
<version>2.8.1</version>
<executions>
<execution>
<id>main</id>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
<configuration>
<classSource>target/classes</classSource>
<packages>somepath.domain.**</packages>
<transformArgs>debug=1</transformArgs>
</configuration>
</plugin>
</plugins>
</build>
Its main class resides in somepath.Bootstrap.
The Procfile sits next to the pom.
What should the contents of the Procfile be?
(I am deploying via git.)

Procfile contains command, that will be executed after deploying your appliaction (git push heroku master for you example i guess).
I do not very familiar with spark, but i guess it can be something like this:
web: mvn exec:java -Dexec.mainClass="somepath.Bootstrap"

A Procfile is a mechanism for declaring what commands are run by your application’s dynos on the Heroku platform.
Here is an example for a Java app:
web: java -cp target/classes:target/dependency/* Main
This is taken from a Heroku Java sample app that uses Spark.
Be aware that build tools, such as Maven, will not be available at runtime.

Related

Maven command runs fine on local machine, but not in Jenkins

So I have a maven project that has a profile
When I run the following in the terminal for my project, the tests will run just fine
mvn clean install -Pserial-integration-test -Dcucumber.options="--tags #'QR_Scan'" -Dtest.environment=PrePRod
When I run the following in a Jenkins project it will not run the tests that I need it too
clean install -Pserial-integration-test -Dcucumber.options="--tags #'QR_Scan'" -Dtest.environment=PrePRod
Jenkins settings
I have setup a Jenkins Maven project and told Jenkins where my Pom is, and I send the command below for the goal and options "clean install -Pserial-integration-test -Dcucumber.options="--tags #'QR_Scan'" -Dtest.environment=PrePRod"
Maven Settings
serial-integration-test
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<junitPlatformArtifactName>com.github.junit-team.junit5:junit-platform-engine</junitPlatformArtifactName>
<forkCount>1</forkCount>
<reuseForks>true</reuseForks>
<includes>
<include>**/Parallel*IT.class</include>
</includes>
<systemPropertyVariables>
<test.environment></test.environment>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.temyers</groupId>
<artifactId>cucumber-jvm-parallel-plugin</artifactId>
<version>5.0.0</version>
<executions>
<execution>
<id>generateRunners</id>
<phase>validate</phase>
<goals>
<goal>generateRunners</goal>
</goals>
<configuration>
<plugins>
<plugin>
<name>com.gm.onstar.rita.cucumber.CucumberReporter</name>
</plugin>
</plugins>
<glue>
<package>com.gm.onstar.rita.stepdefinitions</package>
</glue>
<featuresDirectory>src/main/resources/features</featuresDirectory>
<tags>
<tag>${cucumber.tag1}</tag>
<tag>${cucumber.tag2}</tag>
<tag>${cucumber.tag3}</tag>
<tag>${cucumber.tag4}</tag>
<tag>${cucumber.tag5}</tag>
<tag>~#Ignore</tag>
</tags>
</configuration>
</execution>
</executions>
</plugin>
What I have tried
I have tried putting in like this in Jenkins -Dcucumber.options="--tags #QR_Scan" and like this -Dcucumber.options='--tags #QR_Scan'
I have tried putting the profile -Pserial-integration-test with a space and without a space -P serial-integration-test
I have tried to see if I a missing some sort of plugin
I have tried to see if Mvn clean install or Mvn clear verify would run it on Jenkins
What it might be.
Jenkins does not like that my cucumber runner is in the main and not in java test folder?
Am I missing a plugin for Jenkins?
Am I typing the command in wrong in jenkins, and maybe missing some parentheses or something?
Any help would be appreciated. Thank you!

How to run java program using Maven

I am trying to run a Java project using Maven, need help on how to run
I tried with various options, Run As > Maven clean, Run As > Maven Install, Run As > Maven test, etc.
But the output is not showing in the console though build is successful
I am using eclipse and able to run java file using Run As > Java Application
My Build tag in pom.xml
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<mainClass>mypackage.classnamehavingmain</mainClass>
</configuration>
</plugin>
</plugins>
</build>
You should add the goal for execution
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>your_goal_name</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.example.Main</mainClass>
</configuration>
</plugin>
and then to execute you can perform :
mvn exec:your_goal_name
If you would like to run it from the terminal you can do mvn compile exec:java -Dexec.mainClass=mypackage.classnamehavingmain.

Running an Executable Jar using Maven

Is it possible to run an executable jar file using Maven?
A brief introduction to setup:
Environment is running on Centos
I have included the exec plugin into my maven POM and have it running a shell script that is meant to run the jar file and works fine using the terminal but I get Unable to access jarfile error when run in maven.
I have chmod the jar, shell and other files to 777
I have editted the sudoers file as suggested by other posts
I have also given maven and Jenkins root access
All of these changes still result in the above error and I have run out of ideas.
HELP!!!
POM File
<pluginRepositories>
<pluginRepository>
<id>smartbear-sweden-plugin-repository</id>
<url>http://www.soapui.org/repository/maven2/</url>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<!-- Run our Password Checker script -->
<id>Password Checker</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>src/pass/passCheck.sh</executable>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>eviware</groupId>
<artifactId>maven-soapui-plugin</artifactId>
<version>4.5.1</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>test</goal>
</goals>
<id>MPesa-Tests</id>
<configuration>
<projectFile>src/test/GenericAPI-G2-soapui-project.xml</projectFile>
<outputFolder>SoapUI-Results/</outputFolder>
<junitReport>true</junitReport>
<exportwAll>true</exportwAll>
<printReport>false</printReport>
<projectProperties>
<value>message=Tests Completed</value>
</projectProperties>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<configuration>
<outputDirectory>/usr/share/Surefire/</outputDirectory>
<reportDirectories>
<reportDirectories>/usr/share/Surefire/reports/</reportDirectories>
</reportDirectories>
</configuration>
</plugin>
</plugins>
</build>
</project>
I had this exact same need to execute a Spring Boot packaged application and solved it by using the maven dependency plugin to copy the artifact to /tmp (or anywhere for that matter) and then using the maven exec plugin to execute that jar using the exec:exec goal.

Maven WebApp tomcat7 system properties

We are using a maven dependency to add embedded tomcat on our webapplication. It works fine, but I need to add systemProperties to embedded tomcat, so that our webapp can use this systemProperties.
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<executions>
<execution>
<id>tomcat-run</id>
<goals>
<goal>exec-war-only</goal>
</goals>
<phase>package</phase>
<configuration>
<path>/html5</path>
<enableNaming>true</enableNaming>
<finalName>html5.jar</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
I tried to add system properties like this, but it didn't work. I added it
<build>
<plugins>
<plugin>
<configuration>
<systemProperties>
<dashboard.oracle.host>1.1.1.1</dashboard.oracle.host>
<dashboard.oracle.port>1521</dashboard.oracle.port>
<dashboard.oracle.sid>orcl</dashboard.oracle.sid>
<dashboard.oracle.url>
jdbc:oracle:thin:#${dashboard.oracle.host}:${dashboard.oracle.port}:${dashboard.oracle.sid}
</dashboard.oracle.url>
<dashboard.oracle.username>username</dashboard.oracle.username>
<dashboard.oracle.password>password</dashboard.oracle.password>
</systemProperties>
</configuration>
...
</plugin>
</plugins>
</build>
In general the way you have added the system properties to the tomcat plugin is correct:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<systemProperties>
<example.value.1>alpha</example.value.1>
<example.value.2>beta</example.value.2>
</systemProperties>
</configuration>
</plugin>
Taken from the Apache Docu.
the system properties in the Maven Plugin are only for when running the tomcat7:run mojo ... in order to pass in the system properties to the executable war (jar), you must do it on the command line:
java -DsysProp1=value -DsysProp2=value -jar exec-war.jar

Weblogic 11g Maven deploy Issue

I am trying to deploy a war file on Weblogic 11g server using Maven (weblogic-maven-plugin) v 10.3.4
But I am getting below error on running mvn wls:deploy
Cannot find MW_HOME at location.....C:\work_maven\springmvc\Oracle\Software. You must define the middlewareHome parameter for the Maven goal.
I have installed weblogic at C:\bea11g
I also have MW_HOME set to above weblogic path.
My project's pom.xml build looks like this:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>com.oracle.weblogic</groupId>
<artifactId>weblogic-maven-plugin</artifactId>
<version>10.3.4</version>
<configuration>
<middlewareHome>C:\bea11g</middlewareHome>
<adminurl>t3://localhost:7001</adminurl>
<user>weblogic</user>
<password>weblogic1</password>
<upload>true</upload>
<action>deploy</action>
<remote>false</remote>
<verbose>true</verbose>
<source>
${project.build.directory}/${project.build.finalName}.${project.packaging}
</source>
<name>${project.build.finalName}</name>
</configuration>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Any help is greatly appreciated.
Thanks.
MW_HOME should be set to C:\bea11g, the directory where you installed WebLogic.
However, it looks like it is set to C:\work_maven\springmvc\Ora cle\Software.
Double check your environment variable setup and retry.
[Edit]
See here for reference:
http://docs.oracle.com/cd/E24329_01/web.1211/e24368/maven.htm
It looks like you need to set weblogicHome rather than middlewareHome in your plugin configuration.
It looks like something was wrong with the weblogic-maven-plugin installation and configuration.
I followed the link http://docs.oracle.com/cd/E21764_01/web.1111/e13702/maven_deployer.htm and now it is working fine.

Categories