[英]Using classes from target/test-classes
I am a newbie to Java/Maven. 我是Java / Maven的新手。 I have a standard maven project structure, and I've written some helper classes that I want to use in some testing scripts, and those classes are in the
src/test/java
. 我有一个标准的maven项目结构,并且编写了一些要在某些测试脚本中使用的帮助程序类,这些类在
src/test/java
。 After I do mvn clean install
, I can see that those classes are in target/test-classes
, but in my script although I use the absolute path to the target
directory in my CLASSPATH
, I am seeing a Could not find or load main class ...
. 在执行
mvn clean install
,我可以看到那些类位于target/test-classes
,但是在我的脚本中,尽管我在CLASSPATH
使用了指向target
目录的绝对路径,但是却看到Could not find or load main class ...
For instance, I have src/test/java/validation/CrossValidator.java
, and in my script I am using java -cp $CLASSPATH validation.CrossValidator ...
, where CLASSPATH
is the absolute path to target
directory. 例如,我有
src/test/java/validation/CrossValidator.java
,在我的脚本中,我使用java -cp $CLASSPATH validation.CrossValidator ...
,其中CLASSPATH
是target
目录的绝对路径。
Anyone can guide me to accomplish this? 任何人都可以指导我完成此任务吗? I know that I can simply move those classes to
src/java/main
, but I don't want those classes to be part of the library jar
, since they're not used at runtime. 我知道我可以将这些类简单地移动到
src/java/main
,但是我不希望这些类成为库jar
一部分,因为它们在运行时未使用。
Thanks in Advance. 提前致谢。
You can add a secondary execution of the maven-jar-plugin that builds a test jar from your project: 您可以添加maven-jar-plugin的辅助执行,以从您的项目中构建测试jar:
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
This will create a jar with a classifier of test-jar
that contains all of your test classes. 这将创建一个带有
test-jar
分类器的test-jar
,其中包含所有测试类。
More details can be found at Create test JAR . 可以在创建测试JAR中找到更多详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.