Java Heroku-应用程序中发生错误

Java Heroku-应用程序中发生错误,java,rest,heroku,jax-rs,Java,Rest,Heroku,Jax Rs,我对java和heroku都是新手,只是学习heroku实际上如何帮助部署应用程序。我已经成功地将java jax rs应用程序部署到heroku,它已经成功部署。但是当我尝试访问应用程序时,我得到了一个错误提示 Application Error An error occurred in the application and your page could not be served. Please try again in a few moments. If you are the ap

我对java和heroku都是新手,只是学习heroku实际上如何帮助部署应用程序。我已经成功地将java jax rs应用程序部署到heroku,它已经成功部署。但是当我尝试访问应用程序时,我得到了一个错误提示

Application Error
An error occurred in the application and your page could not be served. Please try again in a few moments.

If you are the application owner, check your logs for details.
日志指出:

2016-02-16T14:05:00.130504+00:00 app[web.1]:    at org.eclipse.jetty.util.compon
ent.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
2016-02-16T14:05:00.130571+00:00 app[web.1]:    at org.eclipse.jetty.server.Serv
er.start(Server.java:342)
2016-02-16T14:05:00.130606+00:00 app[web.1]:    at org.eclipse.jetty.util.compon
ent.ContainerLifeCycle.doStart(ContainerLifeCycle.java:100)
2016-02-16T14:05:00.130543+00:00 app[web.1]:    at org.eclipse.jetty.util.compon
ent.ContainerLifeCycle.start(ContainerLifeCycle.java:118)
2016-02-16T14:05:00.130672+00:00 app[web.1]:    at org.eclipse.jetty.server.hand
ler.AbstractHandler.doStart(AbstractHandler.java:60)
2016-02-16T14:05:00.130773+00:00 app[web.1]:    at org.eclipse.jetty.util.compon
ent.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
2016-02-16T14:05:00.130711+00:00 app[web.1]:    at org.eclipse.jetty.server.Serv
er.doStart(Server.java:290)
2016-02-16T14:05:00.130829+00:00 app[web.1]:    at com.example.heroku.Main.main(
Main.java:37)
2016-02-16T14:05:01.248629+00:00 heroku[web.1]: Process exited with status 143
2016-02-16T14:06:27.270942+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web
process failed to bind to $PORT within 90 seconds of launch
2016-02-16T14:06:27.270942+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-02-16T14:06:28.235216+00:00 heroku[web.1]: Process exited with status 137
2016-02-16T14:06:31.888204+00:00 heroku[web.1]: Starting process with command `j
ava -cp target/classes:target/dependency/* com.example.heroku.Main`
2016-02-16T14:06:33.412568+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults
based on dyno size. Custom settings will override them.
2016-02-16T14:06:33.417995+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx35
0m -Xss512k -Dfile.encoding=UTF-8
2016-02-16T14:06:33.807850+00:00 app[web.1]: 2016-02-16 14:06:33.807:INFO:oejs.S
erver:main: jetty-9.0.6.v20130930
2016-02-16T14:06:34.000888+00:00 app[web.1]: 2016-02-16 14:06:33.000:INFO:oejw.S
tandardDescriptorProcessor:main: NO JSP Support for /, did not find org.apache.j
asper.servlet.JspServlet
2016-02-16T14:06:34.379571+00:00 app[web.1]: 2016-02-16 14:06:34.377:WARN:oejuc.
AbstractLifeCycle:main: FAILED o.e.j.w.WebAppContext@a382ca7{/,file:/app/src/mai
n/webapp/,STARTING}: java.lang.NoSuchMethodError: javax.ws.rs.core.Application.g
etProperties()Ljava/util/Map;
2016-02-16T14:06:34.379577+00:00 app[web.1]:    at org.glassfish.jersey.server.A
pplicationHandler.<init>(ApplicationHandler.java:287)
2016-02-16T14:06:34.379576+00:00 app[web.1]: java.lang.NoSuchMethodError: javax.
ws.rs.core.Application.getProperties()Ljava/util/Map;
2016-02-16T14:06:34.379578+00:00 app[web.1]:    at org.glassfish.jersey.servlet.
WebComponent.<init>(WebComponent.java:311)
2016-02-16T14:06:34.379579+00:00 app[web.1]:    at org.glassfish.jersey.servlet.
ServletContainer.init(ServletContainer.java:169)
2016-02-16T14:06:34.379579+00:00 app[web.1]:    at org.glassfish.jersey.servlet.
ServletContainer.init(ServletContainer.java:359)
2016-02-16T14:06:34.379580+00:00 app[web.1]:    at javax.servlet.GenericServlet.
init(GenericServlet.java:244)
2016-02-16T14:06:34.379582+00:00 app[web.1]:    at org.eclipse.jetty.servlet.Ser
vletHolder.initialize(ServletHolder.java:351)
2016-02-16T14:06:34.379581+00:00 app[web.1]:    at org.eclipse.jetty.servlet.Ser
vletHolder.initServlet(ServletHolder.java:542)
2016-02-16T14:06:34.379582+00:00 app[web.1]:    at org.eclipse.jetty.servlet.Ser
vletHandler.initialize(ServletHandler.java:803)
2016-02-16T14:06:34.379583+00:00 app[web.1]:    at org.eclipse.jetty.servlet.Ser
vletContextHandler.startContext(ServletContextHandler.java:288)
2016-02-16T14:06:34.379584+00:00 app[web.1]:    at org.eclipse.jetty.webapp.WebA
ppContext.startContext(WebAppContext.java:1322)
2016-02-16T14:06:34.379585+00:00 app[web.1]:    at org.eclipse.jetty.server.hand
ler.ContextHandler.doStart(ContextHandler.java:732)
2016-02-16T14:06:34.379589+00:00 app[web.1]:    at org.eclipse.jetty.util.compon
ent.ContainerLifeCycle.start(ContainerLifeCycle.java:118)
2016-02-16T14:06:34.379587+00:00 app[web.1]:    at org.eclipse.jetty.webapp.WebA
ppContext.doStart(WebAppContext.java:490)
2016-02-16T14:06:34.379588+00:00 app[web.1]:    at org.eclipse.jetty.util.compon
ent.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
2016-02-16T14:06:34.379589+00:00 app[web.1]:    at org.eclipse.jetty.server.Serv
er.start(Server.java:342)
2016-02-16T14:06:34.379591+00:00 app[web.1]:    at org.eclipse.jetty.server.Serv
er.doStart(Server.java:290)
2016-02-16T14:06:34.379590+00:00 app[web.1]:    at org.eclipse.jetty.util.compon
ent.ContainerLifeCycle.doStart(ContainerLifeCycle.java:100)
2016-02-16T14:06:34.379591+00:00 app[web.1]:    at org.eclipse.jetty.server.hand
ler.AbstractHandler.doStart(AbstractHandler.java:60)
2016-02-16T14:06:34.379597+00:00 app[web.1]:    at com.example.heroku.Main.main(
Main.java:37)
2016-02-16T14:06:34.379592+00:00 app[web.1]:    at org.eclipse.jetty.util.compon
ent.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
2016-02-16T14:06:34.381381+00:00 app[web.1]: 2016-02-16 14:06:34.380:WARN:oejuc.
AbstractLifeCycle:main: FAILED org.eclipse.jetty.server.Server@6dfb8d2e: java.la
ng.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map
;
2016-02-16T14:06:34.381384+00:00 app[web.1]: java.lang.NoSuchMethodError: javax.
ws.rs.core.Application.getProperties()Ljava/util/Map;
2016-02-16T14:06:34.381385+00:00 app[web.1]:    at org.glassfish.jersey.server.A
pplicationHandler.<init>(ApplicationHandler.java:287)
2016-02-16T14:06:34.381386+00:00 app[web.1]:    at org.glassfish.jersey.servlet.
WebComponent.<init>(WebComponent.java:311)
2016-02-16T14:06:34.381387+00:00 app[web.1]:    at org.glassfish.jersey.servlet.
ServletContainer.init(ServletContainer.java:169)
2016-02-16T14:06:34.381388+00:00 app[web.1]:    at org.glassfish.jersey.servlet.
ServletContainer.init(ServletContainer.java:359)
2016-02-16T14:06:34.381388+00:00 app[web.1]:    at javax.servlet.GenericServlet.
init(GenericServlet.java:244)
2016-02-16T14:06:34.381389+00:00 app[web.1]:    at org.eclipse.jetty.servlet.Ser
vletHolder.initServlet(ServletHolder.java:542)
2016-02-16T14:06:34.381390+00:00 app[web.1]:    at org.eclipse.jetty.servlet.Ser
vletHolder.initialize(ServletHolder.java:351)
2016-02-16T14:06:34.381391+00:00 app[web.1]:    at org.eclipse.jetty.servlet.Ser
vletHandler.initialize(ServletHandler.java:803)
2016-02-16T14:06:34.381391+00:00 app[web.1]:    at org.eclipse.jetty.servlet.Ser
vletContextHandler.startContext(ServletContextHandler.java:288)
2016-02-16T14:06:34.381392+00:00 app[web.1]:    at org.eclipse.jetty.webapp.WebA
ppContext.startContext(WebAppContext.java:1322)
2016-02-16T14:06:34.381393+00:00 app[web.1]:    at org.eclipse.jetty.server.hand
ler.ContextHandler.doStart(ContextHandler.java:732)
2016-02-16T14:06:34.381394+00:00 app[web.1]:    at org.eclipse.jetty.webapp.WebA
ppContext.doStart(WebAppContext.java:490)
2016-02-16T14:06:34.381395+00:00 app[web.1]:    at org.eclipse.jetty.util.compon
ent.ContainerLifeCycle.start(ContainerLifeCycle.java:118)
2016-02-16T14:06:34.381394+00:00 app[web.1]:    at org.eclipse.jetty.util.compon
ent.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
2016-02-16T14:06:34.381396+00:00 app[web.1]:    at org.eclipse.jetty.server.Serv
er.start(Server.java:342)
2016-02-16T14:06:34.381396+00:00 app[web.1]:    at org.eclipse.jetty.util.compon
ent.ContainerLifeCycle.doStart(ContainerLifeCycle.java:100)
2016-02-16T14:06:34.381397+00:00 app[web.1]:    at org.eclipse.jetty.server.hand
ler.AbstractHandler.doStart(AbstractHandler.java:60)
2016-02-16T14:06:34.381398+00:00 app[web.1]:    at org.eclipse.jetty.server.Serv
er.doStart(Server.java:290)
2016-02-16T14:06:34.381398+00:00 app[web.1]:    at org.eclipse.jetty.util.compon
ent.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
2016-02-16T14:06:34.381402+00:00 app[web.1]:    at com.example.heroku.Main.main(
Main.java:37)
2016-02-16T14:06:34.381922+00:00 app[web.1]: Exception in thread "main" java.lan
g.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;

2016-02-16T14:06:34.382058+00:00 app[web.1]:    at org.glassfish.jersey.servlet.
WebComponent.<init>(WebComponent.java:311)
2016-02-16T14:06:34.381988+00:00 app[web.1]:    at org.glassfish.jersey.server.A
pplicationHandler.<init>(ApplicationHandler.java:287)
2016-02-16T14:06:34.382316+00:00 app[web.1]:    at org.eclipse.jetty.servlet.Ser
vletHolder.initServlet(ServletHolder.java:542)
2016-02-16T14:06:34.382117+00:00 app[web.1]:    at org.glassfish.jersey.servlet.
ServletContainer.init(ServletContainer.java:169)
2016-02-16T14:06:34.382183+00:00 app[web.1]:    at org.glassfish.jersey.servlet.
ServletContainer.init(ServletContainer.java:359)
2016-02-16T14:06:34.382256+00:00 app[web.1]:    at javax.servlet.GenericServlet.
init(GenericServlet.java:244)
2016-02-16T14:06:34.382511+00:00 app[web.1]:    at org.eclipse.jetty.servlet.Ser
vletContextHandler.startContext(ServletContextHandler.java:288)
2016-02-16T14:06:34.382382+00:00 app[web.1]:    at org.eclipse.jetty.servlet.Ser
vletHolder.initialize(ServletHolder.java:351)
2016-02-16T14:06:34.382572+00:00 app[web.1]:    at org.eclipse.jetty.webapp.WebA
ppContext.startContext(WebAppContext.java:1322)
2016-02-16T14:06:34.382448+00:00 app[web.1]:    at org.eclipse.jetty.servlet.Ser
vletHandler.initialize(ServletHandler.java:803)
2016-02-16T14:06:34.382663+00:00 app[web.1]:    at org.eclipse.jetty.server.hand
ler.ContextHandler.doStart(ContextHandler.java:732)
2016-02-16T14:06:34.382728+00:00 app[web.1]:    at org.eclipse.jetty.webapp.WebA
ppContext.doStart(WebAppContext.java:490)
2016-02-16T14:06:34.382797+00:00 app[web.1]:    at org.eclipse.jetty.util.compon
ent.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
2016-02-16T14:06:34.382861+00:00 app[web.1]:    at org.eclipse.jetty.util.compon
ent.ContainerLifeCycle.start(ContainerLifeCycle.java:118)
2016-02-16T14:06:34.382986+00:00 app[web.1]:    at org.eclipse.jetty.util.compon
ent.ContainerLifeCycle.doStart(ContainerLifeCycle.java:100)
2016-02-16T14:06:34.382925+00:00 app[web.1]:    at org.eclipse.jetty.server.Serv
er.start(Server.java:342)
2016-02-16T14:06:34.383127+00:00 app[web.1]:    at org.eclipse.jetty.server.Serv
er.doStart(Server.java:290)
2016-02-16T14:06:34.383063+00:00 app[web.1]:    at org.eclipse.jetty.server.hand
ler.AbstractHandler.doStart(AbstractHandler.java:60)
2016-02-16T14:06:34.383259+00:00 app[web.1]:    at com.example.heroku.Main.main(
Main.java:37)
2016-02-16T14:06:34.383194+00:00 app[web.1]:    at org.eclipse.jetty.util.compon
ent.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
2016-02-16T14:06:28.251181+00:00 heroku[web.1]: State changed from starting to c
rashed
2016-02-16T14:06:28.252206+00:00 heroku[web.1]: State changed from crashed to st
arting
2016-02-16T14:06:42.640134+00:00 heroku[router]: at=error code=H20 desc="App boo
t timeout" method=GET path="/" host=ftptransfer.herokuapp.com request_id=5a0d99c
8-fb68-4571-95e2-08f220449580 fwd="115.114.17.154" dyno= connect= service= statu
s=503 bytes=
2016-02-16T14:06:55.474328+00:00 heroku[router]: at=error code=H20 desc="App boo
t timeout" method=GET path="/myresource" host=ftptransfer.herokuapp.com request_
id=0046bf64-dfe3-4baa-b70b-6135355e0bae fwd="115.114.17.154" dyno= connect= serv
ice= status=503 bytes=
2016-02-16T14:07:23.368287+00:00 heroku[router]: at=error code=H20 desc="App boo
t timeout" method=GET path="/myresource" host=ftptransfer.herokuapp.com request_
id=88a341fd-f5a3-4e11-bce5-734e039dca7c fwd="115.114.17.154" dyno= connect= serv
ice= status=503 bytes=
2016-02-16T14:07:51.237097+00:00 heroku[router]: at=error code=H20 desc="App boo
t timeout" method=GET path="/myresource" host=ftptransfer.herokuapp.com request_
id=b37215de-9ae0-4db0-902b-efb2ce1ce157 fwd="115.114.17.154" dyno= connect= serv
ice= status=503 bytes=
2016-02-16T14:08:02.313979+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-02-16T14:08:02.313979+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web
process failed to bind to $PORT within 90 seconds of launch
2016-02-16T14:08:03.154767+00:00 heroku[web.1]: Process exited with status 137
2016-02-16T14:08:03.172563+00:00 heroku[web.1]: State changed from starting to c
rashed
2016-02-16T14:08:05.121238+00:00 heroku[router]: at=error code=H10 desc="App cra
shed" method=GET path="/myresource" host=ftptransfer.herokuapp.com request_id=28
a84ca6-e983-4fa2-9977-44fff8b2ff58 fwd="115.114.17.154" dyno= connect= service=
status=503 bytes=
2016-02-16T14:08:06.325390+00:00 heroku[router]: at=error code=H10 desc="App cra
shed" method=GET path="/myresource" host=ftptransfer.herokuapp.com request_id=26
a57209-b0f4-49cc-8e63-a9806348f1df fwd="115.114.17.154" dyno= connect= service=
status=503 bytes=
2016-02-16T14:08:09.244071+00:00 heroku[router]: at=error code=H10 desc="App cra
shed" method=GET path="/favicon.ico" host=ftptransfer.herokuapp.com request_id=d
c079096-1929-4b71-8094-333d43b03d21 fwd="115.114.17.154" dyno= connect= service=
 status=503 bytes=
