我想使用Tomcat来测试一些Web服务(使用maven)。 Tomcat与maven @ test一起运行。当我尝试部署我的战争时,我直接获得JspServlet的ClassNotFoundException。 jasper jar在classpath中,我通过代码调试。尝试使用loadClass()加载类 - >得到这个错误,Class.forName()正在运行......
也许有人有想法
我的测试课程:
@BeforeClass
public static void setUp() throws Exception {
wsdlURL = new URL(address + "?wsdl");
String appBase = "./target";
tomcat = new Tomcat();
tomcat.setPort(Integer.parseInt(System.getProperty("port")));
tomcat.setBaseDir(".");
tomcat.getHost().setAppBase(appBase);
StandardServer server = (StandardServer) tomcat.getServer();
AprLifecycleListener listener = new AprLifecycleListener();
server.addLifecycleListener(listener);
Context app = tomcat.addWebapp("/service", warFile.getAbsolutePath());
app.addSecurityRole("AllRole");
tomcat.start();
}
我的pom.xml的一部分:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
<systemProperties>
<property>
<name>warFile</name>
<value>${project.build.finalName}</value>
</property>
<property>
<name>port</name>
<value>9101</value>
</property>
</systemProperties>
<classpathDependencyExcludes>
<classpathDependencyExclude>javax:javaee-web-api</classpathDependencyExclude>
</classpathDependencyExcludes>
</configuration>
</plugin>
[...]
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>${tomcat.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-logging-juli</artifactId>
<version>${tomcat.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>${tomcat.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>${tomcat.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper-el</artifactId>
<version>${tomcat.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jsp-api</artifactId>
<version>${tomcat.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>${tomcat.version}</version>
<scope>test</scope>
</dependency>
我尝试过tomcat版本7和8。
也许有人知道为什么忽略jasper包?