Author |
Message |
10/08/2017 11:46:33
|
vadingding
Power User
Joined: 14/07/2017 13:26:37
Messages: 145
Offline
|
Hi Captain,
Is it possible to compile or create a class file during runtime in CaptainCasa? Is it supported?
If so, can you give us a hint or example?
We tried it in Eclipse without using framework, and it works! But when we tried it using CaptainCasa, it seems that it cannot see or read captaincasa jar files even if those jar files are in the classpath.
Here is the code when we tried it in standalone:
Code:
String className = "ClassName";
String code =
"public class ClassName{\n" +
" public static void test(){\n" +
" System.out.println(\"Hello World!\");\n" +
" }\n" +
"}";
RuntimeCompiler r = new RuntimeCompiler();
r.addClass(className, code);
r.compile();
MethodInvocationUtils.invokeStaticMethod(r.getCompiledClass(className), "test");
But when we replace System.out with StatusBar.outputAlert() an error occur.
It says, it wasnt able to locate eclntjsfserver jar file.
Please help us
|
|
|
10/08/2017 13:20:44
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5555
Offline
|
Hi,
I never did things like this ;-).
But I assume that this must be a classloader issue. Isnt't ther some API to tell the MethodInvokcationUtils (which I assume is your code), on which class loader to operate).
For receiving the CaptaiNCasa class loder environment the easiest way is to call HotDeployManger.currentClassLoader() - which passed back the "deepest level" of the classloader hierarchy.
Regards, Björn
|
Björn Müller, CaptainCasa GmbH |
|
|
10/08/2017 15:02:51
|
vadingding
Power User
Joined: 14/07/2017 13:26:37
Messages: 145
Offline
|
Thanks for the reply, will give it another shot
|
|
|
11/08/2017 04:25:41
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5555
Offline
|
Just fyi: please note that you can "totally dynamically" develop with CaptainCasa. Base of this is the expression management (the one of JSF) where expressions can be resolved by implementing maps.
Examples:
Code:
#{d.XyzUI.data['whatever'].firstName}
This expression calls getData - which may return a Map - and the obejct of the map provides getFirstName().
Same with methods:
#{d.XyzUI.data['whatever'].onSomeAction}
...calls the method "onSomAction" of this object.
Same with lists:
#{d.XyzUI.items[3].onSomeAction}
Together with (ROW)DYNAMICCONTENT you may build up totally generic dialogs.
Regards, Björn
|
Björn Müller, CaptainCasa GmbH |
|
|
11/08/2017 04:35:12
|
vadingding
Power User
Joined: 14/07/2017 13:26:37
Messages: 145
Offline
|
Hi captain,
What we wanna do for now is to create a java file (class) during run time,
and on that class we just wanna add "Statusbar.outputAlert("Hello");" during run time too.
Like this:
Code:
public void onTest(javax.faces.event.ActionEvent event){
FileWriter write = null;
try{
File file = new File("C:\\Zone\\Test\\src\\managedbeans\\File.java");
file.createNewFile();
write = new FileWriter(file);
write.append("package managedbeans;\n");
write.append("import org.eclnt.jsfserver.defaultscreens.Statusbar;\n");
write.append("public class File{\n");
write.append(" public File(){\n");
write.append(" Statusbar.outputAlert(\"Yow\");");
write.append(" }\n");
write.append("}\n");
write.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
try {
write.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Any opinion on this?
|
|
|
14/08/2017 04:03:16
|
vadingding
Power User
Joined: 14/07/2017 13:26:37
Messages: 145
Offline
|
Hi Captain,
Saw your comment, does it automatically create the class file just by doing that? What we wanna achieve is, create class files during run time
|
|
|
14/08/2017 08:15:57
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5555
Offline
|
...just to add the info:
HotDeployManager.triggerCreationOfNewInstance is the method to trigger the creation of a hot deployment class loader.
JavaDoc says "must not be used" by application processing. We will update the docu: your application processing is a "technical application processing", which may call this method for good reason...
Regards, Björn
|
Björn Müller, CaptainCasa GmbH |
|
|
14/08/2017 14:20:32
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5555
Offline
|
...and further comment: please be aware of that new classes are applied to new sessions / user logins "only". So do not expect that classes are exchanged within the current session by magic...
Regards, Björn
|
Björn Müller, CaptainCasa GmbH |
|
|
14/08/2017 14:44:37
|
vadingding
Power User
Joined: 14/07/2017 13:26:37
Messages: 145
Offline
|
Haha okay, thanks for the reply Captain.
|
|
|
|