简体   繁体   English

在Heroku上部署Java,无法在target \\ dependency中找到主类

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

I try to deploy java on Heroku. 我尝试在Heroku上部署java。 I follow the steps on Heroku ,But I get error on 我按照Heroku的步骤,但我得到错误

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

the error is : Error: Could not find or load main class HelloWorld 错误是: 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. 我在pom.xml中找到了helloworld关键字,所以我尝试将其更改为HelloWorld。 It still does not work. 它仍然无法正常工作。 btw, I am running windows 7(64 bit) with jdk1.7.0_05. 顺便说一句,我用jdk1.7.0_05运行Windows 7(64位)。

Looks like you are using Windows-style path for the -cp flag. 看起来您正在使用Windows样式的路径作为-cp标志。 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. Heroku在Linux上运行,因此您可能需要将其更改为java -cp target/classes:"target/dependency/*" HelloWorld您正在部署到Heroku的Procfile java -cp target/classes:"target/dependency/*" HelloWorld

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... 对于任何试图关注Heroku入门教程并试图在本地部署并且收到此错误的狂热读者...

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: 如果您正在使用Maven的入门指南,请在项目根文件夹中执行以下maven命令以在本地构建目标:

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) (显然,替代Procfile.windowsProcfile如果你没有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来本地访问您的应用程序:

localhost:5000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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