• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 738
  • Last Modified:

Working with Identical Package Names in Maven/Netbeans

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 ---> com.mohave.property.form

In these packages I have a class called BuildForm

so in OVERRIDE/CORE modules I have com.mohave.property.form.BuildForm.

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 "com.mohave.property.form.Default" 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 "com.mohave.property.form.BuildForm" 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="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">


    <name>core overrides</name>


                        <outputDirectory>${project.build.directory}/../mohave BL/packages</outputDirectory>


Open in new window

  • 3
  • 3
3 Solutions

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.
So why can't you put your overriding classes first in the classpath ?
CedarvilleAuthor Commented:
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 BuildForm.java : 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 BuildForm.java : 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.

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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.
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.
CedarvilleAuthor Commented:
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.

CedarvilleAuthor Commented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now