Projeto Web com Maven, Eclipse e libs externas

1 resposta
romarcio

Estou começando a usar Maven e estou encontrando um probleminha em um projeto que criei no Eclipse, o qual também sou iniciante.
O que acontece é o seguinte:
1° Criei pelo eclipse um projeto maven
2° Transformei esse projeto em um projeto web
3° Adicionei no pom.xml as dependencias (hibernate, jstl, …) e o eclipse criou na arvore um item “Maven Dependencies” com todas elas dentro.
4° Selecionei o servidor Tomcat e mandei rodar

Dai quando o Tomcat roda, pelo eclipse, ele não encontra as classes das bibliotecas adicionadas no pom.xml

Gostaria de saber se tenho que fazer mais alguma coisa.

1 Resposta

romarcio

Esse é o arquivo Maven que foi gerado pelo Eclipse, o qual inseri as dependências:

<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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>MyFirstMaven</groupId>
	<artifactId>MyFirstMaven</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>war</packaging>

	<name>MyFirstMaven</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<dependencies>
		<dependency>
			<groupId>asm</groupId>
			<artifactId>asm</artifactId>
			<version>3.1</version>
		</dependency>
		<dependency>
			<groupId>commons-logging</groupId>
			<artifactId>commons-logging</artifactId>
			<version>1.0.4</version>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jstl</artifactId>
			<version>1.1.2</version>
		</dependency>
		<dependency>
			<groupId>javax.servlet.jsp.jstl</groupId>
			<artifactId>jstl-api</artifactId>
			<version>1.2</version>
		</dependency>
		<dependency>
			<groupId>org.glassfish.web</groupId>
			<artifactId>jstl-impl</artifactId>
			<version>1.2</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-aop</artifactId>
			<version>3.0.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-asm</artifactId>
			<version>3.0.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-beans</artifactId>
			<version>3.0.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>3.0.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context-support</artifactId>
			<version>3.0.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>3.0.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-expression</artifactId>
			<version>3.0.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-oxm</artifactId>
			<version>3.0.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>3.0.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>3.0.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.ws</groupId>
			<artifactId>spring-xml</artifactId>
			<version>1.0-m2</version>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
	</dependencies>
</project>

Esse é o Log gerado no console do Eclipse. Veja que ele não encontras as classes: org.springframework.web.servlet.DispatcherServlet
Essa classe está presente na dependência: spring-webmvc

22/10/2011 15:00:57 org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments 
	was not found on the java.library.path: 
	C:\Program Files (x86)\Java\jre6\bin;
	C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files\Common Files\Microsoft Shared\Windows Live;
	C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;
	C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;
	C:\Program Files (x86)\JavaFX\javafx-sdk1.3\bin;C:\Program Files (x86)\JavaFX\javafx-sdk1.3\emulator\bin;C:\Windows\system32;
	C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;
	C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Windows Live\Shared;CATALINA_HOME\bin;
	C:\Program Files\Java\jdk1.7.0\bin;C:\jboss-4.2.3.GA\bin;C:\axis2-1.5.4\bin;C:\apache-maven-3.0.3\bin;;.
22/10/2011 15:00:57 org.apache.tomcat.util.digester.SetPropertiesRule begin
AVISO: [SetPropertiesRule]{Server/Service/Engine/Host/Context} 
	Setting property 'source' to 'org.eclipse.jst.jee.server:MyFirstMaven' did not find a matching property.
22/10/2011 15:00:58 org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
22/10/2011 15:00:58 org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 319 ms
22/10/2011 15:00:58 org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
22/10/2011 15:00:58 org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.32
22/10/2011 15:00:58 org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet spring as unavailable
22/10/2011 15:00:58 org.apache.catalina.core.ApplicationContext log
GRAVE: Error loading WebappClassLoader
  context: /MyFirstMaven
  delegate: false
  repositories:
    /WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@18fe7c3
 org.springframework.web.servlet.DispatcherServlet
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
	...
22/10/2011 15:00:58 org.apache.catalina.core.StandardContext loadOnStartup
GRAVE: Servlet /MyFirstMaven threw load() exception
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
	...
22/10/2011 15:00:58 org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
22/10/2011 15:00:58 org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
22/10/2011 15:00:58 org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/10  config=null
22/10/2011 15:00:58 org.apache.catalina.startup.Catalina start
INFO: Server startup in 201 ms
22/10/2011 15:01:00 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
	...

Estou rodando a aplicação pelo "Run As > Run on Server".

Criado 22 de outubro de 2011
Ultima resposta 22 de out. de 2011
Respostas 1
Participantes 1