我知道这已经回答了一段时间。我无法从 Ben McCann 那里得到为我工作的答案。但是,我很幸运,通过添加将 JSP 支持直接添加到 Jetty
<!--jsp support for jetty, add the 2 following -->
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jsp-2.1</artifactId>
<version>6.1.14</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jsp-api-2.1</artifactId>
<version>6.1.14</version>
<type>jar</type>
</dependency>
奇怪的是,我最初拥有的 6.1.24 版本不支持这一点。
所以总的来说,这让我的 pom.xml 看起来像这样:
http://maven.apache.org/xsd/maven-4.0.0.xsd">4.0.0
<groupId>wikiproject</groupId>
<artifactId>wikiproject</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<jetty.version>6.1.14</jetty.version>
</properties>
<!-- Jetty dependencies -->
<dependencies>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<version>${jetty.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>${jetty.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-plus</artifactId>
<version>${jetty.version}</version>
<type>jar</type>
</dependency>
<!--jsp support for jetty, add the 2 following -->
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jsp-2.1</artifactId>
<version>${jetty.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jsp-api-2.1</artifactId>
<version>${jetty.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-antlr</artifactId>
<version>1.7.1</version>
</dependency>
</dependencies>
和我的开始课程(我在文件夹中添加\src\test\java\com\company\wikiproject
)
package com.company.wikiproject;
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.bio.SocketConnector;
import org.mortbay.jetty.webapp.WebAppContext;
/**
* User: Jesper Rønn-Jensen
* start wiki pages
*/
公共课开始{
public static void main(String[] args) {
Server jettyServer = null;
try {
jettyServer = new Server();
SocketConnector conn = new SocketConnector();
conn.setPort(8080);
jettyServer.setConnectors(new Connector[]{conn});
WebAppContext context = new WebAppContext();
context.setContextPath("/");
context.setWar("src/main/webapp");
jettyServer.setHandler(context);
jettyServer.start();
} catch (Exception ignore) {
if (jettyServer != null) {
try {
jettyServer.stop();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
}
}