简体   繁体   English

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

[英]how to generate a jar file for the java program which has property file

how to generate a jar file for the java program which has property file 如何为具有属性文件的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);

                }

You need to pass the path to your file properties into a jvm using -D 您需要使用-D将文件属性的路径传递到jvm中

-Dname=$pathto yourjar anyargs..

you can get it in your application likethis : 您可以像这样在应用程序中获取它:

String location = System.getProperty(name);

You should be able to do it just like any other. 您应该能够像其他任何人一样去做。 See this on how to generate a jar file: Java creating .jar file 关于如何生成jar文件,请参见以下内容: Java创建.jar文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM