4

休止状態、freemarker を使用する Spring MVC アプリケーションがあります。マルチMavenプロジェクトとしてセットアップされています。IntelliJ Ultimate を使用しています。

Jetty は問題なく起動しますが、

http://localhost:8080/

プロジェクトのフォルダーを出力するだけで、ブラウザーでソース コードを表示できます。

現在の私のセットアップは次のとおりです。

    final Server server = new Server(8080);

    ProtectionDomain domain = HttpServer.class.getProtectionDomain();
    URL location = domain.getCodeSource().getLocation();

    WebAppContext webAppContext = new WebAppContext();
    webAppContext.setResourceBase(location.toExternalForm());
    webAppContext.setDescriptor(location.toExternalForm() + "/WEB-INF/web.xml");
    webAppContext.setContextPath("/");
    webAppContext.setParentLoaderPriority(true);

    server.setHandler(webAppContext);

    server.start();
    server.join();

私のプロジェクト レイアウトはマルチ Maven プロジェクト (intelli J を使用) で、レイアウトは次のようになります。

/myapp/src/main/java/main.java (this contains the above code to start jetty)
/myapp/src/main/webapp
/myapp/src/main/webapp/assets
/myapp/src/main/webapp/WEB-INF
/myapp/src/main/webapp/WEB-INF/web-context.xml (spring config file)
/myapp/src/main/webapp/WEB-INF/web.xml
/myapp/src/main/webapp/WEB-INF/views/ (parent folder for my freemarker template files)
/myapp/src/main/webapp/WEB-INF/views/home/index.ftl 

私のweb.xmlは次のとおりです。

<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>classpath*:log4j.properties</param-value>
</context-param>

 <servlet>
    <servlet-name>myapp</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>WEB-INF/web-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>myapp</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

これを IntelliJ (11 ulimitate) で実行すると、次の出力が得られます。

2012-08-15 19:17:11,611 [main] INFO  org.eclipse.jetty.server.Server - jetty-7.6.2.v20120308
2012-08-15 19:17:11,886 [main] INFO  org.eclipse.jetty.webapp.StandardDescriptorProcessor - NO JSP Support for /, did not find org.apache.jasper.servlet.JspServlet
2012-08-15 19:17:11,962 [main] INFO  org.eclipse.jetty.server.handler.ContextHandler - started o.e.j.w.WebAppContext{/,file:/Users/me/projects/myapp/myapp-web/target/classes/}
2012-08-15 19:17:12,021 [main] INFO  org.eclipse.jetty.server.AbstractConnector - Started SelectChannelConnector@0.0.0.0:8080

tomcat w/intelliJ を使用して実行すると、休止状態、春などの大量の出力が得られるため、これは明らかに機能していません。

Web モジュールの pom.xml には次のものがあります。

..
 <packaging>war</packaging>
..
4

4 に答える 4

4

これを本番環境で実行することを目的としており、アプリケーションのビルドに既に maven を使用している場合は、最初に実際の war パッケージを作成することをお勧めします。

mvn clean package

次に、Web アプリケーションをビルドしたら、(ソース コードではなく) war アーカイブから実行する新しい Jetty サーバーを作成します。

Jetty のマニュアルに記載されているように、次のようになります。

    Server server = new Server(8080);

    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath("/");
    webapp.setWar("path_to_the_war_file/your_app.war");
    server.setHandler(webapp);

    server.start();
    server.join();
于 2012-08-30T09:50:46.830 に答える
2

おそらくコンテキストローダーリスナーがありません。

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
于 2012-08-16T03:28:46.223 に答える
0

defaultsDescriptorパラメーターを設定しようとしましたか

webAppContext.setDefaultsDescriptor(JETTY_HOME+"/etc/webdefault.xml");

JETTY_HOMEはjettyをインストールした場所であり、JETTY_HOME / etc/webdefault.xmlには重要な設定が含まれています。

于 2012-09-03T13:57:40.777 に答える
0

から Jetty を手動で呼び出す代わりにmain.java、 で Maven Jetty プラグインを参照し、次のコマンドpom.xmlを実行してアプリケーションを起動します。mvn jetty:run

<build>
  <plugins>
    <plugin>
      <groupId>org.mortbay.jetty</groupId>
      <artifactId>jetty-maven-plugin</artifactId>
      <version>8.1.4.v20120524</version>
    </plugin>
  </plugin>
</build>

代わりにWAR、Jetty のコピーが埋め込まれた実行可能ファイルを作成することが目的である場合は、次のようにタスクに取り組みます。

    final Connector connector = new SelectChannelConnector();
    connector.setPort(8080);

    final Server server = new Server();
    server.addConnector(connector);
    server.setStopAtShutdown(true);

    final WebAppContext context = new WebAppContext();
    context.setContextPath("/");
    context.setServer(server);

    final ProtectionDomain protectionDomain = Main.class.getProtectionDomain();
    final URL location = protectionDomain.getCodeSource().getLocation();
    context.setWar(location.toExternalForm());
    server.addHandler(context);

    server.start();
    server.join();
于 2012-09-01T14:25:28.817 に答える