Heroku,Java,Procfile,无法找到或加载主类 [英] Heroku, Java, Procfile, Could not find or load main class
问题描述
我用Maven使用heroku来运行服务器。我的目标是让heroku运行java类server.class作为Web dyno。
如何编写一个procfile来执行java程序server.class作为web?
我的当前Procfile
web:java -cp $ JAVA_OPTS target / classes / v1 / a1 / server
我的错误(来自heroku日志)
拾取JAVA_TOOL_OPTIONS:-Xmx350m -Xss512k -Dfile.encoding = UTF-8
错误:无法找到或加载主类target.classes.v1 .a1.server
状态从开始变为崩溃
可能有用的信息
procfile
web:java -cp $ JAVA_OPTS target / classes / v1 / a1 / *
返回
错误:无法找到或加载主类target.classes.v1.a1。 myOtherClass
我的原始Procfile(也没有用)
web:java -cp target / classes /:target / dependenc y / *服务器
- 我的文件结构与示例有点不同在heroku文档中给出,所以我修改了一下proc文件。
- 我的依赖关系不在/ target / dependencies中。
- 我的类位于target / classes / v1 / a1 /中。
- server.java有一个主要方法和有效的构造方法。
- 我的所有依赖关系似乎都是按顺序排列的。
- Maven会将我的.java文件构建到目标目录中的.class文件中。
- 我在unix上,所以引号和分号可能不起作用。
我认为你的 Procfile
应该包含:
web:java -cp target / classes /:target / dependency / * v1.a1.server
假设如下:
server
class在文件 target / v1 / a1 / server.class中
server
类的Java代码包含 package v1.a1;
在您之前的尝试中,我发现了一些问题:
- 您将
$ JAVA_OPTS
传递给-cp $ c $您正在使用
/
而不是。
在完全限定类名中(不正确) - 您在完全限定类名中包含
目标
dir li>
文件i n target / classes /
和 target / dependency /
目录属于类路径。传递给 -cp
),而 java
命令的最后一个参数应该是完全限定的类名(在表单中 package.Class
)。
I'm using heroku with maven to run a server. My goal is to have heroku run the java class server.class as a web dyno.
How would I write a procfile to execute the java program server.class as web?
My current Procfile
web: java -cp $JAVA_OPTS target/classes/v1/a1/server
My error.(From heroku logs)
Picked up JAVA_TOOL_OPTIONS: -Xmx350m -Xss512k -Dfile.encoding=UTF-8
Error: Could not find or load main class target.classes.v1.a1.server
State changed from starting to crashed
Possibly useful information
The procfile
web: java -cp $JAVA_OPTS target/classes/v1/a1/*
Returns
Error: Could not find or load main class target.classes.v1.a1.myOtherClass
My original Procfile(Also didn't work)
web: java -cp target/classes/:target/dependency/* server
- My file structure is a bit different than the example given in the heroku docs so I modified the procfile a bit.
- My dependencies are not inside /target/dependencies.
- My classes are inside target/classes/v1/a1/.
- server.java has a main method and valid constructor method.
- All my dependencies seem to be in order.
- Maven does builds my .java files into .class files in the target directory.
- I'm on unix so quotes and semicolons probably won't work.
I think your Procfile
should contain:
web: java -cp target/classes/:target/dependency/* v1.a1.server
This assumes the following:
- Your
server
class is in the filetarget/v1/a1/server.class
- The Java code for your
server
class includespackage v1.a1;
- Your class name and file name are lowercase.
A few problems I noticed in your earlier attempts included:
- You are passing
$JAVA_OPTS
to the-cp
options (incorrect) - You are using
/
instead of.
in the fully qualified class name (incorrect) - You are including the
target
dir in the fully qualified class name (incorrect)
The files in the target/classes/
and target/dependency/
directory belong on the classpath (i.e. passed to -cp
) while the last argument to the java
command should be the fully qualified class name (in the form package.Class
).
这篇关于Heroku,Java,Procfile,无法找到或加载主类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!