[英]How to run a class as a jar file trough maven with antrun plugin
I have the following plugin configuration in my maven pom.xml 我的Maven pom.xml中有以下插件配置
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>prepare-database</id>
<phase>pre-integration-test</phase>
<configuration>
<target name="run">
<java fork="false" failonerror="yes" classname="Test">
<arg line="arg1 arg2"/>
</java>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
The class is located in a package under src/main/java the package is called com.ab and the class file is called Test.java 该类位于src / main / java下的包中,该包称为com.ab,而类文件称为Test.java
package com.a.b;
public class Test {
public static void main(String[] args)
{
String arg1 = args[0];
String arg2 = args[1];
doStuff(arg1, arg2);
}
public static void doStuff(String arg1, String arg2)
{
System.out.println(arg1);
}
}
When trying to execute the maven build that runs the ant task I get the following error: 尝试执行运行ant任务的Maven构建时,出现以下错误:
An Ant BuildException has occured: Could not find Test. 发生Ant BuildException:找不到测试。 Make sure you have it in your classpath 确保在类路径中有它
I understand that the file can not be found but I have no clue what to do about it. 我了解找不到该文件,但是我不知道该怎么做。 Any help would be highly appreciated. 任何帮助将不胜感激。
Take a look at the standard-directory-layout article on the Maven site. 看一下Maven网站上的standard-directory-layout文章。
Source folder should be src/main/java (and not src/java/main) 源文件夹应该是src / main / java(而不是src / java / main)
Also, what exactly do you want to do with this ant target ? 另外,您到底想对这个蚂蚁目标做什么? Do you simply need the fork ? 您只需要叉子吗? Why can't you run it as a pure unit test, or a maven integration test and forget about the ANT target ? 为什么不能将其作为纯单元测试或Maven集成测试运行,而忘记了ANT目标?
H2 is well-suited for running in-memory. H2非常适合在内存中运行。 It only takes a couple of lines to connect to the DB and start testing, all inside the JVM, all using standard jUnit code. 只需几行就可以连接到DB并开始测试,所有这些都在JVM内,并且全部使用标准jUnit代码。
Class.forName("org.h2.Driver");
Connection con = DriverManager.getConnection("jdbc:h2:mem:mytest", "sa", "");
Statement sst = con.createStatement();
sst.executeUpdate(SQL);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.