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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:21:26+00:00 2026-06-14T10:21:26+00:00

When a web application is loaded in Tomcat it is loaded by a specific

  • 0

When a web application is loaded in Tomcat it is loaded by a specific classloader, right?
I assume that all libraries (under WEB-INF\lib) used by this web application are all loaded by this same classloader?
In this case, is there a way to load a library under a different classloader without any issues?
The reason I want to do this is because Axis uses some configuration properties that are bound to the classloader and would like to do requests with different properties thereby use a different classloader.
Is this possible?

  • 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-14T10:21:27+00:00Added an answer on June 14, 2026 at 10:21 am

    If you want to load classes programmatically at run time, you can use URLClassLoader, but it can be quite tricky to really get it right. You would do something like this:

    URL[] urls = new URL[] {
        /* URL to your axis jar */,
        /* other URLs you need */
    };
    URLClassLoader classLoader = new URLClassLoader(urls, getClass().getClassLoader());
    Class<...> axisClass = classLoader.findClass(/* fully qualified name */);
    

    Then you should be able to create a new instance of this class and use it.

    Edit: Here is a more concrete example, albeit not using Axis because it would be too difficult to set up. I have create a JAR file that contains the following class:

    public class Hello {
        public Hello(String config) {
    
        }
    
        public String getMessage() {
            return "Hello World";
        }
    }
    

    I have copied this jar file to the source folder of my test project, so I can find it using UrlClassloaderTest.class.getResource("hello.jar"). In a web app, you should probably put it into WebContent/WEB-INF (or something similar) and use the method javax.servlet.ServletContext.getRealPath("WEB-INF/hello.jar") to find it. I can then access the Hello class using the URLClassLoader and reflection:

    public class UrlClassloaderTest {
        public static void main(String[] args) throws Exception {
            URL jarUrl = UrlClassloaderTest.class.getResource("hello.jar");
            URLClassLoader cl = new URLClassLoader(new URL[] { jarUrl }, UrlClassloaderTest.class.getClassLoader());
    
            Class helloClass = cl.loadClass("test.Hello");
            Constructor constructor = helloClass.getConstructor(String.class);
            Object helloObject = constructor.newInstance("some configuration");
            Method messageMethod = helloClass.getMethod("getMessage");
            String message = (String) messageMethod.invoke(helloObject);
    
            System.out.println(message);
        }
    }
    

    Note that I can not use Hello as a type here because it is not on the class path of the application, and so it is not known to the class loader of the class UrlClassLoaderTest!

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

Sidebar

Related Questions

We're running a small web application written JRuby on Rails running under Tomcat. We're
I've got a Tomcat 5.5 web application that uses the Apache Commons-Configuration library to
I'm trying to deploy an application on tomcat 7.0.23 (the web app is all
I have a Spring Web application with an applicationContext.xml loaded through a ContextLoaderListener in
I'm developing a web application on Apache Tomcat 6 with Hibernate and Spring, I'm
I am running a web application using Tomcat and Java Servlets, JSP's, etc. I
I am writing a web application with Struts 3 using Tomcat 7 with Eclipse.
We have a web application running on Tomcat 7 and it loads a JNI
I'm trying to deploy an web application on tomcat server fronted with Nginx. The
I have a web application on tomcat. The application needs two SAXParserFactory implements: one

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.