IDEA最全的正确打包姿势—以及常常出现的运行错误
IDEA最全的正确打包姿势;IDEA怎么打包成jar;运行jar出现的各种错误;IDEA springboot怎么打包成jar;如错误: 找不到或无法加载主类 com.xxx.cn.AppApplication;Failed to configure a DataSource: 'url' attribute is .....;Exception in thread "main" java.lan
文章适合新手了解IDEA怎么正确打包。文章在编写过程中难免有疏漏和错误,欢迎大佬指出文章的不足之处;更多内容请点进👉 Lino_White 👈查看。
未来的世界充满着各式各样的数据,我们该怎么好好利用起来呢?开启正文吧~~~
IDEA分三种打包方式,接下来我们将逐一使用截图来介绍,哪一种都可以使用哟!
三种打包方式——以及出现错误的解决方法
第一种:集所有依赖包在项目中打包成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的相关配置,如下:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.2.2.RELEASE</version>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.yml</include>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.yml</include>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
</build>
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文件中添加以下相关配置即可:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!--去除打印日志-->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
如果提示没有log4j包的话,再单独导包进去,如以下配置:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</dependency>
更多推荐
所有评论(0)