-
Notifications
You must be signed in to change notification settings - Fork 2
ALERT MODULE JAVA
rizcompeer edited this page Sep 19, 2016
·
1 revision
package com.vts.init;
import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.Enumeration; import java.util.TimeZone; import java.util.jar.JarEntry; import java.util.jar.JarFile;
public class init {
public static int account_id = 1; //IESPL ACCOUNT ID -COMPLETE
/*public static ArrayList<Integer> vehicle_id = new ArrayList<Integer>();
public static ArrayList<String> vehicle_name = new ArrayList<String>();
public static ArrayList<Float> max_speed = new ArrayList<Float>();*/
public static ArrayList<String> device_imei_no = new ArrayList<String>();
public static String date1 = "", date2="";
public static void main(String args[]) {
//worker worker_class = new worker();
//worker.process_data(account_id);
/*SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//dd/MM/yyyy
sdfDate.setTimeZone(TimeZone.getTimeZone("Asia/Kolkata"));
Date date_now1 = new Date();
String dateInString = "2016-08-06 14:28:00";
try {
Date date = sdfDate.parse(dateInString);
String start_date = sdfDate.format(date_now1);
System.out.println(start_date);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}*/
String pathToJar = "F:\\JARS_RUNNABLE/test/TestSourceJar.jar";
JarFile jarFile = null;
try {
jarFile = new JarFile(pathToJar);
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
Enumeration<JarEntry> e = jarFile.entries();
//URL[] urls;
try {
URL[] urls = { new URL("jar:file:" + pathToJar+"!/") };
//urls = new URL (pathToJar);
URLClassLoader cl = URLClassLoader.newInstance(urls);
while (e.hasMoreElements()) {
JarEntry je = e.nextElement();
if(je.isDirectory() || !je.getName().endsWith(".class")){
continue;
}
// -6 because of .class
String className = je.getName().substring(0,je.getName().length()-6);
className = className.replace('/', '.');
System.out.println(className);
if(className.equals("test_module")) {
try {
Class cls = cl.loadClass(className);
try {
//c.getMethod("main", String[].class).invoke(null, args);
//Method method = cls.getMethod("TestAlert",);
// TODO Auto-generated catch block
//}
try {
//Object result = method.invoke(null, (Object)args);
//Object result = method.invoke("123");
// cls.getMethod("TestAlert0", String[].class).invoke(1);
Class myClass = cl.loadClass("test_module");
//Method printMeMethod = myClass.getMethod("TestAlert0");
Method printMeMethod = myClass.getMethod("TestAlert1", new Class[] {String.class});
//Method printMeMethod = myClass.getMethod("TestAlert2", new Class[] {String.class, String.class});
//Method printMeMethod = myClass.getMethod("TestAlert3", new Class[] {String.class, String.class});
try {
Object myClassObj = myClass.newInstance();
} catch (InstantiationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//Object response = printMeMethod.invoke(cl);
Object response = printMeMethod.invoke(cl, "String1");
//Object response = printMeMethod.invoke(cl, "String1", "String2");
//Object response = printMeMethod.invoke(cl, "String1", "String2");
//cls.getMethod("TestAlert", String[].class).invoke("123", "123");
/*Method method = cls.getDeclaredMethod("TestAlert", String[].class);
try {
Object instance = cls.newInstance();
} catch (InstantiationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Object result = method.invoke("123", (Object)args);*/
} catch (IllegalAccessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (InvocationTargetException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} catch (IllegalArgumentException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (NoSuchMethodException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SecurityException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
} catch (MalformedURLException e1){// TODO Auto-generated catch block
e1.printStackTrace();}
}
}