Results 1 to 11 of 11
  1. #1
    vijayabaskar is offline Member
    Join Date
    Apr 2009
    Posts
    37
    Rep Power
    0

    Smile Custome classloader problem

    Hi i created servlet program in two different context name
    1.Myhello
    2.Myhello1
    but "com.sample.helloworld" both program has same package name and same class name.
    so when i compiled it throws linkage error in my custom classloader.
    any one can me help to find to solve this error..

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    don't give them the same name
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  3. #3
    vijayabaskar is offline Member
    Join Date
    Apr 2009
    Posts
    37
    Rep Power
    0

    Default

    ya what u said is correct.. i am creating two folder..
    named one for myhello and second for myhello1
    this is the context name for each servlet.
    inside i created com.sample.helloworld.
    for both servlet..
    i hope u will help me to solve this problem

  4. #4
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    843
    Rep Power
    6

    Default

    Hi ,
    Your question is not that clear.just mention the web.xml file entry related to servlet and servlet class code related to imports

  5. #5
    vijayabaskar is offline Member
    Join Date
    Apr 2009
    Posts
    37
    Rep Power
    0

    Default

    hi ramyasivakanth..
    i am creating one servlet container using osgi framework.. it will be like tomcat server.
    if v put the servlet container in webapps folder in tomcat
    in my project, we created war folder.
    in war folder, we need to put only war files.
    i written the code for that war file will automatically extract and then we will see the output in webbrowser.. its normal only..
    its working now..
    what my doubt means if we put the different war file in war folder in my project.
    like myhello and myhello1
    but inside the myhello i created com.sample.helloworld and same thing i did in myhello1 also..
    this only throwing linkage error..
    if u not clear.. ask me

  6. #6
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    You cant have two classes with the same name. You'll have to call one com.sample.helloworld1 and the other com.sample.helloworld2 or something.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  7. #7
    vijayabaskar is offline Member
    Join Date
    Apr 2009
    Posts
    37
    Rep Power
    0

    Default

    i have created two servlet container named sample1 and sample2
    i had created same package name for both.

    In sample1,
    i created one servlet class with package name like com.sample.Hellowrold and /hello1 is alias name

    In sample2,
    i created one servlet class like com.sample.Hellowrold and /hello2 is alias name.


    i need to register the servlet in registerServlet method.
    it takes only the first class name.

    pls help me to define the registerServlet for this.

    see below code in mainThread class

    hs = (HttpServlet) cls.newInstance();
    System.out.println("war : "+wars[i]+" context:"+contexts[j][0]);


    httpService.registerServlet(wars[i]+contexts[j][0],hs, null,null);

    output:

    war : /sample1 context:/hello
    hs : /sample1 com.sample.HelloWorld@16ba008


    war : /sample2 context:/hello
    hs : /sample2 com.sample.HelloWorld@@9f2cff


    sample1 only work..

  8. #8
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Both of the classes are called com.sample.Helloworld. I'm not going to tell you again.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  9. #9
    vijayabaskar is offline Member
    Join Date
    Apr 2009
    Posts
    37
    Rep Power
    0

    Default

    Ya correct orangedog..
    but in tomcat it will work..
    for example
    we created to servlet container sample1 and sample2 in tomcat.
    sample1 and sample2 are the context name.
    we may create com.sample.HelloWorld in both servlet container.
    we will put these two folder in tomcat's webapps.
    and start the tomcat.
    it will work seperately..
    how?
    in tomcat also getting the class from classloader only..
    it works.. y not in my project..

    help to solve this problem..

  10. #10
    einarb is offline Member
    Join Date
    Mar 2009
    Posts
    22
    Rep Power
    0

    Default

    Quote Originally Posted by vijayabaskar View Post
    Ya correct orangedog..
    but in tomcat it will work..
    for example
    we created to servlet container sample1 and sample2 in tomcat.
    sample1 and sample2 are the context name.
    we may create com.sample.HelloWorld in both servlet container.
    we will put these two folder in tomcat's webapps.
    and start the tomcat.
    it will work seperately..
    how?
    in tomcat also getting the class from classloader only..
    it works.. y not in my project..

    help to solve this problem..
    if I remember correctly tomcat doesn't make any guarantees that it will work, it just works in some versions.

    it's safer to have two different classnames and/or packagenames

  11. #11
    vijayabaskar is offline Member
    Join Date
    Apr 2009
    Posts
    37
    Rep Power
    0

    Default

    hi orange,
    thanks for reply..
    but in my project can do it this now..
    its working depends on alias.. so if u want to run same package and same class name means contact my project.. its open source only..

Similar Threads

  1. classloader
    By vijayabaskar in forum Advanced Java
    Replies: 8
    Last Post: 04-06-2009, 09:08 AM
  2. ClassLoader and JVM
    By Pradeen in forum New To Java
    Replies: 0
    Last Post: 01-19-2009, 07:04 PM
  3. Problem of Classloader in Eclipse Plugin Developemt.
    By Ashish Naidu in forum Eclipse
    Replies: 0
    Last Post: 09-12-2008, 11:16 AM
  4. My own ClassLoader didn't work.
    By snooze-g in forum Advanced Java
    Replies: 1
    Last Post: 07-17-2007, 12:12 PM
  5. eclipse classloader problem
    By sandor in forum Eclipse
    Replies: 2
    Last Post: 05-10-2007, 04:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •