• Post Reply Bookmark Topic Watch Topic
  • New Topic

Remote Classpath Loader  RSS feed

 
Vikas Aggarwal
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this situation where I have some class files ot jars placed on a server (server1) and the url is http://www.server1.com/classes/. The server2 has my java program on the same network. Now I want the class files or the jar files to get included in my classpath at server1. I am not allowed to physically move the class files from server1 to server2.
how can we acheive it. Is there any example?
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think that you can directly place a URL in the classpath of your machine. To get this done I believe that you need to use a URLClassLoader. Of course the URL has to be accessable on a Web Server somewhere.
//You would create a URL object array pointing at the location of the classes and any jars at that location.
URL[] myURL = {new URL("http://www.server1.com/classes/") , new URL("http://www.server1.com/classes/myPackage.jar")};
//Then you would create URLClassLoader Object and feed it that URL object.
URLClassLoader myClassLoader = new URLClassLoader(myUrl);
//Finally you would do the load manually by
Class myClass = myClassLoader.findClass("WhateverClass");
I haven't actually tried this, so let us know how it works.
[ April 24, 2003: Message edited by: Cindy Glass ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!