1

我正在使用 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。那么是什么导致码头实例找不到这个罐子呢?

我正在使用eclipse,它在代码中没有显示错误。我将其设置为 Maven 项目,Maven 处理依赖项。我将其设置为不打包码头罐子,因为它们应该在部署时由码头提供。这是我的 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 并且它确实如此处所示

可能是问题的一部分:为了实现一个新的LoginService接口类,我扩展了MappedLoginService已经实现的类LoginService(它在 Jetty jars 中)并且我覆盖了它的一些方法。这会导致问题吗?

4

1 回答 1

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 的任何设置。

于 2013-08-01T00:14:58.307 回答