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

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);

                }

您需要使用 -D

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

您可以像这样在您的应用程序中获取它:

String location = System.getProperty(name);

您应该能够像其他人一样做到这一点。有关如何生成 jar 文件的信息,请参见:Java creating .jar file