I'm using Jetty 9.0.4v20130625 running it using the maven-jetty-plugin
. I have implemented my own LoginService
class to handle users logging in to a realm. On one of the lines, I attempt to use the org.eclipse.jetty.util.security.Credential
class but during execution it throws a NoClassDefFoundError
on that line.
My target
directory contains everything being deployed to the Jetty instance. Within it the WEB-INF/lib
folder does not contain the jetty-util-9.0.4.v20130625.jar
as expected because the plugin should already have it so I believe that rules out conflicting jars. So what could be causing the jetty instance to not find this jar?
I am using eclipse, and it shows no errors in the code. I set it up as a Maven project and Maven handles the dependencies. I set it to not to package the jetty jars as they should be provided by Jetty when deployed. Here is my 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>
I checked to be sure the plugin depends on the jetty-util.jar and it does as seen here
Something that may be part of the problem: To implement a new LoginService
interface class, I am extending the MappedLoginService
class which already implements LoginService
(it's in the Jetty jars) and I'm overriding some of its methods. Could that be causing a problem?
Jetty hides almost all of its implementation classes from the webapp's classloader. If you need access to them from inside your webapp, then you need to put them into your webapp's WEB-INF/lib (in your case add a dependency for jetty-util jar).
This classloading mechanism is described here: http://www.eclipse.org/jetty/documentation/current/jetty-classloading.html
BTW, the configuration for the jetty-maven-plugin from your pom.xml seems to contain some lines from web.xml (i.e. those inside the elements). I believe maven ignores configuration it doesn't understand, but perhaps things are not configured the way you think they are? Also, I don't see any setup for using your custom LoginService.