Override Class loader “Parent First”












1















I have Java web application running on a web application server single node setup, in which I am using a liberary the I included in my Web-Inf and using in my code.



The issue is that I have another application that added its liberaries to the WebSphere parent lib folder, one of which are the same liberary I am using but with an older version, creating conflict and jamming my code.



The server class loader is configured Parent first unfourtunatly and I cannot change that fact. My question is, how can I make my app use my liberary, ignoring the one used by the class loader?










share|improve this question























  • You can't. If you cannot re-configure classloader to "parent last", then you need a different instance, so 1) there is no conflicting classes in parent loader, or 2) you can configure "parent last" to resolve the conflict.

    – Andreas
    Nov 19 '18 at 16:57
















1















I have Java web application running on a web application server single node setup, in which I am using a liberary the I included in my Web-Inf and using in my code.



The issue is that I have another application that added its liberaries to the WebSphere parent lib folder, one of which are the same liberary I am using but with an older version, creating conflict and jamming my code.



The server class loader is configured Parent first unfourtunatly and I cannot change that fact. My question is, how can I make my app use my liberary, ignoring the one used by the class loader?










share|improve this question























  • You can't. If you cannot re-configure classloader to "parent last", then you need a different instance, so 1) there is no conflicting classes in parent loader, or 2) you can configure "parent last" to resolve the conflict.

    – Andreas
    Nov 19 '18 at 16:57














1












1








1








I have Java web application running on a web application server single node setup, in which I am using a liberary the I included in my Web-Inf and using in my code.



The issue is that I have another application that added its liberaries to the WebSphere parent lib folder, one of which are the same liberary I am using but with an older version, creating conflict and jamming my code.



The server class loader is configured Parent first unfourtunatly and I cannot change that fact. My question is, how can I make my app use my liberary, ignoring the one used by the class loader?










share|improve this question














I have Java web application running on a web application server single node setup, in which I am using a liberary the I included in my Web-Inf and using in my code.



The issue is that I have another application that added its liberaries to the WebSphere parent lib folder, one of which are the same liberary I am using but with an older version, creating conflict and jamming my code.



The server class loader is configured Parent first unfourtunatly and I cannot change that fact. My question is, how can I make my app use my liberary, ignoring the one used by the class loader?







java java-ee websphere classloader






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 '18 at 16:51









WiredCoderWiredCoder

496328




496328













  • You can't. If you cannot re-configure classloader to "parent last", then you need a different instance, so 1) there is no conflicting classes in parent loader, or 2) you can configure "parent last" to resolve the conflict.

    – Andreas
    Nov 19 '18 at 16:57



















  • You can't. If you cannot re-configure classloader to "parent last", then you need a different instance, so 1) there is no conflicting classes in parent loader, or 2) you can configure "parent last" to resolve the conflict.

    – Andreas
    Nov 19 '18 at 16:57

















You can't. If you cannot re-configure classloader to "parent last", then you need a different instance, so 1) there is no conflicting classes in parent loader, or 2) you can configure "parent last" to resolve the conflict.

– Andreas
Nov 19 '18 at 16:57





You can't. If you cannot re-configure classloader to "parent last", then you need a different instance, so 1) there is no conflicting classes in parent loader, or 2) you can configure "parent last" to resolve the conflict.

– Andreas
Nov 19 '18 at 16:57












2 Answers
2






active

oldest

votes


















10














The solution is to move the conflicting package to a shared library, configure the library to use an isolated class loader, and associate that library with your application or module. The "isolated class loader" setting creates a separate parent-last class loader for the shared library, so you get that behavior targeted to only the artifacts that need it rather than having to apply it to the entire application or module.



https://www.ibm.com/support/knowledgecenter/en/SSAW57_8.5.5/com.ibm.websphere.nd.multiplatform.doc/ae/tcws_sharedlib.html



I'm specifically referencing the "Use an isolated class loader for this shared library" setting.






