简体   繁体   English

无法编译和运行基于xerces的Java程序

[英]Unable to compile and run xerces based Java program

I have a Java program, where I am using Apache xerces.jar for parsing XML files. 我有一个Java程序,在这里我使用Apache xerces.jar来解析XML文件。 I am running into an error, where the error here is: 我遇到一个错误,这里的错误是:

javac -classpath ":." MyParser.java
MyParser.java:4: error: package org.apache.xerces.parsers does not exist
import org.apache.xerces.parsers.*;
^

I have tried various options like the below: 我尝试了以下各种选项:

javac -classpath ":." MyParser.java
javac -cp ":." MyParser.java
javac -classpath ":xerces.jar" MyParser.java
javac -cp ":xerces.jar" MyParser.java
javac -classpath :. MyParser.java
javac -cp :. MyParser.java
javac -classpath :xerces.jar MyParser.java
javac -cp :xerces.jar MyParser.java

The main code I have that is causing the issue is: 我引起问题的主要代码是:

import org.apache.xerces.parsers.*;

I am able to perfectly compile this and run this in Netbeans IDE, but I am not able to achieve it using Command Line. 我能够完美地编译它并在Netbeans IDE中运行它,但是我无法使用命令行来实现它。 The main reason I am going for a command line is, using Netbeans, I am not able to parse a 250 MB file. 我要使用命令行的主要原因是,使用Netbeans,我无法解析250 MB的文件。 Does anyone have any idea about how to increase the stack / heap limit? 有谁知道如何增加堆栈/堆限制吗?

When I reduce the XML file to less than 10 KB I am able to parse it, but in the current scenario, I am getting this error in the Stack Trace. 当我将XML文件减少到小于10 KB时,我可以解析它,但是在当前情况下,我在堆栈跟踪中收到此错误。

org.xml.sax.SAXParseException; systemId: file:/C:/Users/user/Downloads/Project/Test/Parser/posts2.xml; lineNumber: 1; columnNumber: 1; The markup in the document preceding the root element must be well-formed.
    at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1318)
    at org.apache.xerces.framework.XMLDocumentScanner.reportFatalXMLError(XMLDocumentScanner.java:616)
    at org.apache.xerces.framework.XMLDocumentScanner$XMLDeclDispatcher.dispatch(XMLDocumentScanner.java:798)
    at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)
    at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1208)
    at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1247)
    at MyParser.main(MyParser.java:21)
BUILD SUCCESSFUL (total time: 0 seconds)

I believe this is because, the whole file is not getting read or it is reading a truncated file. 我相信这是因为,整个文件没有被读取或正在读取截断的文件。 Please help. 请帮忙。

Looks like the issue is with UTF-8 BOM. 看起来问题出在UTF-8 BOM。 Use a decent Hex Editor and remove the first three characters of UTF-8 BOM. 使用体面的十六进制编辑器并删除UTF-8 BOM的前三个字符。

EF BB B0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM