使用 exec-maven-plugin 到 Maven 阶段
Using exec-maven-plugin to a maven phase
我正在使用 exec-maven-plugin 执行 java 应用程序以在我的项目中生成一些代码:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<mainClass>com.codegenerator.CodeGeneratorApplication</mainClass>
</configuration>
</plugin>
如果我在命令行 "mvn exec:java" 中执行,这工作正常,但现在我想将此代码生成附加到 Maven 阶段 "generate-resources",所以我将 pom 更改为:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>codegeneration</id>
<phase>generate-resources</phase>
<goals><goal>java</goal></goals>
</execution>
</executions>
<configuration>
<mainClass>com.codegenerator.CodeGeneratorApplication</mainClass>
</configuration>
</plugin>
但是当我执行 "mvn exec:java" 时,突然出现如下错误:
[09:52:03.926] [] [] [com.codegenerator.CodeGeneratorApplication.main()] [WARN ] [AbstractApplicationContext.java:550] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'codeGeneratorApplication': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'cnp.application.acronym' in value "${cnp.application.acronym}"
[09:52:03.940] [] [] [com.codegenerator.CodeGeneratorApplication.main()] [INFO ] [DirectJDKLog.java:179] - Stopping service Tomcat
[09:52:03.982] [] [] [com.codegenerator.CodeGeneratorApplication.main()] [INFO ] [AutoConfigurationReportLoggingInitializer.java:101] -
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
[09:52:03.987] [] [] [com.codegenerator.CodeGeneratorApplication.main()] [ERROR] [SpringApplication.java:815] - Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'codeGeneratorApplication': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'cnp.application.acronym' in value "${cnp.application.acronym}"
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:372)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
at com.codegenerator.CodeGeneratorApplication.main(CodeGeneratorApplication.java:26)
谁能帮我看看哪里出了问题?谢谢!
您的 'configuration' 元素需要位于 'execution' 元素内。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>codegeneration</id>
<phase>generate-resources</phase>
<goals><goal>java</goal></goals>
<configuration>
<mainClass>com.codegenerator.CodeGeneratorApplication</mainClass>
</configuration>
</execution>
</executions>
</plugin>
我正在使用 exec-maven-plugin 执行 java 应用程序以在我的项目中生成一些代码:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<mainClass>com.codegenerator.CodeGeneratorApplication</mainClass>
</configuration>
</plugin>
如果我在命令行 "mvn exec:java" 中执行,这工作正常,但现在我想将此代码生成附加到 Maven 阶段 "generate-resources",所以我将 pom 更改为:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>codegeneration</id>
<phase>generate-resources</phase>
<goals><goal>java</goal></goals>
</execution>
</executions>
<configuration>
<mainClass>com.codegenerator.CodeGeneratorApplication</mainClass>
</configuration>
</plugin>
但是当我执行 "mvn exec:java" 时,突然出现如下错误:
[09:52:03.926] [] [] [com.codegenerator.CodeGeneratorApplication.main()] [WARN ] [AbstractApplicationContext.java:550] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'codeGeneratorApplication': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'cnp.application.acronym' in value "${cnp.application.acronym}"
[09:52:03.940] [] [] [com.codegenerator.CodeGeneratorApplication.main()] [INFO ] [DirectJDKLog.java:179] - Stopping service Tomcat
[09:52:03.982] [] [] [com.codegenerator.CodeGeneratorApplication.main()] [INFO ] [AutoConfigurationReportLoggingInitializer.java:101] -
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
[09:52:03.987] [] [] [com.codegenerator.CodeGeneratorApplication.main()] [ERROR] [SpringApplication.java:815] - Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'codeGeneratorApplication': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'cnp.application.acronym' in value "${cnp.application.acronym}"
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:372)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
at com.codegenerator.CodeGeneratorApplication.main(CodeGeneratorApplication.java:26)
谁能帮我看看哪里出了问题?谢谢!
您的 'configuration' 元素需要位于 'execution' 元素内。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>codegeneration</id>
<phase>generate-resources</phase>
<goals><goal>java</goal></goals>
<configuration>
<mainClass>com.codegenerator.CodeGeneratorApplication</mainClass>
</configuration>
</execution>
</executions>
</plugin>