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