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 8818047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:00:08+00:00 2026-06-14T05:00:08+00:00

I have a modular maven project, in which two modules, BIZ and EJB contain

  • 0

I have a modular maven project, in which two modules, “BIZ” and “EJB” contain somthing like this:

//PART OF "BIZ" Module:

public interface MyInterface{

 public void foo();

}
............................................
public class ImplFactory{

public static MyInterface getInterfaceImplementation(){
MyInterface ret=null;
Class<? extends MyInterface> cl = null;
                try {
                    cl= (Class<? extends MyInterface>) Class.forName("InterfaceImpl");
                    ret= cl.newInstance();
                    }
                ....
                ret ret;
}
.......................................
public class MyClassX{

    public static void doSomethingX(){

    }
}

//PART OF "EJB" Module:

public class InterfaceImpl implements MyInterface
@EJB
private MyEJB1 ejb1;

public void  foo(){
    ejb1.doSomething();
}
........................................
@Stateless
public class MyEJB1{

    public void doSomething(){
    ...
    MyClassX.doSomethingX();
    ....
    }

}

As you see, “EJB” depends on “BIZ” as it uses MyClassX (in the truth, it uses several classes of BIZ). This is the reason why ImplFactory uses reflection to instantiate InterfaceImpl. The problem is cl.newInstance() will throw a ClassCastException as the 2 modules belong respectively to a WAR and a JAR (module “EJB” is compiled specifying type=”ejb” and using the maven ejb plugin) and use different ClassLoaders (it runs on JBoss 7). On the other hand, InterfaceImpl cannot be moved to BIZ as it needs MyEJB1 for its job and this would introduce a cyclic dependency.

So my question is: how would you solve this tricky situation (either programmatically or by changing the configuration)?
I hope you can help me! Thanks!

  • 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-06-14T05:00:10+00:00Added an answer on June 14, 2026 at 5:00 am

    You should split these dependencies a little bit more.

    Something like this would be better:

    .
    ├── pom.xml
    ├── my-api ("API")
    |   ├── pom.xml
    |   └── src
    |       └── main
    |           └── java
    |               └── my
    |                   └── package
    |                       └── MyInterface.java
    ├── my-ejb ("EJB")
    |   ├── pom.xml
    |   └── src
    |       └── main
    |           └── java
    |               └── my
    |                   └── package
    |                       └── InterfaceImpl.java
    └── my-web ("BIZ")
        ├── pom.xml
        └── src
            └── main
                ├── java
                |   └── my
                |       └── package
                |           └── ImplFactory.java
                └── webapp
                    └── WEB-INF
                        └── web.xml
    

    BIZ would depend on EJB that depends on API.

    Now this will solve your immediate problem but I would not recommend you to create those factories, you should use CDI instead but that’s is a different story.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a modular project in which, for every single module, I use jaxb2-maven-plugin
I am using modular MVC with codeigniter. I have a module playlist in which
I have created a modular application. I have two modules, for example Module1 and
I have a really modular application in which modules interact with each other for
I am have modular structure in my project --application ----modules -----admin ------models -----client ------models
We have a modular site and would like to setup searching by module. For
If you have a modular applicaiton that depends on its modules to be in
I'm working with a MVC modular structure, kind of like you can have with
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=

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.