我正在使用Netbeans启动一个将在Glassfish中运行的新应用程序。
我使用Netbeans向导使用maven-archetype-webapp创建一个新的项目,并将我的所有类放在src->main->resources
和我的JSP文件下src->main->webapp
这是我的web.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>My Applicaton Name</display-name>
<servlet>
<servlet-name>Access</servlet-name>
<servlet-class>com.company.department.controller.UserController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Access</servlet-name>
<url-pattern>/Access</url-pattern>
</servlet-mapping>
</web-app>
这是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.mycompany</groupId>
<artifactId>MyApp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>MyApp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7</version>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom2</artifactId>
<version>2.0.6</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.liferay</groupId>
<artifactId>org.apache.commons.fileupload</artifactId>
<version>1.2.2.LIFERAY-PATCHED-1</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20141113</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<type>jar</type>
</dependency>
</dependencies>
<build>
<finalName>MyApp</finalName>
</build>
</project>
当我在本地主机中运行时,我得到java.lang.ClassNotFoundException: com.company.department.controller.UserController
我是Maven的新手,所以我的错误在哪里?
我在SO中发现了一些类似的问题,但没有一个解决方案可以解决问题,而且大多数解决方案都是针对Eclipse的,并且在NetBeans中显然存在一些差异。
答案 0 :(得分:1)
这是您的maven pom文件的片段。 确保以下内容符合规定。
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
</properties>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>