Using URLClassLoader to load .class file

前端 未结 2 860
余生分开走
余生分开走 2021-01-20 13:35

I\'m aware that this question has been asked before:

How to use URLClassLoader to load a *.class file?

However I don\'t really understand due to the lack of

2条回答
  •  广开言路
    2021-01-20 14:11

    Your _sHashFunctionFilePath needs to have the package name of the target class removed from it, so the ClassLoader will look in _sHashFunctionFilePath + package.name + HashFunction.class as the path to the file. If you don't do that, the ClassLoader won't be able to find the file.

    So if the target class is my.great.HashFunction in HashFunction.class, then it needs to be in a directory called my/great/ if you want to use URLClassLoader. Then, you'd use /path/to as the file:/// URL for your URLClassLoader if the .class file was actually found in /path/to/my/great/HashFunction.class.

提交回复
热议问题