03 January 2010

Invoke JDK Commands at runtime,

Now , To be honest for sometime i am writing a tool which is responsible for writing code, generating .dml files and creating a jar file , which is composed of them :))

if there are some lazy developers like me, i think this will make them happy :)


String[] options = new String[] {
"-classpath", "/", "-d", "\\mdb", "\\turkcell\\beawllog\\Exercise.java"
};


com.sun.tools.javac.Main.compile(options);

This line calls javac from tools.jar and generate .class file of the .java file..

Invoking other jdk commands as same as above..

Creating jar from java code is also pretty simple,..
Here is the statement which generates jar file MernisMDB.jar with combination of folders mdb META-INF,


String command = "jar cf MernisMDB.jar \\mdb \\META-INF ";
Runtime.getRuntime().exec(command);

..

if you have standart stuff you can generate class files and copy them into mdb folder
and you can copy your ejb-jar xml, weblogic-jar xml , beans.xml under META-INF folder


and package them under your jar file...


just easy

No comments: