我在包含带有a的类的Maven项目的根目录中的Windows shell中键入以下内容
public static void main(String [] args)
我想要运行的方法.
mvn exec:java -Dexec.mainClass ="com.spp.config.main.SqlGeneratorHarness"-e
该类存在并在该包中编译(即target/classes/com/spp/config/main/SqlGeneratorHarness.class).
我知道了...
+ Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'exec'.
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Invalid task '.mainClass=com.spp.config.main.SqlGeneratorHarness': you must specify a valid
lifecycle phase, or a goal in the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal
[INFO] ------------------------------------------------------------------------
[INFO] Trace org.apache.maven.BuildFailureException: Invalid task' .mainClass=com.spp.config.main.SqlGeneratorHarness': you must specify
a valid lifecycle phase, or a goal in the …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用maven exec插件执行一些任务.一种是运行脚本来生成应用程序将使用的一些外部数据.第二个是在编译阶段运行一大块java代码来做一些方便的工作.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>data_for_app</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${basedir}/scripts/getappdata.sh</executable>
<arguments>
<argument>${basedir}/src/main/webapp/WEB-INF/xml/appdatahere/</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>do_convenience</id>
<phase>compile</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.example.DoConvenienceStuff</mainClass>
<arguments>
<argument>https://example.com/data</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
但是当我跑步时:
mvn clean package exec:exec
Run Code Online (Sandbox Code Playgroud)
我收到错误:
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) on project jss: The parameters 'executable' for goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec are missing or invalid -> [Help 1]
Run Code Online (Sandbox Code Playgroud)
或者类似的错误说参数'mainClass'缺失或无效.
我正在使用Maven构建一个webapp项目,使用maven-failsafe-plugin进行集成测试.货物Glassfish3x容器开始绑定到预集成测试阶段,并作为集成后测试阶段的一部分停止.
但是,我的集成测试是基于pyUnit的脚本.我尝试使用exec-maven-plugin运行它们,并通过maven-bdd-plugin使用nosetests/freshen.
这两种方法都可以很好地运行脚本,但如果测试失败,它们会立即使Maven构建失败.Maven没有运行集成后测试阶段,将一个正在运行的货物集装箱放在后面,这使得任何其他尝试都无法运行测试.
如何配置maven-failsafe来解释我的失败exec是一个失败的测试,以便它完成它的工作并运行集成后测试阶段?
我尝试使用exec-maven-plugin来运行Java程序.
我使用以下pom片段:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<executable>java</executable>
<arguments>
<argument>-Dmyproperty=myvalue</argument>
<argument>-cp</argument>
<argument>"/home/vogella/libs/*"</argument>
<argument>com.vogella.test.Main</argument>
</arguments>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
该类com.vogella.test.Main包含在一个jar文件中,该文件位于/ home/vogella/libs/*中.如果我运行该mvn -X clean install exec:exec命令,我看到以下错误消息:
[DEBUG]执行命令行:java -Dmyproperty = myvalue -cp"/ home/vogella/libs/*"com.vogella.test.Main错误:无法找到或加载主类com.vogella.test.Main
如果我java -Dmyproperty=myvalue -cp "/home/vogella/libs/*" com.vogella.test.Main在我启动Maven构建的shell中复制命令行(),那么Java程序将正确执行.
知道我的Maven设置有什么问题吗?
我是Maven新手,通过Maven运行类文件时遇到问题
使用mvn exec可以正常运行
:java -Dexec.mainClass =“ com.test.Test”
但不适用于
mvn exec:exec -Dexec.executable = java -Dexec.mainClass =“ com.test.Test”
要求输入Java参数
F:\data\work\Test>mvn exec:exec -Dexec.executable=java -Dexec.mainClass="com.test.Test"
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-d32 use a 32-bit data model if available
-d64 use a 64-bit data model if available
-server to select the "server" VM
-hotspot is a synonym for the "server" VM [deprecated]
The default VM …Run Code Online (Sandbox Code Playgroud) 是否可以以某种方式并行运行多个 exec-maven-plugin 执行?
我们希望为 DAL 集成测试部署不同的数据库类型,虽然显然可以按顺序执行此操作,但这会浪费大量时间。
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>first-dbtype-deployment</id>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.example.DeployDBTypeOne</mainClass>
</configuration>
</execution>
<execution>
<id>second-dbtype-deployment</id>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.example.DeployDBTypeTwo</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</build>
Run Code Online (Sandbox Code Playgroud)
实际部署的相应配置当然更复杂,但我认为这与所涉及的特定问题无关。
我已阅读了类似问题的一些问题以及“帮助1”页面。不幸的是,我被困住了。
一个可能的原因可能是代理引起的,但是这里没有这样的代理。另外,当我从Eclipse更新它时,我PC中的所有maven项目都已成功更新。所以我放弃了这种可能性。
我检查的另一件事是在本地存储库中查找codehaus,然后找到它(C:\ Users \ myUser.m2 \ repository \ org \ codehaus \ mojo)。
另一种尝试,我尝试在设置中添加pluginGroups / pluginGroup。该项目是一个非常简单的问候词,仅使用Spring Batch和Tasklet及其execute方法。没有公共的static void main方法。
我添加了Matteo建议后,打印了整个错误的Command.exe:
C:\temp\TaskletJavaConfig\spring-batch-helloworld>mvn compile exec:java -e
Picked up JAVA_TOOL_OPTIONS: -agentlib:jvmhook
Picked up _JAVA_OPTIONS: -Xrunjvmhook -Xbootclasspath/a:C:\PROGRA~2\HP\QUICKT~1\
bin\JAVA_S~1\classes;C:\PROGRA~2\HP\QUICKT~1\bin\JAVA_S~1\classes\jasmine.jar
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/mojo/exec-maven-p
lugin/1.1/exec-maven-plugin-1.1.pom
[WARNING] Failed to retrieve plugin descriptor for org.codehaus.mojo:exec-maven-
plugin:1.1: Plugin org.codehaus.mojo:exec-maven-plugin:1.1 or one of its depende
ncies could not be resolved: Failed to read artifact descriptor for org.codehaus
.mojo:exec-maven-plugin:jar:1.1
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven
-deploy-plugin/2.7/maven-deploy-plugin-2.7.pom …Run Code Online (Sandbox Code Playgroud) 我正在使用exec-maven-plugin在maven项目中运行JavaScript单元测试
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>run-karma</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${node.bin.folder}/node</executable>
<workingDirectory>${project.basedir}</workingDirectory>
<arguments>
<argument>node_modules/karma/bin/karma</argument>
<argument>start</argument>
<argument>--single-run</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我假设如果我通过-DskipTests,将跳过整个测试阶段,但事实并非如此,只有在使用"Surefire,Failsafe和编译器插件"时才会尊重该skipTests标志.
问题:如何使执行取决于skipTests标志?
我正在制作一个使用sparql端点服务的maven应用程序.我想有一个maven目标来下载sparql端点并启动服务,但似乎maven在配置类路径时遇到一些问题.
我在https://mvnrepository.com/artifact/com.blazegraph/bigdata-jar上使用了blazegraph及其工件.
这是我在pom.xml中的插件配置:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.bigdata.rdf.sail.webapp.StandaloneNanoSparqlServer</mainClass>
<includePluginDependencies>true</includePluginDependencies>
<includeProjectDependencies>false</includeProjectDependencies>
<executableDependency>
<groupId>com.blazegraph</groupId>
<artifactId>blazegraph-jar</artifactId>
</executableDependency>
<addOutputToClasspath>false</addOutputToClasspath>
</configuration>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.blazegraph/blazegraph-jar -->
<dependency>
<groupId>com.blazegraph</groupId>
<artifactId>blazegraph-jar</artifactId>
<version>2.1.4</version>
<scope>runtime</scope>
<type>jar</type>
</dependency>
</dependencies>
</plugin>
Run Code Online (Sandbox Code Playgroud)
调试输出提示插件无法找到工件:
Caused by: java.lang.NullPointerException
at org.codehaus.mojo.exec.AbstractExecMojo.findExecutableArtifact(AbstractExecMojo.java:278)
at org.codehaus.mojo.exec.ExecJavaMojo.determineRelevantPluginDependencies(ExecJavaMojo.java:650)
at org.codehaus.mojo.exec.ExecJavaMojo.addRelevantPluginDependenciesToClasspath(ExecJavaMojo.java:568)
at org.codehaus.mojo.exec.ExecJavaMojo.getClassLoader(ExecJavaMojo.java:520)
at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:301)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
... 27 more
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
编辑1 这个问题不是什么是NullPointerException的副本,我该如何解决?因为Maven抛出异常,因为它无法在依赖项列表中找到正确的工件(但它应该).
编辑2 感谢@Sean Patrick Floyd,我已经部分解决了这个问题.我想,类路径配置中仍然存在一些问题.现在Maven找到了主类和jar,但是在执行之后我在编译代码中得到了另一个NPE.查看blazegraph的开源代码,似乎无法打开可执行jar内的资源.
以下是导致NPE的行:
System.setProperty("jetty.home",
jettyXml.getClass().getResource("/war").toExternalForm());
Run Code Online (Sandbox Code Playgroud)
classpath nullpointerexception maven-3 maven exec-maven-plugin
我正在使用 exec-maven-plugin 执行 java 应用程序以在我的项目中生成一些代码:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<mainClass>com.codegenerator.CodeGeneratorApplication</mainClass>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
如果我在命令行“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>
Run Code Online (Sandbox Code Playgroud)
但是突然当我执行“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 …Run Code Online (Sandbox Code Playgroud)