博客
关于我
idea中多模块项目MAVEN打包若干问题的解决方案
阅读量:480 次
发布时间:2019-03-06

本文共 1986 字,大约阅读时间需要 6 分钟。

Maven项目构建及Spring Boot打包问题及解决方法

一、Maven项目中出现“Could not find artifact…”错误的解决方案

在多模块 Maven 项目中,可能会遇到“Could not find artifact …:pom:0.0.1-SNAPSHOT”的错误。这个问题通常是因为父模块没有被正确安装,导致子模块在编译时无法找到父模块的依赖。

解决方法

  • 确保多模块项目的父模块已经被安装。进入父模块目录,执行:
  • mvn clean install
    1. 完成父模块安装后,进入子模块目录,执行:
    2. mvn clean compile

      这将确保父模块的依赖被正确引入,避免错误。

      二、Spring Boot项目打包错误“Unable to find main class”的解决方法

      使用Spring Boot Maven 插件可能会遇到无法找到主类的问题。这个问题通常是由于项目结构不符合插件的要求,或者项目中缺失必要的启动类。

      解决方法

    3. 可以考虑不使用Spring Boot Maven 插件,而是改用传统的Maven 插件。这样,每个模块只需拥有启动类即可进行打包,而无需每个模块都有完整的启动配置。
    4. 配置 Maven 插件,如以下示例:
    5. org.apache.maven.plugins
      maven-compiler-plugin
      3.8.1
      1.8
      1.8
      ${project.build.sourceEncoding}

      确保 compiler 插件配置正确,与 JDK 版本一致,避免因版本不符导致打包失败。

      三、 IDEA 中出现“Compilation failed: internal java compiler error”的解决方法

      该错误通常与 JDK 版本相关,可能源于项目或 IDE 的 JDK 配置不一致。

      解决方法

    6. 检查项目和 JDK 版本是否匹配。在 IDEA 中的 File > Settings > Project:Modules 中查看每个模块的 JDK 版本是否正确。
    7. 项目可能使用的是环境变量中的 JDK 安装路径,而不是与项目配置冲突的。
    8. 在 IDEA 中的 File > Settings > Build, Execution, Deployment > Compiler 设置 Java Compiler 的目标版本,与项目 JDK 一致,例如设置为 1.8 或更高版本。
    9. 另一种方法是在 Maven 项目的 pom 文件中指定 JDK 版本,例如:
    10. org.apache.maven.plugins
      maven-compiler-plugin
      3.8.1
      1.8
      1.8

      确保 JDK 和 Maven 插件配置一致,避免编译器因版本不匹配而出错。

      四、 IDEA 中持续出现“Compilation failed:…”错误的解决建议

      除了调整 JDK 配置,IDEA 的缓存问题也可能导致错误。执行以下步骤可以解决问题:

    11. 关闭 IDEA后,重新打开项目,或者清理项目的缓存文件。
    12. 在 menu bar 中选择 Build > Clean Project 或者根据提示清理项目文件。
    13. 确认项目的 JDK 配置准确无误,避免默认值与实际使用的 JDK 不符。
    14. 通过以上方法,开发者可以有效解决 Maven 项目构建和打包在 IDEA 或命令行环境中出现的常见错误,确保项目顺利完成。

    转载地址:http://irxdz.baihongyu.com/

    你可能感兴趣的文章
    npm error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”。要解决此问题,1) 安装
    查看>>
    npm install CERT_HAS_EXPIRED解决方法
    查看>>
    npm install digital envelope routines::unsupported解决方法
    查看>>
    npm install 卡着不动的解决方法
    查看>>
    npm install 报错 EEXIST File exists 的解决方法
    查看>>
    npm install 报错 ERR_SOCKET_TIMEOUT 的解决方法
    查看>>
    npm install 报错 Failed to connect to github.com port 443 的解决方法
    查看>>
    npm install 报错 fatal: unable to connect to github.com 的解决方法
    查看>>
    npm install 报错 no such file or directory 的解决方法
    查看>>
    npm install 权限问题
    查看>>
    npm install报错,证书验证失败unable to get local issuer certificate
    查看>>
    npm install无法生成node_modules的解决方法
    查看>>
    npm install的--save和--save-dev使用说明
    查看>>
    npm node pm2相关问题
    查看>>
    npm run build 失败Compiler server unexpectedly exited with code: null and signal: SIGBUS
    查看>>
    npm run build报Cannot find module错误的解决方法
    查看>>
    npm run build部署到云服务器中的Nginx(图文配置)
    查看>>
    npm run dev 和npm dev、npm run start和npm start、npm run serve和npm serve等的区别
    查看>>
    npm run dev 报错PS ‘vite‘ 不是内部或外部命令,也不是可运行的程序或批处理文件。
    查看>>
    npm scripts 使用指南
    查看>>