繁体   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