Run a jar File from java program

Using ProcessBuilder(java.lang.ProcessBuilder) will solve your problem. Syntax is as follows – ProcessBuilder pb = new ProcessBuilder(“java”, “-jar”, “absolute path upto jar”); Process p = pb.start(); You can redirent input/output/error to/from files as follows File commands = new File(“absolute path to inputs file”); File dirOut = new File(“absolute path to outputs file”); File dirErr = new … Read more

Can a program depend on a library during compilation but not runtime?

A compile-time dependency is generally required at runtime. In maven, a compile scoped dependency will be added to the classpath on runtime (e.g. in wars they will be copied to WEB-INF/lib). It is not, however, strictly required; for instance, we may compile against a certain API, making it a compile-time dependency, but then at runtime … Read more

Create object instance of a class from its name in string variable

Having the class name in string is not enough to be able to create its instance. As a matter of fact you will need full namespace including class name to create an object. Assuming you have the following: string className = “MyClass”; string namespaceName = “MyNamespace.MyInternalNamespace”; Than you you can create an instance of that … Read more

On-the-fly, in-memory java code compilation for Java 5 and Java 6

JCI looks fine. This code snippet should be your base: JavaCompiler compiler = new JavaCompilerFactory().createCompiler(“eclipse”); MemoryResourceReader mrr = new MemoryResourceReader(); mrr.add(“resource name string”, yourJavaSourceString.getBytes()); MemoryResourceStore mrs = new MemoryResourceStore(); CompilationResult result = compiler.compile(sources, mrr, mrs); // don’t need the result, unless you care for errors/warnings // the class should have been compiled to your destination … Read more

Runtime.exec on argument containing multiple spaces

Ok, this is not simply an update but also an answer so I’m filing it as one. According to all information I could find, the following should theoretically do it: String[] cmd = {“explorer.exe”, “/select,\”C:\New”, “”, “”, “”, “”, “”, “”, “Folder\file.txt\””}; The multiple spaces have been broken into empty strings and the array version … Read more