-
1. Re: about classloader of wildfly
ctomc Jun 3, 2014 9:29 AM (in response to hai_feng)WildFly doesn't use URLClassLoader anymore, last version that used it was AS6.
Since AS7 we use ModuleClassLoader which is implemented by Jboss modules.
see more about it:
https://docs.jboss.org/author/display/MODULES/Home
https://docs.jboss.org/author/display/WFLY8/Class+Loading+in+WildFly
-
2. Re: about classloader of wildfly
hai_feng Jun 4, 2014 8:40 AM (in response to ctomc)Hi,Tomaz
Thanks your reply,But when i scan the ducument(Home - JBoss Modules - Project Documentation Editor),there is no content about Modules API.The second ducument is not overall about ModuleClassLoader.
I want to know more about ModuleClassLoader and other classLoader about WildFly.My project use Tomcat past,now we want to move to wildfly,but when we visit the project on wildfly,it tells us can't use ModuleClassLoader.as you said as follow:
"
WildFly doesn't use URLClassLoader anymore, last version that used it was AS6.
Since AS7 we use ModuleClassLoader which is implemented by Jboss modules.
"
So i know the reason about this problem,and i write a demo to simulate the function in our project.
Example as following:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
ClassLoader parent = TestPath.class.getClassLoader();
URLClassLoader uL;
URL[] path;
int i;
if (parent instanceof URLClassLoader) {
System.out.println("ClassLoader:" + parent.getClass().getName());
uL = (URLClassLoader)parent;
path = uL.getURLs();
if (path != null) {
for (i = 0; i < path.length; ++i) {
System.out.println(path[i].getPath());
}
}
}
}
use Tomcat,the console print:
ClassLoader:org.apache.catalina.loader.WebappClassLoader
/S:/springToolSuite/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/webapps/testpath/WEB-INF/classes/
/S:/springToolSuite/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/webapps/testpath/WEB-INF/lib/jboss-modules.jar
Because Wildfly doesn't use URLClassLoader anymore,so above java code make invalid. Now,I want to know what api of ModuleClassLoader can i use to make the same function on wildfly?
please help!
Thanks!
-
3. Re: about classloader of wildfly
ctomc Jun 4, 2014 9:51 AM (in response to hai_feng)Wind Wild wrote:
Because Wildfly doesn't use URLClassLoader anymore,so above java code make invalid. Now,I want to know what api of ModuleClassLoader can i use to make the same function on wildfly?
Nothing really special here, just use standard java.lang.ClassLoader api, no need to cast it so impl version and call some special methods on it...
-
4. Re: about classloader of wildfly
hai_feng Jun 5, 2014 8:22 AM (in response to ctomc)Hi,Tomaz
Firstly,I know what you mean,but i can't find any api of ClassLoader make the same function to URLClassLoader,I just want to get the directory of war,what can i do?
Secondly,i write a demo as following:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
ClassLoader parent = TestPath.class.getClassLoader();
ClassLoader uL;
URL path;
int i;
if (parent instanceof ClassLoader) {
System.out.println("ClassLoader:" + parent.getClass().getName());
uL = (ClassLoader)parent;
path = uL.getResource("/com/classloader/test");
System.out.println(path.getPath());
}
}
the ""/com/classloader/test" is this class's package.
Now,when i deploy it to wildfly,the console print(os:windows)
when i deploy it to wildfly,the console print(os:linux)
when i deploy it to tomcat,the console print:
we can see that it's normal on tomcat,but it seem to be off normal on wildfly.What confuse me is why the directory of /com/classloader/test under the JBOSS_HOME/bin (windows wildfly)?the directory of /com/classloader/test under the linux root directory (linux wildfly).
According to my understanding,is it should under JBOSS_HOME\standalone\tmp\vfs\deployment ?
Please Help!
Thanks!
-
5. Re: about classloader of wildfly
hai_feng Jun 6, 2014 6:41 AM (in response to ctomc)Hi Tomaz:
about second question,i have solve it,as follow:
public String getRealFilePath(String aFilePath) throws Exception {
org.jboss.vfs.VirtualFile vFile = org.jboss.vfs.VFS.getChild(aFilePath);
URI fileNameDecodedTmp = org.jboss.vfs.VFSUtils.getPhysicalURI(vFile);
path = fileNameDecodedTmp.getPath();
System.out.println(path);
return path;
}
So at runtime I just need to call getRealFilePath() with the original question values, and problem solved
but i want to the first question's answer,please tell me,Thanks!