IDEA打包jar-解决找不到或无法加载主类 main的问题
作者:Pro+Hacker 时间:2021-12-28 10:30:42
学习大佬们开发安全小工具,打包jar解决错误: 找不到或无法加载主类 main
1 Maven方式
遇到报错”找不到或无法加载主类 main“
解决方案
一定加入<build> <plugins>中的插件,这里需要注意的是
<mainClass>Main</mainClass>,这里填写的路径为/src/main/java下开始写的
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>groupId</groupId>
<artifactId>code</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>net.dongliu</groupId>
<artifactId>requests</artifactId>
<version>5.0.8</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>Main</mainClass> <!-- 此处为主入口-->
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
重新编译
java -jar jar包路径
2 IDEA build模式
补充知识:java:关于已经编译成功生成class文件,却报错找不到
环境:Windows10、jdk-12.0.1
使用terminal编译执行,
.java文件compiler成为.class文件,然后就死活报错说找不到类
解决方法:
1、修改环境变量CLASSPATH (没有解决问题)
.;%JAVA_HOME%
//前面加一个英语句号代表当前文件,和后面的lib用个分号隔开
2、删除你的CLASSPATH变量(解决问题)
直接删除后,瞬间解决问题
来源:https://blog.csdn.net/qq_38376348/article/details/106893167
标签:IDEA,打包jar,主类,main
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
C#多线程中的互斥锁Mutex
2022-04-26 06:11:55
![](https://img.aspxhome.com/file/2023/5/69225_0s.png)
SpringCloud服务实现同时使用eureka和nacos方法
2022-01-14 13:58:57
![](https://img.aspxhome.com/file/2023/6/70346_0s.png)
详解Java中的ThreadLocal
2022-08-19 17:48:43
![](https://img.aspxhome.com/file/2023/0/99890_0s.png)
Android之Viewpager+Fragment实现懒加载示例
2021-06-30 04:36:20
一篇超详细的Spring Boot整合Mybatis文章
2022-01-27 10:02:58
![](https://img.aspxhome.com/file/2023/3/72313_0s.jpg)
Spring IOC基于注解启动示例详析
2022-04-19 22:49:55
![](https://img.aspxhome.com/file/2023/9/87219_0s.jpg)
C# 实现QQ式截图功能实例代码
2022-04-04 03:48:12
![](https://img.aspxhome.com/file/2023/2/89782_0s.png)
基于C语言实现静态通讯录的示例代码
2023-07-02 22:07:38
![](https://img.aspxhome.com/file/2023/2/103102_0s.gif)
Springboot实现多服务器session共享
2022-09-06 13:58:34
![](https://img.aspxhome.com/file/2023/8/88188_0s.png)
Android中Socket大文件断点上传示例
2022-07-11 02:33:32
![](https://img.aspxhome.com/file/2023/9/117139_0s.jpg)
基于request获取访问者真实IP代码示例
2023-02-15 02:45:13
C#使用CefSharp实现内嵌网页详解
2022-04-12 15:02:00
![](https://img.aspxhome.com/file/2023/0/80110_0s.gif)
解决@JsonInclude(JsonInclude.Include.NON_NULL)不起作用问题
2023-05-26 08:57:45
![](https://img.aspxhome.com/file/2023/0/67470_0s.png)
Java实现将PDF转为PDF/A
2023-03-16 00:54:22
![](https://img.aspxhome.com/file/2023/0/116820_0s.jpg)
Android应用开发SharedPreferences存储数据的使用方法
2023-06-23 16:02:47
![](https://img.aspxhome.com/file/2023/0/82410_0s.jpg)
Ubuntu安装jdk8常用方法流程解析
2021-12-21 13:40:04
Java 获取当前时间及实现时间倒计时功能【推荐】
2022-08-21 16:08:27
![](https://img.aspxhome.com/file/2023/7/75657_0s.png)
Java虚拟机内存区域划分详解
2023-06-20 22:04:24
![](https://img.aspxhome.com/file/2023/6/57516_0s.png)
Java中this,static,final,const用法详解
2022-01-23 17:21:41
Spring中Bean扫描原理详情
2022-05-26 04:33:14
![](https://img.aspxhome.com/file/2023/8/75488_0s.png)