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

  • SEARCH
  • Home
  • 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

On a current project I'm using a helper class to make API calls, which
As part of my current project I've been tasked with collecting URL's for various
in my current project I'm using code first approach. I have a type called
My current programming project is a sort of french dictionary in Java (using sqlite).
As a part of my current pet project, I have to write an program
I've come across a place in my current project where I have created several
I am using com.sun.net.httpserver.HttpsServer in my current project which deals with client-authentification etc.. Currently
My current Hibernate project is having some mapping problems. But first of all, I'll
I created a FlowDocument.xaml in my current WPF project. What i want to do
As part of my current project I am required to download images from 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.