我正在尝试将我当前的应用程序转换为 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
我创建了包含所有模型类的模型模块,并且我能够成功编译它。
现在我正在尝试编译 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>
如果您需要更多信息,请告诉我。
最佳答案
您的 mybatis
模块缺少对模型项目的依赖项。依赖项基本上包括模块的编译类路径中另一个项目的类。
所以,包括:
<dependency>
<groupId>com.myproject</groupId>
<artifactId>model</artifactId>
<version>${project.version}</version>
</dependency>
在你的 mybatis
模块中,你应该可以开始了。
关于java - 使用eclipse将项目转换为maven,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22769789/