首页 文章

java - Jar文件无法在另一台PC上执行

提问于
浏览
-2

我有一个可编程的jar文件,我从我的程序编译,我在我的电脑上运行它 . 当我在命令提示符下使用 java -jar [nameofjar.jar] 运行它时它完全正常工作

但是,我尝试在另一台电脑上测试它 . 使用命令提示符运行相同的jar文件,它会抛出一个错误:

D:\QA06122018_2>java -jar Indexing.jar
java.lang.NullPointerException
        at IndexDriver.processText(IndexDriver.java:81)
        at IndexDriver.index(IndexDriver.java:140)
        at Main.main(Main.java:44).....

两台PC都使用相同的操作系统和设置 . 我甚至查看了有关错误的代码,似乎没有任何问题 . 在我的IDE上运行得很好 .

有什么我可能会被忽视的吗?

编辑:

代码 :

public PreparedStatement preparedStatement = null;

     MysqlAccessIndex con = new MysqlAccessIndex();
        public Connection con1 = con.connect();
        String path1;


        public void index() throws Exception {
               // Connection con1 = con.connect();
                try {


                    Statement statement = con1.createStatement();

                    ResultSet rs = statement.executeQuery("select * from filequeue where Status='Active' LIMIT 5");


                    while (rs.next()) {
                        // get the filepath of the PDF document
                         path1 = rs.getString(2);
                       int getNum = rs.getInt(1);

                        Statement test = con1.createStatement();
                        test.executeUpdate("update filequeue SET STATUS ='Processing' where UniqueID="+getNum);



                        try {
                            // call the index function




                            PDDocument document = PDDocument.load(new File(path1),MemoryUsageSetting.setupTempFileOnly());

                            if (!document.isEncrypted()) {

                                PDFTextStripper tStripper = new PDFTextStripper();

                                for(int p=1; p<=document.getNumberOfPages();++p) {
                                    tStripper.setStartPage(p);
                                    tStripper.setEndPage(p);
                                    try {
                                        String pdfFileInText = tStripper.getText(document);
                                        processText(pdfFileInText);
                                        System.out.println("Page  "+p+" done");
                                    }catch (Exception e){
                                        e.printStackTrace();
                                        Statement statement1 = con1.createStatement();
                                        statement1.executeUpdate("update filequeue SET Error ='E0003' where UniqueID="+getNum);
                                        statement1.executeUpdate("update filequeue SET Status ='Error' where UniqueID="+getNum);
                                      con1.commit();
                                      con1.close();
                                    }
                                }


                                }







                            // After completing the process, update status: Complete
                            Statement pre= con1.createStatement();
                            pre.executeUpdate("update filequeue SET STATUS ='Complete' where UniqueID="+getNum);

                           // con1.commit();

                            preparedStatement.close();



                           document.close();

                            System.out.println("Successfully commited changes to the database!");
                            con1.commit();
                           // con1.close();
                           // updateComplete_DB(getNum);
                        } catch (Exception e) {

                            try {
                                System.err.println(e);


                                Statement statement1 = con1.createStatement();
                                statement1.executeUpdate("update filequeue SET STATUS ='Error' where UniqueID="+getNum);
                                statement1.executeUpdate("update filequeue SET Error ='E0002' where UniqueID="+getNum);

                                con1.commit();
                                // add rollback function
                                rollbackEntries();


                            }catch (Exception e1){
                                System.out.println("Could not rollback updates :" + e1.getMessage());
                            }
                        }

                                 //  con1.close();
                    }

                }catch(Exception e){

            e.printStackTrace();
                   //System.out.println("lalala");

                }
        //con1.commit();
         con1.close();

            }

调用方法:

public void processText(String text) throws SQLException {

    String lines[] = text.split("\\r?\\n");
    for (String line : lines) {
        String[] words = line.split(" ");


        String sql="insert IGNORE into  test.indextable values (?,?);";


        preparedStatement = con1.prepareStatement(sql);
        int i=0;
        for (String word : words) {

            // check if one or more special characters at end of string then remove OR
            // check special characters in beginning of the string then remove
            // insert every word directly to table db
            word=word.replaceAll("([\\W]+$)|(^[\\W]+)", "");
            preparedStatement.setString(1, path1);
            preparedStatement.setString(2, word);

              preparedStatement.executeUpdate();

 }





    }
    preparedStatement.close();

}

1 回答

  • 1

    根本原因是没有要处理的线 .

    您似乎只在 for (String line : lines) { 循环内创建预准备语句 . 但是你只关闭你创建的最后一个语句(在该循环之外) .

    如果没有任何行, preparedStatement 为null,因为您从未创建过任何行 .

    即使你有要处理的行,你也要创建许多准备好的语句,但只关闭最后一个 .

    您应该在方法的开头创建一个预准备语句,并将其重用于整个方法,最后将其关闭 .

相关问题