【问题标题】:Exec Maven Plugin with ClassNotFoundException带有 ClassNotFoundException 的 Exec Maven 插件
【发布时间】:2018-07-10 08:39:57
【问题描述】:

我有一个多模块(模型和服务模块)的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 并生成一些样板类。

“服务”模块对“模型”模块具有 Maven 依赖关系,并且对代码生成器模块(外部应用程序)有依赖关系。

当我在“服务”模块中运行“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)我已经声明了对该模块的依赖。

【问题讨论】:

    标签: java maven exec-maven-plugin


    【解决方案1】:

    似乎一旦我使用了这个插件的另一个目标(我只是执行 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>
    

    但我不确定背后的真正原因。

    【讨论】:

      【解决方案2】:

      您可以访问this

      <executableDependency>
          <groupId>your groupId</groupId>
          <artifactId>>model</artifactId>
      </executableDependency>
      <mainClass>com.codegenerator.CodeGeneratorApplication</mainClass>
      

      【讨论】:

        猜你喜欢
        • 2017-05-11
        • 1970-01-01
        • 2015-07-29
        • 1970-01-01
        • 1970-01-01
        • 2018-02-12
        • 1970-01-01
        • 2020-07-10
        • 2013-05-30
        相关资源
        最近更新 更多