我正在使用Jetty 9.0.4v20130625使用maven-jetty-plugin
运行它。我已经实现了自己的LoginService
类来处理登录领域的用户。在其中一行中,我尝试使用org.eclipse.jetty.util.security.Credential
类,但在执行期间,它会在该行上抛出NoClassDefFoundError
。
我的target
目录包含部署到Jetty实例的所有内容。在其中WEB-INF/lib
文件夹不包含预期的jetty-util-9.0.4.v20130625.jar
因为插件应该已经拥有它所以我相信这会排除冲突的jar。那么什么可能导致jetty实例找不到这个jar?
我正在使用eclipse,它在代码中没有显示错误。我将其设置为Maven项目,Maven处理依赖项。我将其设置为不打包Jetty罐子,因为它们应该在部署时由Jetty提供。这是我的pom.xml:
<project ...>
...
<packaging>war</packaging>
...
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>9.0.4.v20130625</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.11.2</version>
</dependency>
</dependencies>
<build>
<finalName>...</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.0.4.v20130625</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webApp>
<contextPath>/...</contextPath>
</webApp>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>Test Realm</realm-name>
<form-login-config>
<form-login-page>/loginAuth.html?param=redirect</form-login-page>
<form-error-page>/loginAuth.html?param=failed</form-error-page>
</form-login-config>
</login-config>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.8.1</version>
<configuration>
<connectionType>developerConnection</connectionType>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>install</phase>
<configuration>
<tasks>
<ant target="deploy" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.50</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-jsch</artifactId>
<version>1.9.2</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
我检查确保插件依赖于jetty-util.jar,它看起来像here
可能是问题的一部分:为了实现一个新的LoginService
接口类,我正在扩展已经实现MappedLoginService
的{{1}}类(它在Jetty jar中)和我重写了一些方法。这会导致问题吗?
答案 0 :(得分:1)
Jetty几乎隐藏了webapp的类加载器中的所有实现类。如果您需要从webapp中访问它们,那么您需要将它们放入webapp的WEB-INF / lib中(在您的情况下为jetty-util jar添加依赖项)。
此类描述机制在此处描述:http://www.eclipse.org/jetty/documentation/current/jetty-classloading.html
顺便说一句,你的pom.xml中的jetty-maven-plugin的配置似乎包含了web.xml中的一些行(即元素内部的那些行)。我相信maven忽略了它不理解的配置,但也许事情没有像你认为的那样配置?另外,我没有看到任何使用自定义LoginService的设置。