簡體   English   中英

我的JAR無法像通過Eclipse啟動時那樣工作

[英]My JAR doesnt work as when launched by eclipse

我的程序使用大文本文件(45MB)進行操作,並且在Eclipse中運行良好。 導出到jar中后,在訪問大型源文件時它無法正常工作。 小文件沒有問題(300kB)

Eclipse:凍結10秒鍾,然后准備加載文件。

Jar:凍結5秒,沒有任何反應。

為了使JAR正常運行,我應該進行哪些更改?

編輯:

public String [] RetreiveTokens(){
    String path = Main_Win.class.getProtectionDomain().getCodeSource().getLocation().getPath();
    String decodedPath = null;
    try {
        decodedPath = URLDecoder.decode(path, "UTF-8");
    } catch (UnsupportedEncodingException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    String FileName=decodedPath+"languages/D3.txt";//LangPath+SourceFileLists.get(i);

    String content = null;
    boolean DictCC = false;
    int ContentsAddress=0;
    try {

        BufferedReader fin;

        String lineFromFile="";
        try {
            fin = new BufferedReader(new FileReader(FileName));
            //System.out.println("cc");
            lineFromFile = fin.readLine();
            lineFromFile=lineFromFile.substring(3);
            if(lineFromFile.substring(0,1).equals("#")){
                DictCC=true;
                for(ContentsAddress=0; fin.readLine().length()>0; ContentsAddress++);
                ContentsAddress+=2;
                //System.out.println(ContentsAddress);
            }
            fin.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        //System.out.println(lineFromFile);
        //if(!DictCC){
        content = new Scanner ( new File (FileName), "UTF-8").useDelimiter("\\Z").next();
        //}
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    String[] tokens=null;
    //String[][] Words_1=new String[2][32];;

    if(!DictCC){
        content=content.substring(1);
        content=content.replace("\r\n\r\n", "\r\n");
        tokens = content.split("\r\n");
    }
    else {
        content = content.split("\r\n")[ContentsAddress];
        tokens = content.split("    ");
    }

    for (int t=0; t<tokens.length; t++){
        if(tokens[t].contains("\n")){
            int index = nthOccurrence(tokens[t], '\n', 0);
            tokens[t]=tokens[t].substring(index);
        }
        if(tokens[t].contains("[")){
            tokens[t]=tokens[t].replace(" [", "[");
            tokens[t]=tokens[t].replace("] ", "]");
            tokens[t]=tokens[t].replaceAll("\\[.*\\]", "");
        }
        if(tokens[t].contains("<")&&tokens[t].contains(">")){
            tokens[t]=tokens[t].replace(" <", "<");
            tokens[t]=tokens[t].replace("> ", ">");
            tokens[t]=tokens[t].replaceAll("\\<.*\\>", "");
        }
        tokens[t]=tokens[t].replaceAll("[?¿!¡,.;/'{}]", "");
        tokens[t]=tokens[t].replace("\n", "").replace("\r", "");

    }
    return tokens;
}

我認為您的問題是堆內存不足。 您通過雙擊其jar運行該應用程序,因此將使用沒有STDOUT和STDERR的javaw

打開命令提示符,然后通過鍵入java -jar yourjar.jar來運行您的應用程序,其中yourjar.jar是jar的實際路徑。

您將看到OutOfMemoryError 現在您應該增加內存。 將參數-Xmx2048M添加到您的執行路徑,即:

java -Xmx2048M -jar yourjar.jar

我希望這將有所幫助。 如果找不到更好的數字。 顯然,這一行意味着您的應用程序將能夠使用多達2G的堆。

現在的問題是“為什么需要那么多內存?” 嘗試檢查您的代碼,看看會發生什么。 可能是您將整個文件讀到了內存中? 你需要這個嗎? 等等。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM