Working with Identical Package Names in Maven/Netbeans

Posted on 2011-10-05
Last Modified: 2012-06-27
Dear Experts:

I have a maven project with three modules:
1) BL or my business layer stuff which is all new
2) OVERRIDE for stuff I want to modified from my original software
3) CORE the original stuff.

                                      |      BL     |
                                   /                    \
                                 /                       \
   ------------------------/                          \-------------------
   |    OVERRIDE      |                           |   CORE      |
   -------------------------                           --------------------


I have the same exact class stored in both the OVERRIDE and CORE
(where my core stuff in a jar file called core.jar) modules

These identical classes are a package as follows:

package name and files --->

In these packages I have a class called BuildForm

so in OVERRIDE/CORE modules I have

But in my override module I added a method called "getPreferredSize(window)" to class
BuildForm. The "getPreferredSize" method does not exist in my original core module.


Also in the  OVERRIDE package I have another class "" that calls
"getPreferredSize(window)" from the BuildForm class.

This method exist in my OVERRIDE module but not my original CORE module.

Netbeans tells me it cannot find the getPreferredSize. It exist in the same package. But Netbeans is looking at my original CORE module where the class "" does not have this module.

Attached is my pom.xml


 in a classpath way, If I want my class to be used first instead of another class I place "First" in the class path.

I cannot get this to work with my Netbeans Maven Project.

Any recommendations would be appreciated
Summary:. In Java or Maven, how do you tell your Maven Builder to use Class A first instead of Class B? When class A and B are named the same?

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=""


    <name>core overrides</name>


                        <outputDirectory>${}/../mohave BL/packages</outputDirectory>


Open in new window

Question by:Cedarville
    LVL 47

    Accepted Solution


    check here about Maven classpath order:

    MNG-1412 / MNG-3111 introduced deterministic ordering of dependencies on the classpath. In the past, natural set ordering was used and this lead to odd results. The ordering is now preserved from your pom, with dependencies added by inheritence added last. In builds that had conflicting or duplicate dependencies, this may introduce a change to the output. In short, if you have weird issues with 2.0.9, take a look at the dependencies to see if you have conflicts somewhere.
    LVL 47

    Expert Comment

    So why can't you put your overriding classes first in the classpath ?

    Author Comment

    Dear Yan:

    I'll check out your link. Yes, I can run my project correctly if I set the classpath. But I want to run in Netbeans. Here's the funny thing;

    If I "debug break" in my coreover class I get the following error in netbeans:

    Not able to submit breakpoint LineBreakpoint : 192, reason: Breakpoint's source file does not belong into the preferred source root 'D:\netbeans\14sep2011\core\mohave\src\main\java'. See Window/Debugging/Sources.
    Invalid LineBreakpoint : 192

    Netbeans is just not looking at my module.  Even though Netbeans will let me build this module.

    I'll check out the link you sent  and see what I learn.

    LVL 47

    Assisted Solution

    In NetBeans I'd think you certainly cannot have two versions of the source code of the same class.
    You can make jar file or say a special folder with only classes of your older files and I hope you can put this folder with old classes
    as an external dependency. It should still take the classes generated from your code ar first thing and those which you didn't touch and where you don't have the code it should take form the old stuff - this is my guess, at least.
    LVL 10

    Assisted Solution

    Generally the way you would accomplish what you want is by extending the base classes to add new functionality, then configuring the application to use your extended class instead of the original.  Generally, building an application that depends on the order JARs are specified in the classpath is a bad idea.  I don't believe (and I might be wrong -- haven't looked at the JLS in a while) that it is mandated for a JDK to include JARs based on command-line ordering and different vendors may implement conflict resolution in multiple ways.

    Completely understand that you may have to do things this way because the rest of the code is not configurable, but you're building your application to fail unexpectedly at some point in the future.

    Author Comment

    For_yan, thank you for the link, it had interesting information.

    Gordon, I agree with your statements; I'm trying to do things with module order dependency because my co-workers do this in IntelliJ. I feel like if I knew more I could do this in either Maven or Netbeans as well.

    But yes, it is a bad practice.


    Author Closing Comment

    I got a lot of great comments and pointers. Unfortunately, these were helpful but did not solve my question.

    I will do further research. I want to force Maven and Netbeans to honor classpath order; regardless if best practice.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Suggested Solutions

    How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from ( Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
    Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
    This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now