share|improve this answer































    2














    If you can't change your application server setup there are basically three things you can do:




    1. Downgrade your application dependency to lower version used by WebSphere server and keep it in sync. This is preferable as it's least hassle.


    2. Shade the dependency during build to your own package to prevent package clash. This can be done with Maven Shade Plugin, see Relocating Classes usage example.


    3. Write a new custom classloader to work around the problem.



    I'd try them in 1 -> 2 -> 3 order. Option 3 is possible but is an error-prone nightmare. I'd rather deploy to another server than do it.






    share|improve this answer
























    • 4. Start another WebSphere instance.

      – Andreas
      Nov 19 '18 at 16:59











    • "I'd rather deploy to another server than do it." - As would I. The OP's problem is one of the reasons why some people say "application servers are dead". It's often easier to just treat the server as a dependency of an application than going through all the hassle that comes with incompatibilities like that.

      – Thomas
      Nov 19 '18 at 17:01











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379273%2foverride-class-loader-parent-first%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    10














    The solution is to move the conflicting package to a shared library, configure the library to use an isolated class loader, and associate that library with your application or module. The "isolated class loader" setting creates a separate parent-last class loader for the shared library, so you get that behavior targeted to only the artifacts that need it rather than having to apply it to the entire application or module.



    https://www.ibm.com/support/knowledgecenter/en/SSAW57_8.5.5/com.ibm.websphere.nd.multiplatform.doc/ae/tcws_sharedlib.html



    I'm specifically referencing the "Use an isolated class loader for this shared library" setting.






    share|improve this answer




























      10














      The solution is to move the conflicting package to a shared library, configure the library to use an isolated class loader, and associate that library with your application or module. The "isolated class loader" setting creates a separate parent-last class loader for the shared library, so you get that behavior targeted to only the artifacts that need it rather than having to apply it to the entire application or module.



      https://www.ibm.com/support/knowledgecenter/en/SSAW57_8.5.5/com.ibm.websphere.nd.multiplatform.doc/ae/tcws_sharedlib.html



      I'm specifically referencing the "Use an isolated class loader for this shared library" setting.






      share|improve this answer


























        10












        10








        10







        The solution is to move the conflicting package to a shared library, configure the library to use an isolated class loader, and associate that library with your application or module. The "isolated class loader" setting creates a separate parent-last class loader for the shared library, so you get that behavior targeted to only the artifacts that need it rather than having to apply it to the entire application or module.



        https://www.ibm.com/support/knowledgecenter/en/SSAW57_8.5.5/com.ibm.websphere.nd.multiplatform.doc/ae/tcws_sharedlib.html



        I'm specifically referencing the "Use an isolated class loader for this shared library" setting.






        share|improve this answer













        The solution is to move the conflicting package to a shared library, configure the library to use an isolated class loader, and associate that library with your application or module. The "isolated class loader" setting creates a separate parent-last class loader for the shared library, so you get that behavior targeted to only the artifacts that need it rather than having to apply it to the entire application or module.



        https://www.ibm.com/support/knowledgecenter/en/SSAW57_8.5.5/com.ibm.websphere.nd.multiplatform.doc/ae/tcws_sharedlib.html



        I'm specifically referencing the "Use an isolated class loader for this shared library" setting.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 '18 at 17:49









        JaridJarid

        1,04327




        1,04327

























            2














            If you can't change your application server setup there are basically three things you can do:




            1. Downgrade your application dependency to lower version used by WebSphere server and keep it in sync. This is preferable as it's least hassle.


            2. Shade the dependency during build to your own package to prevent package clash. This can be done with Maven Shade Plugin, see Relocating Classes usage example.


            3. Write a new custom classloader to work around the problem.



            I'd try them in 1 -> 2 -> 3 order. Option 3 is possible but is an error-prone nightmare. I'd rather deploy to another server than do it.






            share|improve this answer
























            • 4. Start another WebSphere instance.

              – Andreas
              Nov 19 '18 at 16:59











            • "I'd rather deploy to another server than do it." - As would I. The OP's problem is one of the reasons why some people say "application servers are dead". It's often easier to just treat the server as a dependency of an application than going through all the hassle that comes with incompatibilities like that.

              – Thomas
              Nov 19 '18 at 17:01
















            2














            If you can't change your application server setup there are basically three things you can do:




            1. Downgrade your application dependency to lower version used by WebSphere server and keep it in sync. This is preferable as it's least hassle.


            2. Shade the dependency during build to your own package to prevent package clash. This can be done with Maven Shade Plugin, see Relocating Classes usage example.


            3. Write a new custom classloader to work around the problem.



            I'd try them in 1 -> 2 -> 3 order. Option 3 is possible but is an error-prone nightmare. I'd rather deploy to another server than do it.






            share|improve this answer
























            • 4. Start another WebSphere instance.

              – Andreas
              Nov 19 '18 at 16:59











            • "I'd rather deploy to another server than do it." - As would I. The OP's problem is one of the reasons why some people say "application servers are dead". It's often easier to just treat the server as a dependency of an application than going through all the hassle that comes with incompatibilities like that.

              – Thomas
              Nov 19 '18 at 17:01














            2












            2








            2







            If you can't change your application server setup there are basically three things you can do:




            1. Downgrade your application dependency to lower version used by WebSphere server and keep it in sync. This is preferable as it's least hassle.


            2. Shade the dependency during build to your own package to prevent package clash. This can be done with Maven Shade Plugin, see Relocating Classes usage example.


            3. Write a new custom classloader to work around the problem.



            I'd try them in 1 -> 2 -> 3 order. Option 3 is possible but is an error-prone nightmare. I'd rather deploy to another server than do it.






            share|improve this answer













            If you can't change your application server setup there are basically three things you can do:




            1. Downgrade your application dependency to lower version used by WebSphere server and keep it in sync. This is preferable as it's least hassle.


            2. Shade the dependency during build to your own package to prevent package clash. This can be done with Maven Shade Plugin, see Relocating Classes usage example.


            3. Write a new custom classloader to work around the problem.



            I'd try them in 1 -> 2 -> 3 order. Option 3 is possible but is an error-prone nightmare. I'd rather deploy to another server than do it.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 19 '18 at 16:56









            Karol DowbeckiKarol Dowbecki

            20.4k92852




            20.4k92852













            • 4. Start another WebSphere instance.

              – Andreas
              Nov 19 '18 at 16:59











            • "I'd rather deploy to another server than do it." - As would I. The OP's problem is one of the reasons why some people say "application servers are dead". It's often easier to just treat the server as a dependency of an application than going through all the hassle that comes with incompatibilities like that.

              – Thomas
              Nov 19 '18 at 17:01



















            • 4. Start another WebSphere instance.

              – Andreas
              Nov 19 '18 at 16:59











            • "I'd rather deploy to another server than do it." - As would I. The OP's problem is one of the reasons why some people say "application servers are dead". It's often easier to just treat the server as a dependency of an application than going through all the hassle that comes with incompatibilities like that.

              – Thomas
              Nov 19 '18 at 17:01

















            4. Start another WebSphere instance.

            – Andreas
            Nov 19 '18 at 16:59





            4. Start another WebSphere instance.

            – Andreas
            Nov 19 '18 at 16:59













            "I'd rather deploy to another server than do it." - As would I. The OP's problem is one of the reasons why some people say "application servers are dead". It's often easier to just treat the server as a dependency of an application than going through all the hassle that comes with incompatibilities like that.

            – Thomas
            Nov 19 '18 at 17:01





            "I'd rather deploy to another server than do it." - As would I. The OP's problem is one of the reasons why some people say "application servers are dead". It's often easier to just treat the server as a dependency of an application than going through all the hassle that comes with incompatibilities like that.

            – Thomas
            Nov 19 '18 at 17:01


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379273%2foverride-class-loader-parent-first%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to change which sound is reproduced for terminal bell?

            Can I use Tabulator js library in my java Spring + Thymeleaf project?

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents