java - Janino compile several classes -
i have tried janino , i'm able execute dynamic class, passing string janino compiler.
now, should create several classed dynamically, , import them dynamic class.
an example:
- compile class string
- compile class b string
- create class c, putting inside "import mypackage.a; import mypackage.b; etc..."
- compile class c
how achieve result?
my first dynamic class is:
package com.flink.pojo; public class rainpojo { private string altitude; private string city_name; private string latitude; private string longitude; private string rainfall; private string station_name; private string time; public string getaltitude() { return altitude; } public void setaltitude(string altitude) { this.altitude = altitude; } public string getcity_name() { return city_name; } public void setcity_name(string city_name) { this.city_name = city_name; } public string getlatitude() { return latitude; } public void setlatitude(string latitude) { this.latitude = latitude; } public string getlongitude() { return longitude; } public void setlongitude(string longitude) { this.longitude = longitude; } public string getrainfall() { return rainfall; } public void setrainfall(string rainfall) { this.rainfall = rainfall; } public string getstation_name() { return station_name; } public void setstation_name(string station_name) { this.station_name = station_name; } public string gettime() { return time; } public void settime(string time) { this.time = time; } }
then have call class following class, generated dynamically:
import org.apache.flink.api.common.functions.mapfunction; import java.util.arraylist; import com.google.gson.jsonobject; import org.apache.flink.api.java.dataset; import org.apache.flink.api.java.executionenvironment; import org.apache.flink.api.java.tuple.tuple2; import org.apache.flink.api.common.operators.base.joinoperatorbase; import com.flink.pojo.rainpojo; public class flinkexecutor { public flinkexecutor() {} public static void main(string[] args) throws exception { final executionenvironment env = executionenvironment.getexecutionenvironment(); env.setdegreeofparallelism(1); source rain = new source("sensor", "rain"); string path_rain = rain.getcsvpath(); dataset < rainpojo > ds_s1 = env.readcsvfile("file://" + path_rain) .ignorefirstline() .pojotype(rainpojo.class, "table", "time", "longitude", "latitude", "average_rainfall", "maximum_rainfall"); ds_s1.map(new maprain(ds_s1.count())) .print(); } }
to compile first class have used:
simplecompiler compiler = new simplecompiler(); compiler.cook(p_class); classloader classloader = compiler.getclassloader(); try { class<?> cl = classloader.loadclass("com.flink.pojo.rainpojo"); } catch (classnotfoundexception e1) { e1.printstacktrace(); }
while second class, contains main method:
simplecompiler compiler = new simplecompiler(); compiler.cook(this.allclass); try { class<?> cl = compiler.getclassloader().loadclass("flinkexecutor"); method mainmeth = cl.getmethod("main", new class[] { string[].class }); string[] methargs = new string[] { "" }; // 1 input mainmeth.invoke(null, new object[] { methargs }); } catch (classnotfoundexception | nosuchmethodexception | securityexception | illegalaccessexception | illegalargumentexception e) { e.printstacktrace(); }
the error is:
org.codehaus.commons.compiler.compileexception: line 8, column 7: class 'com.flink.pojo.rainpojo' not found
janino can't find class import declaration.
thank you, giacomo
Comments
Post a Comment