Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App not runnning once deployed to Heroku #36

Closed
Stuartkenworthy opened this issue Mar 8, 2017 · 14 comments
Closed

App not runnning once deployed to Heroku #36

Stuartkenworthy opened this issue Mar 8, 2017 · 14 comments

Comments

@Stuartkenworthy
Copy link

Stuartkenworthy commented Mar 8, 2017

After deploying to Heroku and attempting to run the app I am seeing this error message in the logs:
Error: Unable to access jarfile jbot-example/target/jbot-example-1.0.0-SNAPSHOT.jar

I have checked this is the correct name for the jar file and this is the jar file that is auto-created when running mvn spring-boot:run.

My procfile looks like this: web: java -Dserver.port=8080 -jar jbot-example/target/jbot-example-1.0.0-SNAPSHOT.jar

And the path from the jbot directory to the jar file is jbot-example\target\jbot-example-1.0.0-SNAPSHOT.jar

Any help with this would be greatly appreciated

This is the first time I've used Heroku so not sure if I am missing anything.

@rampatra
Copy link
Owner

rampatra commented Mar 8, 2017

Well, from your comments I see that Heroku has forward slash / in the path and the path you specified has backward slash \. Can you please make sure that's not the issue?

@Stuartkenworthy
Copy link
Author

I tried changing the slashes to how it is in jbot-example\target\jbot-example-1.0.0-SNAPSHOT.jar in the procfile and this removed the slashes in heroku altogether and showed up under the resources tab as
jbot-exampletargetjbot-example-1.0.0-SNAPSHOT.jar

@Stuartkenworthy
Copy link
Author

Stuartkenworthy commented Mar 8, 2017

OK I moved the jar file to the root directory and this resolved the issue, now seeing:
no main manifest attribute, in jbot-example-1.0.0-SNAPSHOT.jar instead.

After googling it is saying that there should be a main-Class set in the manifest.mf file inside the jar, this does not exist, should this not have automatically been set when the jar was created?

Have manually added the class package to the manifest.mf file and now seeing a different error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication

2017-03-08T13:16:38.631889+00:00 app[web.1]: at example.jbot.JBotApplication.main(JBotApplication.java:16)

2017-03-08T13:16:38.632768+00:00 app[web.1]: Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication

@rampatra
Copy link
Owner

rampatra commented Mar 8, 2017

You need not move any jar files, it would mess things up. Have you followed the steps mentioned in the deploy to cloud section in the docs?

@Stuartkenworthy
Copy link
Author

Stuartkenworthy commented Mar 8, 2017

Have resolved the issue, problem was that the jar did not contain org.springframework.boot dependencies
added -
build
plugins
plugin
groupId org.springframework.boot groupId
artifactIdspring-boot-maven-plugin artifactId
plugin
plugins
build
to the pom.xml in jbot-example, repackaged and this worked properly.

@rampatra
Copy link
Owner

rampatra commented Mar 8, 2017

So you mean there are dependencies missing from jbot-example? I will take a look at it this weekend and come back to you. Thanks for the issue.

@Stuartkenworthy
Copy link
Author

Yes thats correct, I have attached the link to the article I found that showed me how to solve this issue:
http://docs.spring.io/spring-boot/docs/current/reference/html/getting-started-first-application.html
Point 11.5 shows the change I made.

@rampatra
Copy link
Owner

rampatra commented Mar 9, 2017

Okay, if it's really an issue then I think it wouldn't even build locally but it is. I will give it a look and come back to you.

@talbright
Copy link
Contributor

talbright commented Jul 13, 2017

The directions on the README for heroku do not work correctly. While @Stuartkenworthy is right that the fix for no main manifest attribute, in jbot-example-1.0.0-SNAPSHOT.jar is adding the spring-boot-maven-plugin to the pom.xml, my solution for the other issue was to modify the Procfile:

web: java -Dserver.port=$PORT -jar  jbot-example/target/jbot-example-1.0.0-SNAPSHOT.jar

There's also an issue with forcing the app to bind to port 8080. There are times when deploying to heroku where this will fail. Instead we should bind to port $PORT and let heroku pick the port for us to bind to. See https://devcenter.heroku.com/articles/java-webapp-runner.

@ramswaroop the reason the build works fine locally is because this issue isn't about compiling, but rather about packaging. The jar needs to be executable to run in heroku correctly as paired with the given Procfile.

talbright added a commit to talbright/jbot that referenced this issue Jul 13, 2017
talbright added a commit to talbright/jbot that referenced this issue Jul 13, 2017
talbright added a commit to talbright/jbot that referenced this issue Jul 13, 2017
talbright added a commit to talbright/jbot that referenced this issue Jul 13, 2017
@rampatra
Copy link
Owner

Thanks @talbright , it makes sense. Can we also do something around the jar file name in the Procfile such that everytime I update the jbot-example jar I don't have to edit the Procfile.

@talbright
Copy link
Contributor

talbright commented Jul 13, 2017

You bet 🎉

That seems to be the next logical step, to do something around automating version changes. Alternatively, it might just be better to go with deploying directly to heroku: https://devcenter.heroku.com/articles/deploying-java-applications-with-the-heroku-maven-plugin

But I haven't had time to work through that approach yet but will in the next couple of weeks and can push a fix when I figure out the best way to do it.

For now you shouldn't have to update Procfile that often -- only when you change the version of jbot-example/pom.xml. So far from git log it doesn't look like you have changed it yet, so it should be stable for the meantime.

I would suggest merging this in now since it fixes an immediate issue, and we can work on a better long term solution in another PR.

@rampatra
Copy link
Owner

Yes @talbright, I am reviewing the PR now.

rampatra pushed a commit that referenced this issue Jul 13, 2017
* Fixes jbot-example broken heroku deploy. See #36 for more details
@ShinkarevPavel
Copy link

web: java -Dserver.port=$PORT -jar jbot-example/target/jbot-example-1.0.0-SNAPSHOT.jar
@talbright , thank you so much for this tip. I spent a lot of time looking for a solution error of jarfile access. You are my savior.

@KostaPo
Copy link

KostaPo commented May 5, 2022

web: java -Dserver.port=$PORT -jar jbot-example/target/jbot-example-1.0.0-SNAPSHOT.jar @talbright , thank you so much for this tip. I spent a lot of time looking for a solution error of jarfile access. You are my savior.

в двух словах обьясни в чем ошибка и что нужно предпринять?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants