i want to access a class from another project in the workspace using ClassLoader. How can i specify the path to that class and get that class file ?I am using Eclipse . 开发者_高级运维Help
You have to just add that project in to build path configuration of the project where you want to access that. And the class loader will find that class depending on the import statement you have given in the class where you are using it.
To add in the build path : you have to right click on the project > select Build Path > Configure Build Path > then select a project tab and add the project in which the class is present which you want load.
You could try URLClassLoader an example is here
I never used GNU Classpath which could be heplful.
While I'm sure there are devious ways of doing exactly that, I think having one project reference another this way is not the best of ideas.
What you can do is create a jar of the project you're getting the class from via Export->Java->JAR file and put that file into your project. This will let you access the class you need while still keeping your projects self-contained.
精彩评论