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

The Archive Base Latest Questions

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

I would like JBoss to use only the dependencies located in my war file.

  • 0

I would like JBoss to use only the dependencies located in my war file.
Each time I deploy this war file, JBoss still uses its own jars.

Here is the jboss-web.xml I use :

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
    <class-loading java2ClassLoadingCompliance="false">
        <loader-repository>
            my.package:loader=my-app.war
           <loader-repository-config>
              java2ParentDelegation=false
           </loader-repository-config>
        </loader-repository>
    </class-loading>
</jboss-web>

and the jboss-classloading.xml :

<?xml version="1.0" encoding="UTF-8"?>
<classloading 
    xmlns="urn:jboss:classloading:1.0"
    export-all="NON_EMPTY"
    import-all="true"
    parent-first="false"/>

JBoss 5.1.0.GA

  • 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-27T12:23:34+00:00Added an answer on May 27, 2026 at 12:23 pm

    1> SUMMARY

    Initially, I have tried this class loading isolation for loading Hibernate 3.6.4 jars with JBoss 5.1.0.GA.

    It’s definitively NOT possible. There is some magic under the hood that prevents you from using any Hibernate version with JPA2 support.

    I’m really disappointed that JBoss project didn’t provide some kind of patch or service pack for supporting JPA2 on 5.1.0.GA.

    2> WORKAROUND : “The Kernel solution”
    I have managed to use JPA2 with JBoss 5.1.0.GA
    I describe here my recipe. It’s more a proof of concept you can use to make your own solution.

    Ingredients :

    • 1 WAR archive
    • 1 servlet
    • 1 standalone java application (J2SE)

    Recipe :

    Step 1: Build the standalone application (APP)

    This application will receive instructions from the servlet for using Hibernate.

    I leave you the choice of the communication method.
    As the APP uses JPA2, it will need a persistence.xml file located in a META-INF folder.
    Since JBoss 5.x, when you deploy a WAR, JBoss will scan the WAR and all its sub-deployments for finding and deploying blindly persistence.xml files. Rename your persistence.xml file into my-persistence.xml for example. Use the code below when you build your EntityManagerFactory (Prevent JBoss from deploying persistence.xml).

    UPDATE:
    This method does work but some strange warnings are raised by Hibernate. In order to stop those warnings, I have decided to put the META-INF folder and the persistence file (renamed back to persistence.xml now) outside of the WAR. In my case, I choosed a special config folder on the hard drive and added it to the classpath. No more strange warnings and no custom classloader required for loading the persistence file.

    I leave it up to you to choose between using a custom class loader or changing the persistence file location. In both cases, JBoss won’t find the persistence file.

    Step 2: Build the servlet

    When the servlet needs to access the database, it launches the APP and tells it what to do.

    For lauching the APP, the servlet is responsible of spawning a new JVM and build the classpath of the APP. Read the code below for (Spawning a JVM). The classpath is easily buildable since all the required jars will be in the /lib directory of the WAR archive…

    Step 3: Build the WAR archive

    Build a WAR archive where you put the servlet and the standalone application packaged as a JAR. The APP will be a dependency of the WAR.


    Prevent JBoss from deploying persistence.xml

    // Install a proxy class loader for adding renamed persistence.xml file
    Thread t = Thread.currentThread();
    ClassLoader clOriginal = t.getContextClassLoader();
    t.setContextClassLoader(new SpecialClassLoader(clOriginal, "META-INF/my-persistence.xml"));
    
    // Build EntityManagerFactory
    EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnitName);
    
    // Restore original class loader
    t.setContextClassLoader(clOriginal);
    
    //...
    
    private class ProxyClassLoader extends ClassLoader {
        private ClassLoader realClassLoader;
        private String hiddenFromJBossPersistenceFile;
    
        public ProxyClassLoader(ClassLoader realClassLoader, String hiddenFromJBossPersistenceFile) {
            this.realClassLoader = realClassLoader;
            this.hiddenFromJBossPersistenceFile = hiddenFromJBossPersistenceFile;
        }
    
        public void clearAssertionStatus() {
            realClassLoader.clearAssertionStatus();
        }
    
        public boolean equals(Object obj) {
            return realClassLoader.equals(obj);
        }
    
        public URL getResource(String name) {
            return realClassLoader.getResource(name);
        }
    
        public InputStream getResourceAsStream(String name) {
            return realClassLoader.getResourceAsStream(name);
        }
    
        public Enumeration<URL> getResources(String name) throws IOException {
            ArrayList<URL> resources = new ArrayList<URL>();
    
            if (name.equalsIgnoreCase("META-INF/persistence.xml")) {
                resources.add(getResource(this.hiddenFromJBossPersistenceFile));
            }
            resources.addAll(Collections.list(realClassLoader.getResources(name)));
    
            return Collections.enumeration(resources);
        }
    
        public int hashCode() {
            return realClassLoader.hashCode();
        }
    
        public Class<?> loadClass(String name) throws ClassNotFoundException {
            return realClassLoader.loadClass(name);
        }
    
        public void setClassAssertionStatus(String className, boolean enabled) {
            realClassLoader.setClassAssertionStatus(className, enabled);
        }
    
        public void setDefaultAssertionStatus(boolean enabled) {
            realClassLoader.setDefaultAssertionStatus(enabled);
        }
    
        public void setPackageAssertionStatus(String packageName, boolean enabled) {
            realClassLoader.setPackageAssertionStatus(packageName, enabled);
        }
    
        public String toString() {
            return realClassLoader.toString();
        }
    }
    

    Spawning a JVM

    public static Process createProcess(final String optionsAsString, final String workingDir, final String mainClass, final String[] arguments) throws IOException {
        String jvm = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
    
        String[] options = optionsAsString.split(" ");
        List<String> command = new ArrayList<String>();
        command.add(jvm);
        command.addAll(Arrays.asList(options));
        command.add(mainClass);
        command.addAll(Arrays.asList(arguments));
    
        //System.out.println(command);
    
        ProcessBuilder processBuilder = new ProcessBuilder(command);
        processBuilder.directory(new File(workingDir));
    
        return processBuilder.start();
    }
    
    public static void makeItRun() {
       try {
          // Start JVM
          String classPath = buildClassPath();
          String workingDir = getSuitableWorkingDir();//or just "."
          Process java = createProcess("-cp \"" + classPath + "\"", workingDir, my.package.APP.class.getCanonicalName(), "-the -options -of -my -APP");
    
          // Communicate with your APP here ...
    
          // Stop JVM
          java.destroy();
       } catch(Throwable t) {
          t.printStackTrace();
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For tests of some small JBoss enterprise apps I would like to use JUnit,
I use sl4j-api 1.7.2 with slf4j-log4j12. I would like to log something like this:
My goal is to install only one WAR file but to use test or
I would like to specify file paths using the JBoss provided substitutions, e.g. ${jboss.server.log.dir}.
I would like to configure JBoss 4.2.x to utilize the JBoss Web Native Connectors
We are using JBoss 4.2. We would like to customize the session id which
Would like to parse IPv4 address from exit-addresses . Format of the file: ExitNode
I use the JAXBContext.newInstance operation in my JBoss based web application. This operation, as
I'm migrating my apps from WebSphere to JBoss. I would like to know if
I would like to use JPA2 Criteria API with metamodel objects, which seems to

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.