我正试图从小时开始解决问题。我写了一个简单的应用程序来加载一个xml文件,修改它们并将更改写回来。它一直有效,直到我将项目转换为maven项目。我不确定这是不是问题。我无法理解异常
这是我的DOM-parser的代码部分:
import java.io.File;
import java.io.IOException;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import **.***.Notification.*;
public class TomcatVM implements ViewModel{
Document tomcatDoc;
Node shutdownPortNode = null;
Node portNode = null;
private StringProperty port = new SimpleStringProperty();
private StringProperty shutdownPort = new SimpleStringProperty();
private BooleanProperty tomcatService = new SimpleBooleanProperty();
private String fullTomcatPropPath = new String();
private StringProperty path = new SimpleStringProperty();
public void init() {
NotificationCenter.getDefaultNotificationCenter().addObserverForName(Notification.LOAD_NOTIFICATION.toString(), new NotificationObserver() {
@Override
public void receivedNotification(final String arg0, final Object... arg1) {
// TODO Auto-generated method stub
File tomcatXmlFile = new File(getFullTomcatPropPath());
if(tomcatXmlFile != null){
try{
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
System.out.println("got: "+getFullTomcatPropPath());
System.out.println("path: "+tomcatXmlFile.getPath());
tomcatDoc = dBuilder.parse(tomcatXmlFile);
tomcatDoc.getDocumentElement().normalize();
if(tomcatDoc != null){
shutdownPortNode = tomcatDoc.getElementsByTagName("Server").item(0).getAttributes().getNamedItem("port");
portNode = tomcatDoc.getElementsByTagName("Connector").item(0).getAttributes().getNamedItem("port");
// tomcatShutdownPortTextField.setText(shutdownPortNode.getTextContent());
setPort(portNode.getTextContent());
setShutdownPort(shutdownPortNode.getTextContent());
}
}catch(Exception e){
e.printStackTrace();
}
}
}
});
NotificationCenter.getDefaultNotificationCenter().addObserverForName(Notification.SAVE_NOTIFICATION.toString(), new NotificationObserver() {
/*
* write changes from the interface to the doc file for
* the tomcat-xml file and overwrite the old tomcat-xml
*/
@Override
public void receivedNotification(final String arg0, final Object... arg1) {
portNode.setTextContent(getPort().toString());
shutdownPortNode.setTextContent(getShutdownPort().toString());
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer;
try {
transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(tomcatDoc);
StreamResult result = new StreamResult(new File(getFullTomcatPropPath()));
enter code here // ******here is the exception: *******
transformer.transform(source, result);
} catch (TransformerConfigurationException e) {
e.printStackTrace();
} catch (TransformerException e) {
e.printStackTrace();
}
}
});
}
public String getFullTomcatPropPath() {
return fullTomcatPropPath;
}
public void setFullTomcatPropPath(final String fullTomcatPropPath) {
this.fullTomcatPropPath = fullTomcatPropPath;
}
}
这就是我得到的例外情况:
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at javafx.scene.Node.fireEvent(Unknown Source)
at javafx.scene.control.Button.fire(Unknown Source)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(Unknown Source)
at com.sun.javafx.scene.control.skin.SkinBase$4.handle(Unknown Source)
at com.sun.javafx.scene.control.skin.SkinBase$4.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at javafx.scene.Scene$MouseHandler.process(Unknown Source)
at javafx.scene.Scene$MouseHandler.process(Unknown Source)
at javafx.scene.Scene$MouseHandler.access$1900(Unknown Source)
at javafx.scene.Scene.impl_processMouseEvent(Unknown Source)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.notifyMouse(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(Unknown Source)
at com.sun.glass.ui.win.WinApplication$3$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.Trampoline.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
... 53 more
Caused by: java.lang.AbstractMethodError: org.apache.xerces.dom.DeferredDocumentImpl.getXmlStandalone()Z
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.setDocumentInfo(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
at **.*****.***.***.database.DatabaseVM$3.receivedNotification(DatabaseVM.java:238)
我没有为dom-parser的pom.xml添加任何依赖项。 SAME CODE正在另一个项目中运行,唯一的区别是,我得到异常的项目是maven项目。如果我注释掉该行,我在另一个保存其他xml文件的类上得到了异常。所以我觉得tomcat不是问题吗? 有人有想法吗? :/
提前致谢!
答案 0 :(得分:3)
在没有maven的独立项目中,您是否包含任何罐子/进口?如果相同的确切代码在那里工作,但不是在maven中它会让我相信你有一个依赖性错误。
尝试将此依赖项添加到pom.xml:xercesImpl.jar
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.11.0</version>
</dependency>