问题
I'm having project named car-rental which contains business logic (built with maven). I use this project as dependency in other project named car-rental. It's declared as :
<dependency>
<groupId>com.car.rental</groupId>
<artifactId>car-rental-model</artifactId>
<version>1.0</version>
</dependency>
During compilation in IDE Eclipse car-rental see all classes from dependency. But after deploy to Java EE container (for example GlassFish) classes aren't seen. Deployed project in server doesn't contain dependency classes.
car-rental project doesn't contains any specific build definitions:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.2</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
After maven packaging, car-rental-1.0 in target directory, contains required classes from business dependency.
Here's my car-rental project structure:
Probably I should somehow link business dependency in pom.xml file, but I have no idea how... Or maybe I thining wrong?
UPDATE
car-rental-model is packaged as *.jar file
<groupId>com.car.rental</groupId>
<artifactId>car-rental-model</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>car-rental-model</name>
car-rental is packaged as *.war file
<modelVersion>4.0.0</modelVersion>
<groupId>com.car.rental</groupId>
<artifactId>car-rental</artifactId>
<version>1.0</version>
<packaging>war</packaging>
UPDATE 2
To give more info about project I put configuration files:
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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="CarRental" version="2.5">
<display-name>CarRental</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/configs/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>1000</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>redirect.jsp</welcome-file>
</welcome-file-list>
</web-app>
dispatcher-servlet.xml contains only references to other configuration files, which stores only configurations to Tiles, controllers or DAO implementations - it's rather not important to place here... maybe except Hibernate mapping:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.H2Dialect
hibernate.hbm2ddl.auto=create
hibernate.ejb.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
hibernate.connection.charSet=UTF-8
hibernate.bytecode.provider=javassist
hibernate.show_sql=true
hibernate.format_sql=true
</value>
</property>
<property name="annotatedClasses">
<list>
<value>com.car.rental.model.Car</value>
<value>com.car.rental.model.User</value>
</list>
</property>
</bean>
回答1:
I think your configuration could look like this
Car rental model
<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>com.car.rental</groupId>
<artifactId>car-rental-model</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<!-- dependencies ... -->
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Car rental
<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>com.car.rental</groupId>
<artifactId>car-rental</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.car.rental</groupId>
<artifactId>car-rental-model</artifactId>
<version>1.0</version>
</dependency>
<!-- other dependencies -->
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
I use the same configuration in all my projects and it works fine. If all of them have the maven-compiler-plugin
, I will prefer creating a parent containing the common parts.
来源:https://stackoverflow.com/questions/9448852/spring-web-app-with-maven-dependency-class-not-found-during-deploy