日常踩坑:idea錯誤 找不到或無法載入主類 test
阿新 • • 發佈:2021-01-16
日常踩坑:idea錯誤: 找不到或無法載入主類 test
今天在整合一個ssm專案時,寫了一個測試test卻怎麼也跑不起來一直報一個錯誤: 找不到或無法載入主類 test,上網查閱了很多資料,各種辦法沒有結果後,看到一個博主建議對比其他專案的iml檔案,果然發現了不同。
這是報錯專案的iml檔案:
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4" >
<component name="FacetManager">
<facet type="web" name="Web">
<configuration>
<descriptors>
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/web/WEB-INF/web.xml" />
</descriptors>
<webroots>
<root url="file://$MODULE_DIR$/web" relative="/" />
</webroots>
<sourceRoots>
<root url="file://$MODULE_DIR$/src/main/resources" />
<root url="file://$MODULE_DIR$/src/main/java" / >
</sourceRoots>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
這是另一個正常測試成功的專案iml檔案:
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="web" name="Web">
<configuration>
<descriptors>
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/web/WEB-INF/web.xml" />
</descriptors>
<webroots>
<root url="file://$MODULE_DIR$/web" relative="/" />
</webroots>
<sourceRoots>
<root url="file://$MODULE_DIR$/src/main/resources" />
<root url="file://$MODULE_DIR$/src/main/java" />
</sourceRoots>
</configuration>
</facet>
</component>
</module>
對比以下可以看到,出錯的檔案多了以下的程式碼塊:
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
可以看到多出來的程式碼塊開啟了一個新的許可權並將 inherit-compiler-output設定為true,相當於沒有設定專案輸出路徑。
最終解決辦法即刪除多餘的程式碼塊,重新整理Maven即可。
ref:iml與poml區別