Eclipse集成MapStruct

Eclipse集成MapStruct

今天拿到同事其他项目的源码,导入并运行的时候抛出了异常,根据异常定位到Mappers.getMapper()获取不到值,后面查了一下发现是Eclipse需要自己手动集成MapStruct插件支持才行,同事用的IDEA已经默认支持了MapStruct,所以没这个问题。想换IDEA的心越来越强烈了。。。。

在Eclipse中添加MapStruct依赖

(这个其实原本项目中本来就有了,加上去是为了完整,万一哪天自己要加还可以看一下)

在pom.xml中添加:

bash 复制代码
...
<properties>
    <org.mapstruct.version>1.5.5.Final</org.mapstruct.version>
</properties>
...
<dependencies>
    <dependency>
        <groupId>org.mapstruct</groupId>
        <artifactId>mapstruct</artifactId>
        <version>${org.mapstruct.version}</version>
    </dependency>
</dependencies>
...
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>1.8</source> <!-- depending on your project -->
                <target>1.8</target> <!-- depending on your project -->
                <annotationProcessorPaths>
                    <path>
                        <groupId>org.mapstruct</groupId>
                        <artifactId>mapstruct-processor</artifactId>
                        <version>${org.mapstruct.version}</version>
                    </path>
                    <!-- other annotation processors -->
                </annotationProcessorPaths>
            </configuration>
        </plugin>
    </plugins>
</build>

这其实是出自于MapStruct的官网:https://mapstruct.org/documentation/installation

配置Eclipse支持MapStruct

可直接参考官网:https://mapstruct.org/documentation/ide-support/

①安装 m2e-apt

Eclipse Marketplace的方式安装

eclipse里面:Help--> Eclipse Marketplace 打开应用市场,输入m2e-apt,选择m2e-apt 1.5.4(最新的),点击Installed进行安装

Install new software的方式安装(JDK8用到)

我自己在Eclipse Marketplace上安装不了,提示大概意思JDK要11才行(或者11以上?)。自己用的是JDK8,只能找低一点的m2e-apt版本进行安装。

m2e-apt的其他版本地址:https://download.jboss.org/jbosstools/updates/m2e-extensions/m2e-apt/

在Eclipse那里,Help-->Install new software,弹出的框那里点击Add...

在弹出的框那里输入Nane:m2e,Location输入要选择m2e-apt的版本地址,我的Eclipse是2020-06,选择m2e-apt 1.5.3,输入m2e-apt 1.5.3的地址

点Add后next进行添加,一直往后安装就好,这里不截图了。

m2e-apt 的版本地址可以直接从浏览器那里复制,如我选择了m2e-apt 1.5.3,点到对应的地址是

②添加到pom.xml

安装完后需要在pom.xml那里添加(我是在版本依赖的pom.xml那里进行添加):

bash 复制代码
<properties>
  <!-- automatically run annotation processors within the incremental compilation -->
  <m2e.apt.activation>jdt_apt</m2e.apt.activation>
</properties>

最后重启一下Eclipse,重新运行项目。

相关推荐
hongtianzai8 分钟前
Laravel8.x核心特性全解析
java·c语言·开发语言·golang·php
逸Y 仙X12 分钟前
文章十一:ElasticSearch Dynamic Template详解
java·大数据·数据库·elasticsearch·搜索引擎·全文检索
隔壁小邓14 分钟前
IDEA 中同时启动多个微服务
java·微服务·intellij-idea
:12114 分钟前
idea17创建tomcat项目(计网底层核心理解!)
java·ide·intellij-idea
Brookty18 分钟前
网络通信核心:四元组、socket与IO机制详解
java·网络通信·网络入门
猿小猴子18 分钟前
主流 AI IDE 之一的 华为云码道「CodeArts」 介绍
ide·人工智能·ai·华为云
佩奇大王28 分钟前
P159 摆动序列
java·开发语言·算法
计算机学姐30 分钟前
基于SpringBoot的网吧管理系统
java·spring boot·后端·spring·tomcat·intellij-idea·mybatis
Boop_wu31 分钟前
[Java EE 进阶] SpringBoot 配置文件全解析:properties 与 yml 的使用(1)
java·spring boot·spring·java-ee
我不是秋秋33 分钟前
软件开发项目各角色关系解析:产品/前后端/测试如何高效协作?
java·算法·面试·职场和发展·哈希算法