Q開頭的類找不到,無法加載插件:com.mysema.maven:apt-maven-plugin


http://www.jspxcms.com/documentation/297.html

 

如果出現無法加載com.mysema.maven:apt-maven-plugin插件的情況,通常是由於maven插件倉庫的問題。所有Q開頭的類(如QInfo、QNode、QVoteMark等)找不到,都是由於這個問題導致。Q開頭的類式QueryDSL生成的用於查詢的類,位於src/generated-sources/java。由於src/generated-sources/java並不是默認的源碼路徑,如果com.mysema.maven:apt-maven-plugin插件沒有正常加載,這個路徑下的源碼不會被識別,從而出現找不到類的情況;如果該插件正常加載,則會自動把src/generated-sources/java作為源碼路徑,一切都將正常工作。

錯誤信息通常為:

Execution default of goal com.mysema.maven:apt-maven-plugin:1.1.3:process failed: Unable to load the mojo 'process' (or one of its required components) from the plugin 'com.mysema.maven:apt-maven-plugin:1.1.3' (com.mysema.maven:apt-maven-plugin:1.1.3:process:default:generate-sources) 

由於maven依賴包倉庫和maven插件倉庫的配置並不是同一個地方,很容易被忽略。maven依賴包倉庫通過mirror配置,而maven插件倉庫則通過profile的pluginRepository配置。

完整配置如下:

<?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <!--<localRepository>D:/repositories/maven</localRepository>--> <pluginGroups></pluginGroups> <proxies></proxies> <servers></servers> <mirrors> <mirror> <id>central</id> <mirrorOf>*</mirrorOf> <name>Nexus Aliyun</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> </mirror> </mirrors> <!-- 注意:以下配置用於指定Maven插件的倉庫,不能省略,否則可能出現無法加載Maven插件的問題(如:`com.mysema.maven:apt-maven-plugin`) --> <profiles> <profile> <id>nexus</id> <repositories> <repository> <id>nexus-repo</id> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus-repo</id> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <activeProfile>nexus</activeProfile> </activeProfiles> </settings> 

修改完配置后,需要在eclipse里面重新加載maven配置Window -> Preferences -> Maven -> User Settings點擊Update settings,最好再重啟一下eclipse,然后右擊項目名 - Maven - Update Project更新項目。

如果使用IDEA開發工具,還需要打開View -> Tool Windows -> Maven Projects,點擊Generate Sources and Update Folders For All Projects

如果實在無法解決這個問題,還有一個更暴力的方式,在pom.xml文件中刪除com.mysema.maven:apt-maven-plugin配置:

<plugin> <groupId>com.mysema.maven</groupId> <artifactId>apt-maven-plugin</artifactId> </plugin> 

然后將src/generated-sources/java目錄的文件全部拷貝至src/main/java目錄中。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM