我有一个简单的Java控制台应用程序,其中使用Jasypt1.9.2进行数据库连接字符串的加密。该代码在Eclipse中运行良好,但是导出为Jar的应用程序给出此错误
这是我简单的Main类:
public static void main (String args[])
{
try {
GetConnection config = new GetConnection();
out = config.getLogFile();
System.out.println("Start");
Interface.writeLine(out, "Start");
while (true) {
new Interface().ProcessProcedure();
new Interface().ProcessKTP();
new Interface().TransferToPRF();
System.out.println("End");
Thread.sleep(90000);
}
}
catch (java.lang.Exception ex) {
System.out.println("Error:"+ex);
}
}
这是我的GetConnection类
public Connection getSql(BufferedWriter out){
try{
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
prop = new EncryptableProperties(encryptor); //--fOR ENCRYPTED PASSWORD
String fileName = System.getProperty("user.dir") + "\\configuration.properties";
InputStream is = new FileInputStream(fileName);
//InputStream inputStream;
if (is != null) {
prop.load(is);
} else {
throw new FileNotFoundException("Configuration property not found");
}
String Driver = prop.getProperty("sqlserver.driver");
String url = prop.getProperty("sqlserver.durl");
String id = prop.getProperty("sqlserver.uid");
key = "123"
encryptor.setPassword(key);
String sqlpass = prop.getProperty("sqlserver.pass").trim();
Class.forName(Driver).newInstance();
Connection conMSSQL = DriverManager.getConnection (url,id,sqlpass);
if(conMSSQL != null && conMSSQL.isValid(0)) {
GetConnection.writeLine(out,"Connection established");
}
return conMSSQL;
}
catch( Exception ex ){
GetConnection.writeLine(out,"Exception at Kondor connection");
GetConnection.writeLine(out,ex.getMessage());
return null;
}
}
我已经检查并验证了Jasypt1.9.2.jar条目的类路径。
请帮忙。
最佳答案
NoClassDefFoundError
表示JVM尝试访问一个类但未找到它。
您已将项目导出到JAR文件,而没有导出依赖关系。
从eclipse导出时选择package
或repack
选项。
这会将依赖项添加到导出的JAR文件中。