Maven tomcat-plugin找不到自定义域

时间:2014-11-27 11:20:11

标签: maven maven-tomcat-plugin

我是自定义领域的初学者。我正在尝试使用Maven和CustomRealm创建一个演示。

当我运行maven项目时,我得到ClassNotFoundException用于自定义关系类。

以下是代码段。

的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example.realm</groupId>
    <artifactId>RealmDemo</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>RealmDemo Maven Webapp</name>
    <url>http://maven.apache.org</url>

    <dependencies>
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-catalina</artifactId>
            <version>7.0.47</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <finalName>RealmDemo</finalName>
    </build>
</project>

自定义领域类

public class TestRealm extends RealmBase {

    @Override
    protected String getName() {
        System.out.println("Get Name");
        return null;
    }
    @Override
    protected String getPassword(String arg0) {
        System.out.println("Get Password for "+arg0);
        return null;
    }
    @Override
    protected Principal getPrincipal(String arg0) {
        System.out.println("Get Principal for "+arg0);
        return null;
    }
}

的web.xml

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>RealmDemo</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>TestRealm</servlet-name>
        <servlet-class>com.test.TestRealm</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>TestRealm</servlet-name>
        <url-pattern>/test</url-pattern>
    </servlet-mapping>
    <security-role>
        <role-name>admin</role-name>
    </security-role>

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>
                Entire Application
            </web-resource-name>
            <url-pattern>/</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>admin</role-name>  
        </auth-constraint>
    </security-constraint>
    <login-config>
        <auth-method>FORM</auth-method> 
        <form-login-config>
            <form-login-page>/login/login.html</form-login-page>
            <form-error-page>/login/error.html</form-error-page>
        </form-login-config>
    </login-config>
</web-app>

我在META-INF文件夹中有一个context.xml文件,其文件配置如下

/META-INF/context.xml

<Context>
    <Realm className="com.test.TestRealm" />
</Context>

当我使用mvn clean install tomcat:run运行此项目时,我得到以下异常

Caused by: java.lang.ClassNotFoundException: com.test.TestRealm

我在过去2天内搜索谷歌的解决方案,但没有得到任何适当的解决方案。

请指导。

由于

0 个答案:

没有答案