Heroku not able to find the worker - java

https://devcenter.heroku.com/articles/run-non-web-java-processes-on-heroku
I followed the above tutorial to deploy my app on heroku. When i package the code in my IDE (intelliJ IDEA) everything works fine. A target folder is created that has a sub floder named bin and it contains two files : worker and worker.bat
From my root director, if i run the command sh target/bin/worker then the application executes properly and desired.
On the otherhand after i push the code to heroku and use the command :
heroku ps:scale worker=1
I get this error :-
sh: 0: Can't open target/bin/worker
Process exited with status 127
State changed from up to crashed
My POM.xml is exactly same as it is in the tutorial with just few extra dependencies.
What is the issue and how can it be resloved ?
POM.xml :-
<dependencies>
....
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>1.1.1</version>
<configuration>
<assembleDirectory>target</assembleDirectory>
<programs>
<program>
<mainClass>MainClass</mainClass>
<name>worker</name>
</program>
</programs>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>assemble</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>

Related

Maven : Download of executable zip based on OS

I want to download a zip file via mavens POM.XML, but based on the OS i need different URLs (Linux/Windows).
How can I change the URL based on the OS maven is executed? (locally, its Windows, on Jenkins its then Linux)
This is how the plugins part of my POM.XML looks like:
<build>
<plugins>
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<executions>
<execution>
<!-- the wget goal actually binds itself to this phase by default -->
<phase>process-resources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>https://test/chromedriver_win32.zip</url>
<unpack>true</unpack>
<outputFileName>chromedriver</outputFileName>
<outputDirectory>${project.build.directory}/chromeDriver</outputDirectory>-->
<outputDirectory>${user.home}/localdata/tools/chromeDriver</outputDirectory>
<overwrite>true</overwrite>
<skipCache>true</skipCache>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Maven - URI is non hierarchial

Im trying learn Spring and Maven but im having some trouble.
When I go to run my tests from the terminal using mvn clean install I'm getting this error: java.lang.IllegalArgumentException: URI is not hierarchical . This is the block of code that throws the error :
LocationWeatherRootResponseTest.class.getClassLoader().getResource("extent.xml")).toURI()
When I change the above code to the following Im getting a null pointer exception.
LocationWeatherRootResponseTest.class.getClassLoader().getResourceAsStream("extent.xml")))
Update
When I change the code to the below Im getting a new error.
File file = new File(WeatherTest.class.getClassLoader().getResource("extent.xml").getPath());
Reporter.loadXMLConfig(file);
stacktrace :
java.io.FileNotFoundException: file:/home/user/IdeaProjects/spring-cucumber-test-harness/common/target/common-1.0-SNAPSHOT.jar!/extent.xml (No such file or directory)
I managed to solve this issue using maven-remote-resources-plugin . Now when I run mvn clean install on the master POM the framework runs from e2e.
In the module containing the resources I wanted to share, I added the following to the POM file
<build>
<plugins>
<plugin>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.7.0</version>
<executions>
<execution>
<goals>
<goal>bundle</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>**/*.xml</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
In the module where I want to use the resource. I added the following
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.7.0</version>
<configuration>
<resourceBundles>
<resourceBundle>{groupId}:{resource artifactId}:1.0-SNAPSHOT</resourceBundle>
</resourceBundles>
</configuration>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
</plugin>

spring-boot-maven-plugin doesn't create fat jar

I'm using spring-boot-maven-plugin to package my REST service. I'm building the jar using mvn clean install or mvn clean package. After I decompile the jar, I don't find any of the dependencies added (I was expecting it to be a fat jar with all dependencies)
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.9.RELEASE</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>repackage</goal>
<goal>build-info</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>true</executable>
<finalName>myapp</finalName>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
When I run the spring boot using java -jar myapp.jar -Drun.jvmArguments="-Dspring.profiles.active=qal" I'm getting ClassNotFoundException for many of the classes. It's clear that artifact didn't build as expected. However, if I start spring boot application using maven ./mvnw spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=qal" I guess, it finds all the dependencies in target folder hence works fine. How can I fix the build issue so that I can start app using java -jar command.
EDIT: It's multi-module maven project
it seems you are using a wrong command. mvn clean package is maven command, you should use command 'repackage', it used for
Repackages existing JAR and WAR archives so that they can be executed
from the command line using java -jar
as it mentioned here https://docs.spring.io/spring-boot/docs/current/maven-plugin/repackage-mojo.html
Or probably it's plugin configuration issue. Just checked: it works with spring-boot-maven-plugin-2.0.0.RELEASE
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
</plugin>
Use this one
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>${start-class}</mainClass>
<executable>true</executable>
<fork>true</fork>
<!-- Enable the line below to have remote debugging of your application on port 5005
<jvmArguments>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005</jvmArguments>
-->
</configuration>
</plugin>

how to update a property file using maven or pom.xml

I have created an automation framework where I am reading values from a property file say "config.properties".
My config.propertioes file contains following :
BrowserName=${browser}
Environment=${env}
I am reading browser value from the property file and passing it to my selenium script to run it.
Now I wants to replace "${browser}" && "${env}" with value "ie" && "IT" using pom.xml. Is there any way/plugin using which I can edit a property file using pom.xml.
Please suggest.
#Keshava
I am putting whole example below as suggested below :
1.Have 2 property files: ◦project.properties: This is the file that we commit in the repository. It consists data as follows: ◾project.connection.username=##DB_USERNAME##
project.connection.password=##DB_PASSWORD##
◦build.properties: This is the file that we do not commit in the repository and is maintained at each of the deployment environments, be it the developers env., UAT env or Production env. The contents of this file are as follows: ◾db.username=mydbuser
db.password=mydbpassword
2.In the project’s pom.xml add the following plugin and a execution:
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>maven-replacer-plugin</artifactId>
<version>1.3.5</version>
<executions>
<execution>
<id>replaceTokens</id>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>target/classes/project.properties</file>
<replacements>
<replacement>
<token>##DB_USERNAME##</token>
<value>${db.username}</value>
</replacement>
<replacement>
<token>##DB_PASSWORD##</token>
<value>${db.password}</value>
</replacement>
</replacements>
</configuration>
</plugin>
from above, I understand that "##DB_USERNAME##" is from "project.properties". But, from which properties file this "${db.username}" value will be taken?. how my pom will understand from where to take "${db.username}" .
Do I need to pass this value in maven goal like below :
mvn clean install -Ddb.username=myuserid
Hello you can use the maven resource plugin.
This plugin implement "Maven Filtering".
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>selenium-profile-chrome</id>
<!-- here the phase you need -->
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/selenium</outputDirectory>
<resources>
<resource>
<directory>src/non-packaged-resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
...
</build>
...
</project>
you could tryin using the maven replacer plugin
See https://code.google.com/archive/p/maven-replacer-plugin/
See an example here

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.

Categories