当我需要解析abig rdf文件时,我有一个maven项目。
我的代码是:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.model.Statement;
import org.eclipse.rdf4j.model.impl.LinkedHashModel;
import org.eclipse.rdf4j.rio.RDFFormat;
import org.eclipse.rdf4j.rio.RDFHandlerException;
import org.eclipse.rdf4j.rio.RDFParseException;
import org.eclipse.rdf4j.rio.RDFParser;
import org.eclipse.rdf4j.rio.RDFWriter;
import org.eclipse.rdf4j.rio.Rio;
import org.eclipse.rdf4j.rio.helpers.StatementCollector;
public class ConvertOntology {
public static void main(String[] args) throws RDFParseException, RDFHandlerException, IOException {
// TODO Auto-generated method stub
String file = "C:\\Users\\user\\Desktop\\fileA.rdf";
File initialFile = new File(file);
InputStream input = new FileInputStream(initialFile);
RDFParser parser = Rio.createParser(RDFFormat.RDFXML);
parser.setPreserveBNodeIDs(true);
Model model = new LinkedHashModel();
parser.setRDFHandler(new StatementCollector(model));
parser.parse(input, initialFile.getAbsolutePath());
FileOutputStream out = new FileOutputStream("C:\\Users\\user\\Desktop\\fileB.rdf");
RDFWriter writer = Rio.createWriter(RDFFormat.RDFXML, out);
try {
writer.startRDF();
for (Statement st: model) {
writer.handleStatement(st);
}
writer.endRDF();
}
catch (RDFHandlerException e) {
// oh no, do something!
}
finally {
out.close();
}
}
}
该代码字适用于小文件,但对于大文件,我得到以下称呼
JAXP00010001: The parser has encountered more than "64000" entity expansions in this document; this is the limit imposed by the JDK
在eclipse中,我通过单击run >> runconfiguration >>参数来运行项目,然后在VM参数-DentityExpansionLimit = 1000000中进行设置。由于内存限制,我得到了一个新的专有名词:
the Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
因此,我可以设置的最大堆大小小于文件所需的大小。所以我想在服务器上执行我的代码。通常,我通过以下方式在服务器上编译并运行我的Maven:
mvn compile
mv exec:java
我的问题: 我通过
在Maven中设置-DentityExpansionLimit = 5000000mvn -DentityExpansionLimit=5000000 exec:java
但是我得到一个原始的异常:
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project rdf4j-getting-started: An exception occured while executing the Java class. null: InvocationTargetException: JAXP00010004: The accumulated size of entities is "50,000,018" that exceeded the "50,000,000" limit set by "FEATURE_SECURE_PROCESSING". [line 1, column 34] -> [Help 1]
如何解决这个问题?
答案 0 :(得分:1)
使用mvn -Djdk.xml.totalEntitySizeLimit=0 -DentityExpansionLimit=0 exec:java
解决了我的问题。希望对您有帮助
答案 1 :(得分:0)
根据documentation,您可以使用负值删除限制。