這種情況一般都是使用maven打成jar包后運行出現(xiàn)的。這種情況是因為jar包里面沒有主類路徑
解決辦法有兩個文章源自四五設(shè)計網(wǎng)-http://www.wasochina.com/44026.html
1、使用IDEA自帶的構(gòu)建jar包流程,不使用Maven打包
打開項目結(jié)構(gòu)設(shè)置文章源自四五設(shè)計網(wǎng)-http://www.wasochina.com/44026.html
文章源自四五設(shè)計網(wǎng)-http://www.wasochina.com/44026.html
新建一個打包目標工件文章源自四五設(shè)計網(wǎng)-http://www.wasochina.com/44026.html
文章源自四五設(shè)計網(wǎng)-http://www.wasochina.com/44026.html
選擇你的主類,路徑保持默認無需修改,記得選擇?提取到目標JAR?否則你的jar包需要依賴其他jar包文章源自四五設(shè)計網(wǎng)-http://www.wasochina.com/44026.html
文章源自四五設(shè)計網(wǎng)-http://www.wasochina.com/44026.html
保存后使用頂部菜單欄的構(gòu)建按鈕,選擇構(gòu)建工件文章源自四五設(shè)計網(wǎng)-http://www.wasochina.com/44026.html
文章源自四五設(shè)計網(wǎng)-http://www.wasochina.com/44026.html
選擇剛剛設(shè)置的構(gòu)建目標,等待構(gòu)建文章源自四五設(shè)計網(wǎng)-http://www.wasochina.com/44026.html
構(gòu)建完成和在out目錄下可以看見生成的jar包,路徑和maven構(gòu)建不一樣
該jar包可以直接使用 java -jar 運行,不會報錯
2、修改pom.xml文件,使用Maven打包
在pom.xml文件添加如下依賴
1 2 3 4 5 6 7 8 | < build > ???????? < plugin > ???????????? < groupId >org.springframework.boot</ groupId > ???????????? < artifactId >spring-boot-maven-plugin</ artifactId > ???????? </ plugin > ???? </ plugins > </ build > |
重新構(gòu)建maven,直接使用maven打包即可(無需指定mainclass)
到此這篇關(guān)于java運行jar包提示 “XXX中沒有主清單屬性” "找不到主類”兩種解決辦法的文章就介紹到這了


評論