Maven的多模块(Multi-Module)工程的pom编写

 

对于使用maven的骨架创建工程,想必大家都已经熟悉了,这里是一些常用的工程类型,如想看到更多的骨架可以使用mvn的交互式Interactive generate Goal创建指令:mvn archetype:generate


// Creating a simple java application
mvn archetype:create -DgroupId=[your project's group id] -DartifactId=[your project's artifact id]

// Creating a webapp
mvn archetype:create -DgroupId=[your project's group id] -DartifactId=[your project's artifact id] -DarchetypeArtifactId=maven-archetype-webapp

// Creating a site
mvn archetype:create -DgroupId=[your project's group id] -DartifactId=[your project's artifact id] -DarchetypeArtifactId=maven-archetype-site-simple

// Creating a mojo
mvn archetype:create -DgroupId=[your project's group id] -DartifactId=[your project's artifact id] -DarchetypeArtifactId=maven-archetype-mojo

// Creating a portlet
mvn archetype:create -DgroupId=[your project's group id] -DartifactId=[your project's artifact id] -DarchetypeArtifactId=maven-archetype-portlet

现在想介绍的是多模块的工程的构建。

典型的多模块划分,即按MVC的分层方式来构建多个模块,如工程包括web,business,core3个模块。好我们先看看主工程的pom中应添加些什么,请注意红色文字部分


1.主工程的pom文件中内容:

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.your-company.xxxx</groupId>
    <artifactId>xxxx</artifactId>
    <packaging>pom</packaging>
    <version>1.0</version>
    <name>xxxx Project</name>
    <url>http://maven.apache.org</url>

    <!-- 工程所包含的模块 -->

    <modules>
        <module>xxxx-core</module>
        <module>xxxx-business</module>
        <module>xxxx-web</module>
    </modules>

2.Web模块的pom文件:

    <!-- 父级的pom文件位置 -->

    <parent>
        <groupId>com.your-company.xxxx</groupId>
        <artifactId>xxxx</artifactId>
        <version>1.0</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <groupId>com.your-company.xxxx</groupId>
    <artifactId>xxxx-web</artifactId>
    <packaging>war</packaging>
    <version>1.0</version>
    <name>xxxx-web/name>
    <url>http://maven.apache.org</url>

    <dependencies>
        <!-- Application Dependencies -->
        <!-- Web层所依赖的上两层模块 -->

        <dependency>
            <groupId>com.your-company.xxxx</groupId>
            <artifactId>xxxx-core</artifactId>
            <version>${version}</version>
        </dependency>
        <dependency>
            <groupId>com.your-company.xxxx</groupId>
            <artifactId>xxxx-business</artifactId>
            <version>${version}</version>
        </dependency>

        ...

    <dependencies>


3.完成后,mvn eclipse:eclipse后的文件目录为:

xxxx

├─xxxx-core

│ ├─pom.xml
│ ├─.settings
│ ├─src
│ │ ├─main
│ │ │ ├─java
│ │ │ └─resources
│ │ └─test
│ │      ├─java
│ │      └─resources
│ └─target
│      ├─classes
│      └─test-classes

├─xxxx-business
│ ├─pom.xml
│ ├─.settings
│ ├─src
│ │ ├─main
│ │ │ ├─java
│ │ │ └─resources
│ │ └─test
│ │      ├─java
│ │      └─resources
│ └─target
│      ├─classes
│      └─test-classes

├─xxxx-web

│ ├─pom.xml
│ ├─.settings
│ ├─src
│ │ ├─main
│ │ │ ├─java
│ │ │ └─resources
│ │ └─test
│ │      ├─java
│ │      └─resources
│ └─target
│      ├─classes
│      └─test-classes

|--pox.xml


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Maven中配置multi-part依赖,需要在项目的pom.xml文件中添加以下依赖项: ``` <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.4</version> </dependency> ``` 这个依赖项是Apache Commons FileUpload的核心依赖项,它包含了处理multi-part请求的主要类和方法。 在Java代码中使用multi-part依赖处理文件上传和表单数据时,需要创建一个FileItemFactory对象和一个ServletFileUpload对象。FileItemFactory负责创建FileItem对象,而ServletFileUpload则负责解析multi-part请求并将每个部分转换成FileItem对象。以下是一个简单的示例: ``` FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List<FileItem> items = upload.parseRequest(request); for (FileItem item : items) { if (item.isFormField()) { // 处理表单字段 String name = item.getFieldName(); String value = item.getString(); } else { // 处理上传的文件 String fieldName = item.getFieldName(); String fileName = item.getName(); String contentType = item.getContentType(); long sizeInBytes = item.getSize(); InputStream inputStream = item.getInputStream(); // ... } } ``` 在这个示例中,DiskFileItemFactory是一个FileItemFactory的实现,它将FileItem对象存储在磁盘上。ServletFileUpload是一个Servlet API的实现,它解析multi-part请求并将每个部分转换成FileItem对象。通过遍历FileItem对象列表,可以处理上传的文件和表单字段。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值