我有一个多模块(模型和服务模块) maven项目:
model
|_____ABCEntity.java
service
|_____pom.xml
<dependency>model</dependency>
<dependency>code-generation</dependency>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<mainClass>com.codegenerator.CodeGeneratorApplication</mainClass>
</configuration>
</plugin>在“模型”模块中,我有一个类名为ABCEntity.java,在服务模块中,我想扫描ABCEntity.java并生成一些样板类。
"service“模块具有对"model”模块的maven依赖,以及对代码生成器模块(外部应用程序)的依赖。
当我在"service“模块中运行"mvn exec:java”时,我得到了一些错误,没有找到ABCEntity.java:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:294)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: Failed to execute ApplicationRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:770)
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:757)
at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:747)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
at codegenerator.CodeGeneratorApplication.main(CodeGeneratorApplication.java:26)
... 6 more
Caused by: java.lang.ClassNotFoundException: ABCEntity有人能帮我这个忙吗?我不明白为什么找不到ABCEntity,因为: 1)ABCEntity在同一个项目中,但在另一个模块中2)我已经声明了该模块的依赖关系。
发布于 2018-01-31 20:45:32
似乎一旦我使用了这个插件的另一个目标(我只需执行mvn exec:exec),就可以找到ABCEntity:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<!-- automatically creates the classpath using all project dependencies,
also adding the project build directory -->
<classpath />
<argument>codegenerator.CodeGeneratorApplication</argument>
...
</arguments>
</configuration>
</plugin>但我不确定背后的真正原因。
发布于 2018-01-31 18:14:57
你可以访问this
<executableDependency>
<groupId>your groupId</groupId>
<artifactId>>model</artifactId>
</executableDependency>
<mainClass>com.codegenerator.CodeGeneratorApplication</mainClass>https://stackoverflow.com/questions/48538743
复制相似问题