Some special projects require different functions in different environments. You can also upload a new JAR file to implement simple and direct hot deployment and run it in a new thread of the system. This ensures that the system does not need to be modified.Source code.
Package COM. shine. framework. jarutil; </P> <p> Import java.net. URL; <br/> Import java.net. urlclassloader; </P> <p> Import COM. shine. framework. core. util. reflectionutil; </P> <p>/** <br/> * jar utilities <br/> * @ author viruscodecn@gmail.com <br/> * @ project javaframework 1.0 <br/> */<br/> public class jarutil extends urlclassloader {<br/> Public jarutil (URL) {<br/> super (new URL [] {URL }); <br/>}</P> <p>/** <br/> * execute a method of class in jar <br/> * @ Param jarpath <br/> * @ Param classpath <br/> * @ Param methodname <br/> * @ Param ARGs <br/> * @ return <br/> */<br/> Public static object executejarclass (string jarpath, string classpath, <br/> string methodname, object... ARGs) {<br/> try {<br/> Object object = jarutil. getclassobject (jarpath, classpath); <br/> return reflectionutil. invokemethod (object, methodname, argS); <br/>} catch (exception ex) {<br/> ex. printstacktrace (); <br/>}< br/> return NULL; <br/>}</P> <p>/** <br/> * execute the main method of a class of jar <br/> * @ Param jarpath <br/> * @ Param classpath <br/> * @ Param ARGs <br/> */<br/> Public static void executejavaclassmainmethod (string jarpath, <br/> string classpath, object... ARGs) {<br/> try {<br/> Object object = jarutil. getclassobject (jarpath, classpath); <br/> reflectionutil. invokemainmethod (object, argS); <br/>} catch (exception ex) {<br/> ex. printstacktrace (); <br/>}</P> <p>/** <br/> * obtain a class in jar <br/> * @ Param jarpath <br/> * @ Param classpath <br/> * @ return <br/> */<br/> Public static object getclassobject (string jarpath, string classpath) {<br/> try {<br/> url = new URL (jarpath); <br/> jarutil T = new jarutil (URL ); </P> <p> Class C = T. findclass (classpath); <br/> return C. newinstance (); <br/>}catch (exception ex) {<br/> ex. printstacktrace (); <br/>}< br/> return NULL; <br/>}< br/>
Example
Package COM. shine. framework. jarutil; </P> <p> public class example {<br/> Public static void main (string ARGs []) {<br/> jarutil.exe cutejarclass ("test. jar "," test. test "," test "," 123 "); <br/>}< br/>