IDEA最全的正确打包姿势 您所在的位置:网站首页 jar文件是什么类型的 IDEA最全的正确打包姿势

IDEA最全的正确打包姿势

2024-07-01 18:05| 来源: 网络整理| 查看: 265

文章适合新手了解IDEA怎么正确打包。文章在编写过程中难免有疏漏和错误,欢迎大佬指出文章的不足之处;更多内容请点进👉 Lino_White 👈查看。 未来的世界充满着各式各样的数据,我们该怎么好好利用起来呢?开启正文吧~~~

IDEA分三种打包方式,接下来我们将逐一使用截图来介绍,哪一种都可以使用哟!

三种打包方式——以及出现错误的解决方法 第一种:集所有依赖包在项目中打包成jar,一个jar第二种:打包成所有依赖包+项目包,多个jar第三种(小编推荐):maven打成一个jar包,一个jar 不要着急,收藏一波,看看运行常常出现的bug!!!

第一种:集所有依赖包在项目中打包成jar,一个jar

在这里插入图片描述 在这里插入图片描述 在这里插入图片描述 在这里插入图片描述 在这里插入图片描述 点击Apply,再点击OK 在这里插入图片描述 选择刚才生成的打包名,build—— 在这里插入图片描述 生成后的项目会在你项目的/out/artifacts/打包名/项目名.jar

第二种:打包成所有依赖包+项目包,多个jar

在这里插入图片描述 在这里插入图片描述 在这里插入图片描述 在这里插入图片描述 在这里插入图片描述 点击Apply,再点击OK 在这里插入图片描述 选择刚才生成的打包名,build—— 在这里插入图片描述 生成后的项目会在你项目的/out/artifacts/打包名/项目名.jar

第三种(小编推荐):maven打成一个jar包,一个jar

在这里插入图片描述 先点击clean,会先将你之前编译的class全部清除,移除缓存;再点击package打包 在这里插入图片描述 运行成功后在项目的target文件夹下就会出现一个jar包,这个拿到java上运行即可。 在这里插入图片描述

不要着急,收藏一波,看看运行常常出现的bug!!!

1、Failed to configure a DataSource: ‘url’ attribute is …

Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method ‘dataSource‘ threw except... *************************** APPLICATION FAILED TO START *************************** Description: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. Reason: Failed to determine a suitable driver class Action: Consider the following: If you want an embedded database (H2, HSQL or Derby), please put it on the classpath. If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active). 首先,在你的配置文件当中,先确定自己的项目有没有使用到HikariDataSource,如果没有移除即可;如果有,那么就看看你的配置文件中spring:datasource有没有配置少或者错误;都没问题,那么就看看pom.xml文件是不是配置正确了。pom.xml文件必须扫包的时候配置有扫描项目下的**/* .yml、** /* .xml、**/* .properties的相关配置,如下: org.springframework.boot spring-boot-maven-plugin 2.2.2.RELEASE src/main/java **/*.xml **/*.yml **/*.properties src/main/resources **/*.yml **/*.xml **/*.properties

2、错误: 找不到或无法加载主类 com.xxx.cn.AppApplication 如果你选择的是第一种,那么你应该就会遇到这种错误,这时候只需要将jar打开,将

在这里插入图片描述 3、Exception in thread “main” java.lang.ClassCastException: org.apache.logging.slf4j.SLF4JLoggerContext cannot be cast to org.apache.logging.log4j.core.LoggerContext

Exception in thread "main" java.lang.ClassCastException: org.apache.logging.slf4j.SLF4JLoggerContext cannot be cast to org.apache.logging.log4j.core.LoggerContext Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.Log4jLoggerFactory loaded from file:/D:/cyy/software/maven/repository/org/slf4j/slf4j- log4j12/1.7.25/slf4j-log4j12-1.7.25.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.Log4jLoggerFactory

spring自带的slf4j包跟其他自带的包冲突所产生,去除冲突的包,在pom.xml文件中添加以下相关配置即可:

org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-logging org.slf4j slf4j-log4j12 ch.qos.logback logback-classic

如果提示没有log4j包的话,再单独导包进去,如以下配置:

org.apache.logging.log4j log4j-slf4j-impl


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有