java - Jar ignoring all methods -
i making pretty simple jar unzip zip , run jar inside of it. problem i've run doesn't @ all.
this main, , class file jar. manifest point correctly it, , loads without errors.
import java.io.file; import java.io.ioexception; import java.io.outputstream; import java.io.filewriter; import java.io.bufferedwriter; import java.io.bufferedoutputstream; import java.io.bufferedinputstream; import java.io.bufferedreader; import java.io.fileoutputstream; import java.io.fileinputstream; import java.io.filenotfoundexception; import java.io.inputstream; import java.io.inputstreamreader; import static java.lang.integer.parseint; import java.net.urlconnection; import java.net.url; import java.util.zip.zipfile; import java.util.zip.zipentry; import java.util.zip.zipinputstream; import java.util.enumeration; import sign.signlink; import java.nio.file.*; import java.io.filereader; public class clientupdater { private string filetoextractnew = "/client.zip"; private string getjardir() throws filenotfoundexception, ioexception{ string linebuf="",verstr=""; fileinputstream fis = new fileinputstream("/runlocationurl.txt"); bufferedreader br= new bufferedreader(new inputstreamreader(fis)); while ((linebuf = br.readline()) != null) { verstr = linebuf; } return verstr; } public static void main(string[] args) { system.out.println("start"); } private void unzip() { system.out.println("unzipping"); try { zipentry zipentry; //client bufferedinputstream bufferedinputstreamnew = new bufferedinputstream(new fileinputstream(this.filetoextractnew)); zipinputstream zipinputstreamnew = new zipinputstream(bufferedinputstreamnew); //client while ((zipentry = zipinputstreamnew.getnextentry()) != null) { string stringnew = zipentry.getname(); file filenew = new file(this.getjardir() + file.separator + stringnew); if (zipentry.isdirectory()) { new file(this.getjardir() + zipentry.getname()).mkdirs(); continue; } if (zipentry.getname().equals(this.filetoextractnew)) { this.unzipnew(zipinputstreamnew, this.filetoextractnew); break; } new file(filenew.getparent()).mkdirs(); this.unzipnew(zipinputstreamnew, this.getjardir() + zipentry.getname()); } zipinputstreamnew.close(); } catch (exception var1_2) { var1_2.printstacktrace(); } } private void unzipnew(zipinputstream zipinputstreamnew, string stringnew) throws ioexception { system.out.println("unzipping new"); fileoutputstream fileoutputstreamnew = new fileoutputstream(stringnew); byte[] arrby = new byte[4024]; int n = 0; while ((n = zipinputstreamnew.read(arrby)) != -1) { fileoutputstreamnew.write(arrby, 0, n); } fileoutputstreamnew.close(); runtime.getruntime().exec("java -jar " + getjardir() + "/project pk client.jar"); system.exit(0); } }
it shows "start" message, not other 2, never reaches methods. because aren't being called? i'm still learning java.
you have call other methods main
. right now, telling computer print start
, exit. functions not called existing.
it seems based on quick glance need add unzip();
main
function, right after system.out.println
line.
to this, need other methods static
, need private static void unzip()
instead of private void unzip()
. other methods too.
import java.io.*; import static java.lang.integer.parseint; import java.net.urlconnection; import java.net.url; import java.util.zip.zipfile; import java.util.zip.zipentry; import java.util.zip.zipinputstream; import java.util.enumeration; import sign.signlink; import java.nio.file.*; public class clientupdater { private string filetoextractnew = "/client.zip"; private static string getjardir() throws filenotfoundexception, ioexception{ string linebuf="",verstr=""; fileinputstream fis = new fileinputstream("/runlocationurl.txt"); bufferedreader br= new bufferedreader(new inputstreamreader(fis)); while ((linebuf = br.readline()) != null) { verstr = linebuf; } return verstr; } public static void main(string[] args) { system.out.println("start"); unzip(); } private static void unzip() { system.out.println("unzipping"); try { zipentry zipentry; //client bufferedinputstream bufferedinputstreamnew = new bufferedinputstream(new fileinputstream(this.filetoextractnew)); zipinputstream zipinputstreamnew = new zipinputstream(bufferedinputstreamnew); //client while ((zipentry = zipinputstreamnew.getnextentry()) != null) { string stringnew = zipentry.getname(); file filenew = new file(this.getjardir() + file.separator + stringnew); if (zipentry.isdirectory()) { new file(this.getjardir() + zipentry.getname()).mkdirs(); continue; } if (zipentry.getname().equals(this.filetoextractnew)) { this.unzipnew(zipinputstreamnew, this.filetoextractnew); break; } new file(filenew.getparent()).mkdirs(); this.unzipnew(zipinputstreamnew, this.getjardir() + zipentry.getname()); } zipinputstreamnew.close(); } catch (exception var1_2) { var1_2.printstacktrace(); } } private static void unzipnew(zipinputstream zipinputstreamnew, string stringnew) throws ioexception { system.out.println("unzipping new"); fileoutputstream fileoutputstreamnew = new fileoutputstream(stringnew); byte[] arrby = new byte[4024]; int n = 0; while ((n = zipinputstreamnew.read(arrby)) != -1) { fileoutputstreamnew.write(arrby, 0, n); } fileoutputstreamnew.close(); runtime.getruntime().exec("java -jar " + getjardir() + "/project pk client.jar"); system.exit(0); } }
Comments
Post a Comment