fork download
  1. import java.io.File;
  2. import java.io.FileInputStream;
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.OutputStream;
  7.  
  8. import javax.xml.parsers.DocumentBuilder;
  9. import javax.xml.parsers.DocumentBuilderFactory;
  10. import javax.xml.xpath.XPath;
  11. import javax.xml.xpath.XPathConstants;
  12. import javax.xml.xpath.XPathExpression;
  13. import javax.xml.xpath.XPathFactory;
  14.  
  15. import org.apache.http.HttpResponse;
  16. import org.apache.http.client.methods.HttpGet;
  17. import org.apache.http.impl.client.DefaultHttpClient;
  18. import org.apache.http.params.BasicHttpParams;
  19. import org.apache.http.params.HttpConnectionParams;
  20. import org.apache.http.params.HttpParams;
  21.  
  22. import org.w3c.dom.Document;
  23.  
  24.  
  25. public class updater {
  26. public static void main(String[] args) throws IOException {
  27. try{
  28. DefaultHttpClient httpclient = ClientMaker();
  29. HttpGet get = new HttpGet("http://www.myserver.com/path/to/Version.xml");
  30. HttpResponse response = httpclient.execute(get);
  31. InputStream in = response.getEntity().getContent();
  32.  
  33. DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
  34. DocumentBuilder builder = domFactory.newDocumentBuilder();
  35. Document doc = builder.parse(in);
  36.  
  37. //Parse the Xml.
  38. XPathFactory factory = XPathFactory.newInstance();
  39. XPath xpath = factory.newXPath();
  40. XPathExpression expr = xpath.compile("//version/number/text()");
  41. String result = (String) expr.evaluate(doc, XPathConstants.STRING);
  42. System.out.println(result);
  43.  
  44. File f = new File("C:\\Users\\Damien\\Documents\\Eclipse\\MyOutput\\bin\\Version.xml");
  45. in = new FileInputStream(f) ;
  46. doc = builder.parse(in);
  47. expr=xpath.compile("//version/number/text()");
  48. String result2 = (String) expr.evaluate(doc, XPathConstants.STRING);
  49. System.out.println(result2);
  50.  
  51.  
  52. if(Integer.parseInt(result) < Integer.parseInt(result2)){
  53. HttpGet get2 = new HttpGet("http://www.myserver.com/path/to/MyJar.jar");
  54. HttpResponse response2 = httpclient.execute(get2);
  55. InputStream in2 = response2.getEntity().getContent();
  56. File f2 = new File("C:\\Users\\Damien\\Documents\\Eclipse\\path\\to\\MyJar.jar");
  57. byte buf[] = new byte[1024];
  58. int len;
  59. while ((len = in2.read(buf)) > 0) {
  60. fos.write(buf, 0, len);
  61. }
  62. fos.close();
  63. in.close();
  64. }
  65. Process p = Runtime.getRuntime().exec("cmd.exe /C javaw -jar C:\\Users\\Damien\\Documents\\Eclipse\\path\\to\\MyJar.jar");
  66. p.waitFor();
  67. p.destroy();
  68. }catch(Exception e){ e.printStackTrace(); }
  69.  
  70.  
  71. }
  72.  
  73. public static DefaultHttpClient ClientMaker() {
  74. int connectiontimeout = 30000; // 1 second int sockettimeout = 1000;
  75. HttpParams httpparameters = new BasicHttpParams();
  76. HttpConnectionParams.setConnectionTimeout(httpparameters,
  77. connectiontimeout);
  78. HttpConnectionParams.setSoTimeout(httpparameters, connectiontimeout);
  79. DefaultHttpClient httpclient = new DefaultHttpClient(httpparameters);
  80. return httpclient;
  81. }
  82.  
  83. }
  84.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:25: class updater is public, should be declared in a file named updater.java
public class updater {
       ^
Main.java:15: package org.apache.http does not exist
import org.apache.http.HttpResponse;
                      ^
Main.java:16: package org.apache.http.client.methods does not exist
import org.apache.http.client.methods.HttpGet;
                                     ^
Main.java:17: package org.apache.http.impl.client does not exist
import org.apache.http.impl.client.DefaultHttpClient;
                                  ^
Main.java:18: package org.apache.http.params does not exist
import org.apache.http.params.BasicHttpParams;
                             ^
Main.java:19: package org.apache.http.params does not exist
import org.apache.http.params.HttpConnectionParams;
                             ^
Main.java:20: package org.apache.http.params does not exist
import org.apache.http.params.HttpParams;
                             ^
Main.java:74: cannot find symbol
symbol  : class DefaultHttpClient
location: class updater
	public static DefaultHttpClient ClientMaker() {
	              ^
Main.java:28: cannot find symbol
symbol  : class DefaultHttpClient
location: class updater
			DefaultHttpClient httpclient = ClientMaker();
			^
Main.java:29: cannot find symbol
symbol  : class HttpGet
location: class updater
			HttpGet get = new HttpGet("http://www.myserver.com/path/to/Version.xml");
			^
Main.java:29: cannot find symbol
symbol  : class HttpGet
location: class updater
			HttpGet get = new HttpGet("http://www.myserver.com/path/to/Version.xml");
			                  ^
Main.java:30: cannot find symbol
symbol  : class HttpResponse
location: class updater
			HttpResponse response = httpclient.execute(get);
			^
Main.java:53: cannot find symbol
symbol  : class HttpGet
location: class updater
				HttpGet get2 = new HttpGet("http://www.myserver.com/path/to/MyJar.jar"); 
				^
Main.java:53: cannot find symbol
symbol  : class HttpGet
location: class updater
				HttpGet get2 = new HttpGet("http://www.myserver.com/path/to/MyJar.jar"); 
				                   ^
Main.java:54: cannot find symbol
symbol  : class HttpResponse
location: class updater
				HttpResponse response2 = httpclient.execute(get2);
				^
Main.java:76: cannot find symbol
symbol  : class HttpParams
location: class updater
		HttpParams httpparameters = new BasicHttpParams();
		^
Main.java:76: cannot find symbol
symbol  : class BasicHttpParams
location: class updater
		HttpParams httpparameters = new BasicHttpParams();
		                                ^
Main.java:77: cannot find symbol
symbol  : variable HttpConnectionParams
location: class updater
		HttpConnectionParams.setConnectionTimeout(httpparameters,
		^
Main.java:79: cannot find symbol
symbol  : variable HttpConnectionParams
location: class updater
		HttpConnectionParams.setSoTimeout(httpparameters, connectiontimeout);
		^
Main.java:80: cannot find symbol
symbol  : class DefaultHttpClient
location: class updater
		DefaultHttpClient httpclient = new DefaultHttpClient(httpparameters);
		^
Main.java:80: cannot find symbol
symbol  : class DefaultHttpClient
location: class updater
		DefaultHttpClient httpclient = new DefaultHttpClient(httpparameters);
		                                   ^
21 errors
stdout

Standard output is empty