Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 357477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:12:33+00:00 2026-05-12T12:12:33+00:00

As part of my current project I’ve created a custom class loader. Part of

  • 0

As part of my current project I’ve created a custom class loader. Part of the unit tests for the custom loader involves using some JAR files to demonstrate the proper behavior of the loader.

I’d like to build the test JAR files from Java sources ahead of running the actual unit tests. Further, the test JAR files cannot be on the class path when the unit tests are run, since I want to dynamically load them during the test execution.

Is there a standard pattern for accomplishing this sort of “build some JARs on the side before the test phase but leave them out of the class path” requirement? I can’t believe I’m the first person to try doing this with Maven 2, but I can’t seem to hit on the right POM structure and dependencies. Usually I end up with some of the test jars not being built ahead of the test phase, but I’ve also had problems with inconsistent order-of-build causing the build to work properly on one machine, but fail to build some of the test jars on another.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T12:12:33+00:00Added an answer on May 12, 2026 at 12:12 pm

    The simplest thing to do is to set up another project to package the classes for your test jar, then set that as a normal test-scoped dependency.

    If you don’t want/aren’t able to do that, you can use the assembly plugin to create a jar in the process-test-classes phase (i.e. after the tests have been compiled but before the tests are executed). The configuration below will invoke the assembly plugin to create a jar called classloader-test-deps in that phase in the target directory. Your tests can then use that jar as needed.

    The assembly plugin uses an assembly descriptor (in src/main/assembly, called test-assembly.xml) that packages the contents of target/test-classes. I’ve set up a filter to include the contents of com.test package and its children. This assumes you have some package name convention you can apply for the contents of the jar.

    The assembly plugin will by default attach the jar as an additional artifact, by specifying attach as false, it will not be installed/deployed.

    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <version>2.2-beta-2</version>
      <executions>
        <execution>
          <id>create-test-dependency</id>
          <phase>process-test-classes</phase>
          <goals>
            <goal>single</goal>
          </goals>
          <configuration>
            <finalName>classloader-test-deps</finalName>
            <attach>false</attach>
            <descriptors>
              <descriptor>src/main/assembly/test-assembly.xml</descriptor>
            </descriptors>
          </configuration>
        </execution>
      </executions>
    </plugin>
    

    This is the content of test-assembly.xml

    <assembly>
      <id>test-classloader</id>
      <formats>
        <format>jar</format>
      </formats>
      <includeBaseDirectory>false</includeBaseDirectory>
      <fileSets>
        <fileSet>
          <directory>${project.build.testOutputDirectory}</directory>
          <outputDirectory>/</outputDirectory>
          <!--modify/add include to match your package(s) -->
          <includes>
            <include>com/test/**</include>
          </includes>
        </fileSet>
      </fileSets>
    </assembly>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As part of my current project I am required to download images from a
I've finished my current part-time project and am looking for something new. I've decided
In the current project I am working in, someone decided that binary files be
In my current project I noticed that all class fields and variable inside methods
As part of our current database work, we are looking at a dealing with
This is actually a two part question. First,does the HttpContext.Current correspond to the current
Part of a new product I have been assigned to work on involves server-side
Part of the install for an app I am responsible for, compiles some C
Part of the series of controls I am working on obviously involves me lumping
My current project is broken down into 3 parts: Website, Desktop Client, and a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.