[Logo] OLD FORUM - Use new one: https://www.CaptainCasa.online/forum
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Java RunTime Compiler  XML
Forum Index -> Development
Author Message
vadingding

Power User
[Avatar]

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

CaptainCasa

Power User
[Avatar]

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
vadingding

Power User
[Avatar]

Joined: 14/07/2017 13:26:37
Messages: 145
Offline

Thanks for the reply, will give it another shot
CaptainCasa

Power User
[Avatar]

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
vadingding

Power User
[Avatar]

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?
vadingding

Power User
[Avatar]

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

CaptainCasa

Power User
[Avatar]

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
CaptainCasa

Power User
[Avatar]

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
vadingding

Power User
[Avatar]

Joined: 14/07/2017 13:26:37
Messages: 145
Offline

Haha okay, thanks for the reply Captain.
 
Forum Index -> Development
Go to:   
Powered by JForum 2.1.6 © JForum Team