简体   繁体   中英

Using classes from target/test-classes

I am a newbie to 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 . 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 ... .

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.

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.

Thanks in Advance.

You can add a secondary execution of the maven-jar-plugin that builds a test jar from your project:

  <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.

More details can be found at Create test JAR .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM