【问题标题】:What is needed to configure Jetty to run Spring MVC application?配置 Jetty 运行 Spring MVC 应用程序需要什么?
【发布时间】:2016-03-03 06:34:51
【问题描述】:

我正在研究 Spring MVC 网络缩写,我需要它在 Jetty 服务器上工作(Jetty 应该是 Servlet Cobtainer)。 我通过“编辑运行配置”将 Jetty 服务器添加到我的应用程序中。

Edit Run Config


以下是应用服务器设置:

App server settings

但是,当我启动我的应用程序时,IDEA 给了我这个:

"C:\Program Files\Java\jdk1.8.0_65\bin\java" -DSTOP.PORT=0 -Dcom.sun.management.jmxremote= -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -DOPTIONS=jmx -Didea.launcher.port=7535 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 15.0.4\bin" -Dfile.encoding=windows-1251 -classpath "D:\jetty-distribution-9.3.7.v20160115\start.jar;C:\Program Files\Java\jdk1.8.0_65\lib\tools.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 15.0.4\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain org.eclipse.jetty.start.Main --module=jmx C:\Windows\Temp\context4config\jetty-contexts.xml
[2016-03-03 07:17:55,511] Artifact DVDExchange:war exploded: Server is not connected. Deploy is not available.
Detected server http port: 8080
java.nio.file.AccessDeniedException: C:\Windows\Temp\context4config\jetty-contexts.xml
    at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:83)
    at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:90)
    at sun.nio.fs.WindowsLinkSupport.getRealPath(WindowsLinkSupport.java:259)
    at sun.nio.fs.WindowsPath.toRealPath(WindowsPath.java:836)
    at sun.nio.fs.WindowsPath.toRealPath(WindowsPath.java:44)
    at org.eclipse.jetty.start.FS.toRealPath(FS.java:165)
    at org.eclipse.jetty.start.StartArgs.addUniqueXmlFile(StartArgs.java:217)
    at org.eclipse.jetty.start.StartArgs.resolveExtraXmls(StartArgs.java:1123)
    at org.eclipse.jetty.start.Main.processCommandLine(Main.java:342)
    at org.eclipse.jetty.start.Main.main(Main.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

Usage: java -jar start.jar [options] [properties] [configs]
       java -jar start.jar --help  # for more information
Disconnected from server

Process finished with exit code -9


可能原因之一是 epmpty jetty-web.xml 文件:

<?xml version="1.0"  encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<Configure class="org.eclipse.jetty.webapp.WebAppContext">

</Configure>

但实际上我应该如何让码头以正确的方式与 Spring web-app 一起工作。 如果我必须做的事情,有人可以给出完整的清单。结构良好且详细的教程将是最好的答案。我真的需要处理那个码头。 提前致谢!

【问题讨论】:

    标签: java spring-mvc intellij-idea jetty


    【解决方案1】:

    这个问题可以满足你的需求,

    Debug web app in IntelliJ, webapp built by maven, run by jetty

    您需要将嵌入式 maven-jetty 插件添加到您的 pom.xml 并运行 maven 目标以启动码头服务器,mvn jetty:run

    <build>
            <plugins>
                <plugin>
                    <groupId>org.mortbay.jetty</groupId>
                    <artifactId>jetty-maven-plugin</artifactId>
                    <version>8.1.8.v20121106</version>
                    <configuration>
                        <contextPath>/</contextPath>
                        <connectors>
                            <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                                <!--<port>8085</port>-->
                                <port>8080</port>
                                <maxIdleTime>60000</maxIdleTime>
                            </connector>
                        </connectors>
                        <stopKey>stop</stopKey>
                        <stopPort>8089</stopPort>
                    </configuration>
                </plugin>            
            </plugins>
    </build>
    

    【讨论】:

    • 运行码头服务器的有趣方式。但是我应该在哪里输入:mvn jetty:run?
    • 由于您使用 Intellij Idea 作为您的 IDE,因此我没有这方面的经验。但是这个文档Executing Maven Goal 应该会有所帮助。
    • @IngeniousTom 你也可以试试Ctrl+Shift+F10快捷方式来调出运行配置。
    • @Licky 好的 - 我会试试的。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2015-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-25
    • 1970-01-01
    相关资源
    最近更新 更多