네트웍으로부터 클래스 로드하기


[ Follow Ups ] [ Post Followup ] [ 자바 묻고 답하기 ]

Posted by 윤경구 on July 05, 1997 at 19:03:41:

In Reply to: [질문] network의 host에 있는 class 를 local 의 자바 소스에서 이용하려면? posted by 강신동 on July 04, 1997 at 14:52:56:

자바 API 문서에서
java.lang.ClassLoader를 찾아보세요. 다음 예제가 있습니다.

For example, an application could create a network class loader to download class files from a server.
Sample code might look like: 

ClassLoader loader = new NetworkClassLoader(host, port); Object main = loader.loadClass("Main", true).newInstance();  . . .

The network class loader subclass must define the method loadClass to load a class from the network. Once it has downloaded the bytes that make up the class, it should use the method defineClass to create a class instance. A sample implementation is:

class NetworkClassLoader { String host; int port; Hashtable cache = new Hashtable(); private byte loadClassData(String name)[] { // load the class data from the connection  . . . } public synchronized Class loadClass(String name, boolean resolve) { Class c = cache.get(name); if (c == null) { byte data[] = loadClassData(name); c = defineClass(data, 0, data.length); cache.put(name, c); } if (resolve) resolveClass(c); return c; } }

조금만 수정하면 웹 서비스를 통해서 클래스를 로드할 수 있을 것 같네요.
물론 다른 호스트 접속이 필요하므로 애플릿에서는 사용하지 못하겠죠.


Follow Ups:



이어서 글올리기(답하기)

이름:
E-Mail:
제목:
내용:
관련 URL(선택):
URL 제목(선택):
관련 이미지 URL:


[ Follow Ups ] [ Post Followup ] [ 자바 묻고 답하기 ]