如何为具有属性文件的java程序生成jar文件

时间:2017-07-07 07:34:37

标签: java jar properties property-files

如何为具有属性文件

的java程序生成jar文件
public class Download_logfiles {
/**
 * Download_logfiles class has to be public because another class uses the
 * Download_logfiles class
 */ 

private static URL URLObj;
/**
 * variable set for the server links from which the log files to be
 * downloaded
 */
private static URLConnection connect;
/** Variable for URL connection */
static String filename = "";
/** Variable used for extracting the servers */
static String user = "";
/** Variable used for user id */
static String pass = "";
/** Variable used for password */

static String download = "";
static Set<String> urls = new HashSet<String>();
static Set<String> comp = new HashSet<String>();
static Set<String> envir = new HashSet<String>();
static Properties prop = new Properties();

public static void main(String[] args)
        throws IOException { /** program entry point */

    System.out.println("argument count:" + args.length + " content:" + args);

    if(args.length==0)
    {
        System.out.println("Please enter the property file via arguments!!!");   /**Go to run configuration and under arguements enter the path **/
        System.exit(0);
    }

    readConfigProperties(args[0]);
    configUIParameter();
    Hashtable<String, String> loginfo = Validation();
    String componentavx = loginfo
            .get("component"); /** extract component information */
    String environmentProd = loginfo
            .get("environment"); /** extract environment information */
    config(componentavx, environmentProd);
    user = loginfo.get(
            "user"); /** extract login information from the property file */
    pass = loginfo.get("pass");

    try { /** Usage of Try catch handlers */
        String currentURL;
        Iterator<String> iter = urls.iterator();
        System.out.println(iter);

        while (iter.hasNext()) { /** Start iterating over URLs */

            currentURL = iter.next();
            StringTokenizer st = new StringTokenizer(currentURL,
                    "/."); /**
                             * The string tokenizer class allows an
                             * application to break a string into tokens
                             */
            st.nextToken();
            String filePrefix = st.nextToken();
            System.out.println("Url: " + currentURL);

            boolean moreFilesAvailable = true; /**
                                                 * check condition for all
                                                 * log files available in
                                                 * the server
                                                 */

            for (int i = 0; moreFilesAvailable; i++) {

                File file = null;

                if (i != 0) { /** Handle the condition */
                    URLObj = new URL(currentURL + filename + "." + i);

                } else {
                    URLObj = new URL(currentURL + filename);

                }

2 个答案:

答案 0 :(得分:0)

您需要使用 -D

将文件属性的路径传递给jvm
-Dname=$pathto yourjar anyargs..

你可以在你的申请中得到它:

String location = System.getProperty(name);

答案 1 :(得分:0)

你应该能够像其他任何一样去做。请参阅有关如何生成jar文件的信息:Java creating .jar file