java file 其他电脑上,java - Jar文件无法在另一台PC上执行

用户报告一个可编程的jar文件在本地计算机上通过命令行正常运行,但在另一台相同配置的计算机上运行时抛出NullPointerException。错误发生在`IndexDriver.processText`和`IndexDriver.index`方法中。代码片段显示了数据库连接和处理PDF文本的部分,但没有明显的问题。问题可能涉及外部资源,如数据库连接或依赖的文件路径。
摘要由CSDN通过智能技术生成

我有一个可编程的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();

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值