Use Eclipse to make jar packages and do batch processing of bat

Source: Internet
Author: User

(1) Packaging jar method: Right-click the project name--export--jar file--Check the files that need to be packaged (by default)

(2) Do batch processing: write Start.bat, content such as:

Set Classpath=download.jar;commons-io-1.1.jar//The third-party jar is required here, and (1) the jar to be hit is specified, with a semicolon interval
Java FileSave//This is the class name that contains the main method

Pause

Add: The Business jar package needs to read the properties file, this path is relative to the root directory before packaging, after packaging, if not add the properties file in the Jar package, the properties file will not be found.

Therefore, it is best to put the package configuration file into the root directory of the project, after the jar, into the sibling directory.

Example: config.properties in the root directory

Import Java.io.file;import java.io.ioexception;import Java.net.url;import Java.util.properties;import Java.util.random;import Org.apache.commons.io.fileutils;public class filesave{static String Remoteurl = ""; static String Savefileurl = ""; static int threadnums = 0;  public static void Main (string[] args) throws IOException {//Read config file readconfig ();  for (int i = 0; i < threadnums; i++) {New Thread (new MyThread (Remoteurl, Savefileurl)). Start ();  }} public static void Readconfig () throws IOException {String fp = system.getproperty ("User.dir") + File.separator +  "Config.properties";  File File = new file (FP);  Properties Properties = new properties ();  Java.io.FileInputStream in = new Java.io.FileInputStream (file);  Properties.load (in);  In.close ();  Remoteurl = Properties.getproperty ("Remoteurl");  Savefileurl = Properties.getproperty ("Savefileurl") + ":/download/"; Threadnums = Integer.parseint (Properties.getproperty ("threadnums")); }}class MyThread implements RUNNABLe{static Long NUM = 0; String Remoteurl = ""; String Savefileurl = "";  Public MyThread (String remoteurl, String savefileurl) {this.remoteurl = Remoteurl; This.savefileurl = Savefileurl; } public void Run () {Downloadfromurl (Remoteurl, Savefileurl);}/** * File Download method */public static String Downloadfromurl (  String url, string dir) {string fileName = "";   try {URL httpurl = new URL (URL);   string[] US = url.split ("/");   FileName = Us[us.length-1]; String ramdom = System.currenttimemillis () + "" + New Random (). Nextint (+) + new Random (). Nextint (+) + new Rand   Om (). Nextint (+) + getsequence ();   filename = Ramdom + "_" + filename;   SYSTEM.OUT.PRINTLN ("FileName:" + filename);   File F = new file (dir + fileName);  Fileutils.copyurltofile (Httpurl, F);   } catch (Exception e) {e.printstacktrace ();  return "fault!"; } return fileName;  } public static synchronized long getsequence () {if (num > 100000000) {num = 0; } return num++; }}


Use Eclipse to make jar packages and do batch processing of bat

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.