2016-02-16T14:08:09.514682+00:00 heroku[router]: at=error code=H10 desc="App cra
shed" method=GET path="/favicon.ico" host=ftptransfer.herokuapp.com request_id=2
e11d1ea-95e5-4b39-86c8-305cf7532a29 fwd="115.114.17.154" dyno= connect= service=
 status=503 bytes=
2016-02-16T14:08:13.994394+00:00 heroku[router]: at=error code=H10 desc="App cra
shed" method=GET path="/myresource" host=ftptransfer.herokuapp.com request_id=3a
a78131-9b59-46ae-9028-e428d370cb52 fwd="115.114.17.154" dyno= connect= service=
status=503 bytes=
2016-02-16T14:09:22.133471+00:00 heroku[router]: at=error code=H10 desc="App cra
shed" method=GET path="/" host=ftptransfer.herokuapp.com request_id=96020566-b42
d-40af-ad49-071a7c1bbdee fwd="115.114.17.154" dyno= connect= service= status=503
 bytes=
2016-02-16T14:10:25.860281+00:00 heroku[router]: at=error code=H10 desc="App cra
shed" method=GET path="/myresource" host=ftptransfer.herokuapp.com request_id=dd
9880db-289d-43e3-87b0-5f9f68c0d961 fwd="115.114.17.154" dyno= connect= service=
status=503 bytes=
2016-02-16T14:10:31.775874+00:00 heroku[router]: at=error code=H10 desc="App cra
shed" method=GET path="/myresource" host=ftptransfer.herokuapp.com request_id=45
a44e6d-91c2-4f4c-a629-dfb16f5f863b fwd="115.114.17.154" dyno= connect= service=
status=503 bytes=
2016-02-16T14:13:54.431711+00:00 heroku[router]: at=error code=H10 desc="App cra
shed" method=GET path="/myresource" host=ftptransfer.herokuapp.com request_id=90
2059bd-d31f-4eb4-93fb-0badf7afcd6d fwd="115.114.17.154" dyno= connect= service=
status=503 bytes=
后来我又添加了一个类用于测试文件上传

package com.example;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import com.sun.jersey.core.header.FormDataContentDisposition;
import com.sun.jersey.multipart.FormDataParam;

@Path("/file")
public class PostFileToHTP {

    @POST
    @Path("/upload")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    public Response uploadFile(
        @FormDataParam("file") InputStream uploadedInputStream,
        @FormDataParam("file") FormDataContentDisposition fileDetail) {

        String uploadedFileLocation = "d://uploaded/" + fileDetail.getFileName();

        // save it
        writeToFile(uploadedInputStream, uploadedFileLocation);

        String output = "File uploaded to : " + uploadedFileLocation;

        return Response.status(200).entity(output).build();

    }

    // save uploaded file to new location
    private void writeToFile(InputStream uploadedInputStream,
        String uploadedFileLocation) {

        try {
            OutputStream out = new FileOutputStream(new File(
                    uploadedFileLocation));
            int read = 0;
            byte[] bytes = new byte[1024];

            out = new FileOutputStream(new File(uploadedFileLocation));
            while ((read = uploadedInputStream.read(bytes)) != -1) {
                out.write(bytes, 0, read);
            }
            out.flush();
            out.close();
        } catch (IOException e) {

            e.printStackTrace();
        }

    }

}
我添加了一个依赖项

<dependency>
    <groupId>com.sun.jersey.contribs</groupId>
    <artifactId>jersey-multipart</artifactId>
    <version>1.8</version>
</dependency>

com.sun.jersey.contribs


我缺少什么--

“NoSuchMethodError:javax.ws.rs.core.Application.getProperties()Ljava/util/Map;”。这就是错误所在。类路径上混合了JAX-RS2.x和1.x类。如果你想使用2.x,你需要去掉1.x的东西。为了获得更好的帮助,发布您的dependenciesok意味着我添加了一个dependency com.sun.jersey.contribs jersey multipart 1.8您认为这是导致问题的原因吗,您需要使用2.x。看@peeskillet谢谢我会试试这个让你知道
<dependency>
    <groupId>com.sun.jersey.contribs</groupId>
    <artifactId>jersey-multipart</artifactId>
    <version>1.8</version>
</dependency>