Reputation: 1769
I'm using Netbeans to start a new application that will runs in Glassfish.
I used the Netbeans wizard to create a new projet using the maven-archetype-webapp and put all my classes under src->main->resources
and my JSP files under src->main->webapp
This is my 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>
This is the 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>
When I run it in my localhost I get java.lang.ClassNotFoundException: com.company.department.controller.UserController
I'm new on Maven, so where is my mistake?
I found some similar problems here in SO, but no solution solved the problem and the most of them are directed for Eclipse and apparently exists some differences in NetBeans.
Upvotes: 0
Views: 551
Reputation: 3533
This is a snippet for your maven pom file. Make sure the following is as provided.
<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>
Upvotes: 1