我正在尝试将当前的应用程序转换为maven。我将代码分成不同的模块。
它是一个具有
的Web应用程序 Controller package
Model package
services packages
DAO packages
mybatis package which has interface to interact with database
WEB-INF Folder which contains all jsps inside /jsp folder
我创建了不同的模块,我创建了一个核心模块,现在已经
了 service package
DAO Package
src/main/webapp/WEB-INF
我创建了Model模块,它包含所有模型类,我能够成功编译它。
现在我正在尝试编译mybatis包,它给了我错误
/home/.../mybatis/db/mybatis/dao/usersmapper.java :[7,54] error:
package com.mycom.myproject.mybatis.db.mybatis.model does not exist
因为usersmapper.class已经使用模型模块创建。
所以我没有得到我做错的事。
我的主要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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myproject</groupId>
<artifactId>mainapp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>mainapp</name>
<properties>
<spring.version>3.1.1.RELEASE</spring.version>
</properties>
<dependencies>
<!--Joda time -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time-jsptags</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<modules>
<module>model</module>
<module>core</module>
<module>mybatis</module>
</modules>
我的模型pom是我能够编译的
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>mainapp</artifactId>
<groupId>com.myproject</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.myproject</groupId>
<artifactId>model</artifactId>
<packaging>jar</packaging>
<name>model</name>
和我无法编译的mybatis pom是
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>mainapp</artifactId>
<groupId>com.myproject</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.myproject</groupId>
<artifactId>mybatis</artifactId>
<packaging>jar</packaging>
<name>mybatis</name>
<dependencies>
<!-- mybaties -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.0</version>
</dependency>
</dependencies>
如果您需要更多信息,请与我们联系。
答案 0 :(得分:1)
您的mybatis
模块缺少对模型项目的依赖性。依赖项基本上包括模块的编译类路径中的另一个项目的类。
所以,包括:
<dependency>
<groupId>com.myproject</groupId>
<artifactId>model</artifactId>
<version>${project.version}</version>
</dependency>
在你的mybatis
模块中,你应该好好去。