Java Heroku application run locally with foreman - java

I'm following the "Getting Started with Java on Heroku" guide at
https://devcenter.heroku.com/articles/getting-started-with-java
I follow the steps till I deploy and execute succesfully the application downloaded from GitHub.
When I try to execute it locally on Windows XP with the command
foreman start web
I get the error:
web.1 | started with pid 3388
web.1 | Error: Could not find or load main class Main
web.1 | exited with code 1
system | sending SIGKILL to all processes
My Procfile is:
web: java %JAVA_OPTS% -cp target\classes:target\dependency\* Main
And
>echo %JAVA_OPTS%
-Xms256m -Xmx512m
Can anyone suggest me how to solve?

Quotes and semicolon
web: java %JAVA_OPTS% -cp target\classes;"target\dependency\*" Main

I ran into this issue while running through the https://devcenter.heroku.com/articles/getting-started-with-java tutorial.
After tinkering with some of these answers I discovered that step six at https://devcenter.heroku.com/articles/getting-started-with-java#define-a-procfile tells the answer.
When you see instructions to run your app with foreman, append an extra -f Procfile.windows flag to ensure your Windows-specific Procfile is picked up. For example: foreman start web -f Procfile.windows
Once I switched to the foreman start web -f Procfile.windows command, everything worked smoothly.

Same problem with java-getting-stared app downloaded from heroku server. Changing to ";" works on Windows. Still need ":" on heroku linux server.

Related

Heroku process crashing as soon as the process starts

I have a simple Micronaut server I am trying to launch on Heroku by building it with a heroku.yml but for some reason when I check the logs the process exits as soon as it starts. The docker image runs just fine locally and nothing else prints out in the logs so I can't find out why.
Here is my Dockerfile
FROM node as build-frontend
WORKDIR /app
COPY frontend/myfrontend/package.json .
COPY frontend/myfrontend/public ./public
COPY frontend/myfrontend/src ./src
RUN npm install .
RUN npm run build
FROM gradle:6.8.2-jre11 AS build-env
# Set the working directory to /home
WORKDIR /home
COPY --chown=gradle:gradle backend ./
COPY --from=build-frontend /app/build /home/src/main/resources/public
# Compile the application.
RUN ./gradlew assemble
FROM openjdk:11.0.10-jre-slim-buster
# Set the working directory to /home
WORKDIR /home
# Copy the compiled files over.
COPY --from=build-env /home/build/libs/myjar-0.1-all.jar /home/myjar.jar
# Starts the java app
# Using EntryPoing to pass env. variables as describe in this article
ENTRYPOINT exec java -XX:+UseContainerSupport -XX:MaxRAMPercentage=80.0 -noverify -XX:+AlwaysPreTouch -jar myjar.jar
Here is my heroku.yml
setup:
addons:
- plan: heroku-postgresql
as: DATABASE
build:
docker:
web: Dockerfile
run:
web: "exec java -XX:+UseContainerSupport -XX:MaxRAMPercentage=80.0 -noverify -XX:+AlwaysPreTouch -jar myjar.jar"
and finally my Micronaut application.yml which just sets some configs
micronaut:
application:
name: mypackage
router:
static-resources:
default:
enabled: true
paths:
- classpath:public
mapping: /**
server:
port: ${PORT:8080}
cors:
enabled: true
datasources:
default:
driverClassName: org.postgresql.Driver
dbUrl: jdbc:postgresql://mydbhost.com:port/dbname?sslmode=require
dbUsername: dbuser
dbPassword: dbpasswd
scan:
packages: mypackage
netty:
default:
allocator:
max-order: 3
When I just do docker build -t test-image:latest . and docker run -p 80:8080 test-image:latest I can connect just fine on localhost and the docker container runs the micronaut server. If it fails for some reason I see an output in the container logs detailing why. When I upload this to heroku (through a github deployment) All i see in the logs are
2023-01-09T22:25:50.145942+00:00 heroku[web.1]: Starting process with command `/bin/sh -c exec\ java\ -XX:\+UseContainerSupport\ -XX:MaxRAMPercentage\=80.0\ -noverify\ -XX:\+AlwaysPreTouch\ -jar\ myjar.jar`
2023-01-09T22:25:51.381760+00:00 heroku[web.1]: Process exited with status 0
2023-01-09T22:25:51.439962+00:00 heroku[web.1]: State changed from starting to crashed
I have tried:
To run it locally connected to the heroku addon postgres database, works just fine
Simplifying the build as much as possible
Removing the default on the port (to ensure it picks up $PORT), and running it locally with export PORT=8080 set (works just fine, docker container picks up the env port like we expect in heroku)
And I cannot figure out why it just quits immediately on Heroku. editted: originally thought it had to do with the port value but but I figured out how to give micronaut a port through the command line and it still doesn't work on Heroku (works locally)
edit:
I tried changing my application.yml to this with the DB hardcoded and still nothing. Just does not seem to work. App still crashes and there is nothing to indicate why in the logs
setup:
config:
PORT: $PORT
MICRONAUT_SERVER_PORT: $PORT
build:
docker:
web: Dockerfile
run:
web: "exec java -Dmicronaut.server.port=$PORT -XX:+UseContainerSupport -XX:MaxRAMPercentage=80.0 -noverify -XX:+AlwaysPreTouch -jar myjar.jar"
I still have no extra output from Heroku. No stacktrace or stderr or stdout at all.
Well, it isn't much of an answer. And nothing in the Heroku docs points me to why this works but removing ENTRYPOINT exec java -XX:+UseContainerSupport -XX:MaxRAMPercentage=80.0 -noverify -XX:+AlwaysPreTouch -jar myjar.jar from my Dockerfile works. With entrypoint removed I see logs again and can see my micronaut server starting. With ENTRYPOINT defined in my Dockerfile I just get what I posted about above "Process starting" followed immediately by process crashed

Deploying Gradle project on Heroku

The problem is when I have the project deployed on Heroku after running
heroku local web
it would show the following
C:\Users\Richer\OneDrive\Project>heroku local web
5:22:24 PM web.1 | Error: Could not find or load main class $JAVA_OPTS
[DONE] Killing all processes with signal SIGINT
5:22:25 PM web.1 Exited with exit code null
and if I run
heroku ps
the shell will show
C:\Users\Richer\OneDrive\Project>heroku ps
Free dyno hours quota remaining this month: 549h 21m (99%)
Free dyno usage for this app: 0h 0m (0%)
For more information on dyno sleeping and how to upgrade, see:https://devcenter.heroku.com/articles/dyno-sleeping
=== web (Free): java -Dserver.port=$PORT $JAVA_OPTS -jar build/libs/*.jar (1)
web.1: crashed 2018/10/12 17:22:22 +0300 (~ 14m ago)
my Procfile looks like this
web: java -Dserver.port=$PORT $JAVA_OPTS -jar build/libs/*.jar
If it helps I have two java classes at src/main/java folder as it should be and after many attempts to upload and tun the project I've also built a jar file and its location is at out/artifacts/1_jar/1.jar though this didn't help.
So what do I do?
In addition, to successfully build a project I had to put this 3 strings in the build.gradle as it was described here
ask stage(dependsOn: ['build', 'clean'])
build.mustRunAfter clean
heroku config:set GRADLE_TASK="build"
On Windows, environment variables are used with the $ notation. You'll need to create a second file called Procfile.windows with the contents:
web: java -Dserver.port=%PORT% %JAVA_OPTS% -jar build\libs\*.jar
Then run heroku local web -f Procfile.windows
But leave the $ for Heroku, which uses Linux.

Running Executable jar file keep hanging on Jenkins

I am very newbie in Jenkins, I've created Jenkins job where it will execute somekind like this jar command in Jenkins job:
ECHO **********************************
ECHO Upgrade Devices
ECHO **********************************
cd c:\JenkinsPull
java -jar DevicesUpgrade.jar PC1 %ProjectName%
When I start to build the Jenkins job it able to run the DevicesUpgrade.jar file until last part of jar process before it finish, sudddenly it just stuck there till I abort the job.
So I think there must be a bug inside the jar file, but it is weird because after that, I tried to run java -jar DevicesUpgrade.jar PC1 %ProjectName% on command prompt, it didn't stuck at all and it able to finish up the jar.
Is there anything that I need to do on Jenkins to fix this hang problem?
Here is the output I got from Jenkins:
c:\JenkinsPull>java -jar DevicesUpgrade.jar PC1 lex_l11_gms
%%%%f95eac91%%%%%
lexl11g_64-ota-L11_D01.00.48_userdebug.zip
1517844524458
%%%%%%%%%%%%%%%%%%%%%%%%
adb -s shell f95eac91 "getprop | grep ro.build.version.incremental"
\\ANDROIDTEST-05\ARM_png\JenkinsPull\BSP\lex_l11_gms\lexl11g_64-ota-
L11_D01.00.48_userdebug.zip
1.143848721E9
[*--------------------------------------------------------------------------
--------------------------]
Here it keep loading the jenkins job till I need to abort the Jenkins job.
Here is the output I got when I am running the jar via Command Prompt:
c:\JenkinsPull>java -jar DevicesUpgrade.jar PC1 lex_l11_gms
%%%%f95eac91%%%%%
lexl11g_64-ota-L11_D01.00.48_userdebug.zip
1517844524458
%%%%%%%%%%%%%%%%%%%%%%%%
adb -s shell f95eac91 "getprop | grep ro.build.version.incremental"
\\ANDROIDTEST-05\ARM_png\JenkinsPull\BSP\lex_l11_gms\lexl11g_64-ota-
L11_D01.00.48_userdebug.zip
1.143848721E9
[*--------------------------------------------------------------------------
--------------------------]
Upgrade Device Completed..!!
c:\JenkinsPull>

Docker build hangs during downloads

Mac 10.10.5 here, using docker-machine to create a VirtualBox host VM for my local Docker. I have a project that builds an executable JVM located at build/libs/myapp-SNAPSHOT.jar. My Dockerfile, which is located in the root of the project, looks like:
FROM frolvlad/alpine-oraclejdk8:slim
VOLUME /tmp
ADD build/libs/myapp-SNAPSHOT.jar myapp.jar
RUN sh -c 'touch /myapp.jar'
ENTRYPOINT ["java","-jar","/myapp.jar"]
Please note, I don't wish to push my images to any registry, just keep/run them locally (for now). When I run:
docker build -t myorg/myapp .
I get the following console output:
myuser#mymachine:~/sandbox/myapp$docker build -t myorg/myapp .
Sending build context to Docker daemon 42.69 MB
Step 1 : FROM frolvlad/alpine-oraclejdk8:slim
slim: Pulling from frolvlad/alpine-oraclejdk8
d0ca440e8637: Downloading [=================================================> ] 2.295 MB/2.32 MB
0f86278f6be1: Downloading [=================================================> ] 3.149 MB/3.172 MB
c704a6161dca: Download complete
And then the command-line just hangs after printing that "Download complete" message. I've waited for as long as 30 minutes (!!!) and nothing happens.
Any ideas where I'm going awry?
The VM is probably hanging. Try the following: https://github.com/docker/machine/issues/1819#issuecomment-138981139
docker-machine rm -f default
rm -fv ~/.docker/machine
docker-machine -D create -d virtualbox default
There are more issues about this on OSX.
I think the best practice is to setup a Linux native build box if you are doing any serious development. That way you can run docker without any VM overhead(which is ironically one of the major pain points docker is trying to solve)
There's also a Docker Beta program which runs on libcontainer natively on OSX and Windows.

INFO - Started Jetty Server, but does not finish

I am trying to setup Dashbuilder. I have worked through a couple issues already (one with the help of others here, thank you). I am at the point where the program must be compiled, built, and run using command
./buildandrun.sh h2
things start off as expected, but then just stop at "[INFO] Started Jetty Server" in terminal.
I've let it sit for hours, no progress. I tried running with the -X flag, but no extra info for that step appeared. When I try to visit http://localhost:8080/dashbuilder to see if the program started I get a 503 error and see
HTTP ERROR: 503
Problem accessing /dashbuilder. Reason:
Service Unavailable
Powered by Jetty:// 9.3.9.v20160517
How can I see in better detail what and why something like this is happening?
Contents of the SH file are:
#!/bin/bash
if [ "$1" = "" ] ; then
echo "Build & Run the application for a given database."
echo ""
echo "USAGE: buildandrun.sh [h2|postgres]"
else
echo "-----------------------------------------------------------------"
echo "Building & Running the application for the '$1' database..."
echo "------------------------------------------------------------------"
cd ..
mvn clean install -P $1,jetty $2 $3 $4
export MAVEN_OPTS="-Xms1024M -Xmx2048M -XX:MaxPermSize=512m -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"
cd modules/dashboard-showcase/
mvn jetty:run -P $1,jetty
fi
The jetty:run goal of the jetty-maven-plugin does exactly that.
It runs Jetty, normally, and waits for the user to terminate it (either with TERM, KILL, Ctrl+C, use of the Shutdown facilities)
That mvn jetty:run command never returns.
Perhaps you wanted to use mvn jetty:start and mvn jetty:stop
See: https://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html#jetty-start-goal

Categories