我创建了一个 maven 项目,并且我已经编写了数周的应用程序并希望最终运行它......但我不能。
执行我的 .jar 时,我得到以下堆栈跟踪:
C:\Users\MyUser\.m2\repository\com\myCompany\MyApp\
0.0.1-SNAPSHOT> java -Dconfigfile=config.xml -jar MyApp-0.0.1-SNAPSHOT.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/configuration/ConfigurationException
at com.mycompany.connector.DBConnector.reloadDBSettings(DBConnector.java:23)
at com.mycompany.connector.DBConnector.<clinit>(DBConnector.java:16)
at com.mycompany.connector.DBConnectorFactory.createDBConnector(DBConnectorFactory.java:17)
at com.mycompany.service.MyAppService.<clinit>(MyAppService.java:38)
at com.mycompany.main.MyAppMain.init(MyAppMain.java:13)
at com.mycompany.main.MyAppMain.main(MyAppMain.java:8)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.configuration.ConfigurationException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more
org.apache.commons.configuration.ConfigurationException 被导入到类中,我设置 Maven 将其用作依赖项。我究竟做错了什么?
顺便说一句:这是我的 reloadDBSettings 方法:
import java.io.FileNotFoundException;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;
public final class ConfigurationHandler {
private static XMLConfiguration config;
/**
* to reload Configuration-File if necessary
*/
public static void reloadConfig() throws FileNotFoundException {
try {
config = new XMLConfiguration(System.getProperty("configfile"));
} catch (ConfigurationException e) {
throw new FileNotFoundException("Es wurde keine Konfiguration geladen - Überprüfen Sie die Systemvariable 'configfile'(" + e.getMessage() + ")");
}
}
}