简体   繁体   中英

Deploy Java on Heroku, Cannot find main class in target\dependency

I try to deploy java on Heroku. I follow the steps on Heroku ,But I get error on

java -cp target\\classes;"target\\dependency\\*" HelloWorld

the error is : Error: Could not find or load main class HelloWorld

How can I solve it? Is it case sensitive?

I found helloworld key word in pom.xml, so I try to change it to HelloWorld. It still does not work. btw, I am running windows 7(64 bit) with jdk1.7.0_05.

Looks like you are using Windows-style path for the -cp flag. Heroku runs on Linux, so you probably need to change that to java -cp target/classes:"target/dependency/*" HelloWorld in the Procfile you are deploying to Heroku.

For any avid readers who are trying to follow Heroku's getting started tutorial and are attempting to deploy locally and are receiving this error...

It is likely that you haven't built the target classes locally (they don't explain it very well in the tutorial).

If you are following the getting started guide with Maven then execute the following maven command in your project root folder to build your target locally:

mvn clean install

After that the local deployment commands like:

heroku local web -f Procfile.windows

should work as expected. (Obviously substitute Procfile.windows with just Procfile if you are not deploying under Windows)

You should then see something like:

Started ServerConnector@4d29c891{HTTP/1.1}{0.0.0.0:5000}

and can access your application locally by navigating to localhost on the port that was displayed:

localhost:5000

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM