Error deploying spring app on heroku - java

Error on running heroku open after deploying
Error: Error: Unable to access jarfile target/*.jar
I am not sure how to fix this. I added something like this in procfile looking at other SO questions.
web: java -Dserver.port=$PORT -jar target/RootScopeIT_Riot-1.0-SNAPSHOT.war
web: java -jar target/dependency/webapp-runner.jar target/*.war
On running heroku open gives this error.
Please help me to fix this. I have been struggling for days. Thank you

Related

How to add new relic java agent to a heroku war

I am facing issue to add java agent to heroku WAR.
Our procfile looks as below,
web: java $JAVA_OPTS -jar target/dependency/webapp-runner.jar --port $PORT target/*.war
I am following this link to setup newrelic on heroku
https://docs.newrelic.com/docs/agents/java-agent/heroku/java-agent-heroku
but this talks only about jar.

Heroku, Java Web app - free dynos Procfile - How to create proper Procfile

I'm trying to upload my 1st Java Web app to the web but I can't handle the Procfile. After deploy, there is info about successfully deploy but when I try to run the app there are an error and server logs seems to indicate that Procfile is empty / does not exist.
In server resources there is following dyno:
java $JAVA_OPTS -jar target/dependency/webapp-runner.jar --port $PORT target/*.war
and in thetutorial there is
"Your Procfile will look something like this:"
web: java $JAVA_OPTS -cp target/classes:target/dependency/* HelloWorld
but I don't udnerstand what is happening here. I know only that there should be web: at the beggining for web-app I don't understand the rest of it. Can some one help me undrstand it so I could create proper Procfile for my app?
If you have heroku installed and if you have only .jsp and .class you can do as it follows, and you don't need a procfile:
$ heroku create <app_name>
Create a WAR file of your app in Eclipse for example:
Right click on the project > Export > WAR file
then you have to deploy it to heroku:
$ heroku war:deploy <path_to_war_file> --app <app_name>
then you'll see the app going to heroku, some logs and blah blah blah. After that you can open your application:
$ heroku open --app <app_name>
Simple. But if you need some help about procfile, take a look here

Java Web App Crashes on Heroku with webapp-runner

I have an existing Java web app project. It works locally with Tomcat. I converted it into a maven project and deployed it on Heroku using webapp-runner. The application is deployed successfully but it does not run; it crashes. I cannot figure out from the logs what the reason is.
My Procfile looks like this: web: java $JAVA_OPTS -jar target/dependency/webapp-runner.jar --port $PORT target/*.war
App structure
logs
It states clearly in the log: The specified path target/*.war does not exist. Run your build locally using mvn clean package and see if you actually have a war file in the target directory and what it's name is.
Then, open your Procfile and replace target/*.war with target/whateverTheNameIs.war and retry.

Debug embedded tomcat on heroku

I'm working on a Java web application. I already deploy it to heroku. Now I'm trying to remote debug my application using IntelliJ with no results. To deploy it I use git, then heroku starts it reading and executing the Procfile. And here is the problem. Everywhere I see that to debug I must use this line in my Procfile: web: java -agentlib:jdwp=transport=dt_socket,server=y,address=9090,suspend=n -jar target/myapp.jar. But I can't put this line on my Procfile because I execute my app using web: sh target/bin/webapp and not java. There's some workaround to simply debug my application.
You'll need Heroku Exec and the Heroku Java CLI.
First, put your agentlib args into the JAVA_TOOL_OPTIONS env var:
$ heroku config:set JAVA_TOOL_OPTIONS="-agentlib:jdwp=transport=dt_socket,server=y,address=9090,suspend=n"
This way, the java process in your target/bin/webapp script will pick it up automatically.
Then run:
$ heroku ps:forward 9090
And you can connect to localhost:9090 from your IDE.

Foreman cannot find $JAVA_OPTS

I have an error following the next tutorial from Heroku specifically on this part
[https://devcenter.heroku.com/articles/getting-started-with-java#run-the-app-locally][1]
If I execute that instruction foreman throws the following error:
Error: cannot find java class $JAVA_OPTS
I have already declared a env variable like this:
Name variable : JAVA_OPTS
Variable value: -Xms256m -Xmx512m
The Proc file that foreman is trying to execute has the following:
web: java $JAVA_OPTS -cp target/classes:target/dependency/* Main
Im clueless about what is happening.
Note: I already checked some other questions
Running java with JAVA_OPTS env variable
Foreman terminates immediately
foreman can't find java
Hope someone knwos what is happening.
EDIT : I answered my own question below
I suspect you are running on Windows. If so, then you'll have to reference the JAVA_OPTS var like %JAVA_OPTS%. But Heroku will still need the *nix style ($JAVA_OPTS), so I recommend creating a Procfile.win next to your Procfile with the following contents:
web: java %JAVA_OPTS% -cp target/classes:target/dependency/* Main
Then run this to start your app locally:
$ foreman start --procfile=Procfile.win
This is what I did in order to solve the issue:
Seems that the documentation at heroku site is not clear about what operating system are you using. But then I found the answer in the link below:
Heroku Deploy your Java app locally
The original Proc file script whas like this:
web: java $JAVA_OPTS -cp target/classes:target/dependency/* Main
and I modified it as you can see below:
web: java %JAVA_OPTS% -cp target\classes;"target\dependency\*" Main
Just as Heroku documentation states.
This solved the problem and I was able to run my app locally
If you're using 'nix,
export JAVA_OPTS
before running the script that expects it.

Categories

Resources