java - Running a batch file that's inside of a jar file -


i'm attempting call batch file packaged inside of jar file jar file itself. i'm not altogether sure possible, figured if knew how on here.

import java.io.ioexception; import java.net.urisyntaxexception; public class filelocationfinder {      public static void main(string[] args) throws ioexception, urisyntaxexception {         string curdir = system.getproperty("user.dir");         system.out.println("the user.dir = " + curdir);         file newfile = new file (filelocationfinder.class.getprotectiondomain().getcodesource().getlocation().touri().getpath());         string strnewfile = newfile.tostring();         system.out.println("the new path = " + strnewfile);              string abpath = new file(".").getabsolutepath();         system.out.println("the absolutepath = " + abpath);         string conpath = new file(".").getcanonicalpath();         system.out.println("the canonical path = " + conpath);         rundir(strnewfile);     }     public static void rundir(string dir){         final int exitval;         final process dirprocess;         try {             system.out.println("running curdir");             dirprocess = runtime.getruntime().exec(dir + "\\" + "somebatch.bat");             try {                 exitval = dirprocess.waitfor();                 if(exitval == 0){                     system.out.println("dir worked");                 }             } catch (interruptedexception e) {                 e.printstacktrace();             }         } catch (ioexception e) {             e.printstacktrace();         }     } } 

the contents of somebatch.bat

echo called 

this runs expect when compile run. when create jar file lot of errors.

you have tell java .bat file, way have it's searching working directory "dir\somebat.bat". search through jar file .bat need utilize classloader's getresource or getresourceasstream methods. may have copy .bat filesystem [such user.home directory] , use runtime.exec() launch there.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -