JAXP00010004 and java.lang.OutOfMemoryError: GC overhead limit exceeded
JAXP00010004 and java.lang.OutOfMemoryError: GC overhead limit exceeded
当我需要解析一个大的 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 i 运行 项目中点击 运行>>运行configuration>>argument 然后在 VM 参数中设置 -DentityExpansionLimit=1000000.i 得到一个由于内存限制的新异常:
the Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
所以我可以设置的最大堆比文件需要的小。所以我想在服务器上执行我的代码。通常我通过以下方式在服务器上编译和 运行 我的 maven:
mvn compile
mv exec:java
我的问题:
我通过
在 maven 中设置 -DentityExpansionLimit=5000000
mvn -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]
如何解决这个问题?
根据 documentation,您可以使用负值来移除限制。
通过使用 mvn -Djdk.xml.totalEntitySizeLimit=0 -DentityExpansionLimit=0 exec:java
我解决了我的问题。希望能有所帮助
当我需要解析一个大的 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 i 运行 项目中点击 运行>>运行configuration>>argument 然后在 VM 参数中设置 -DentityExpansionLimit=1000000.i 得到一个由于内存限制的新异常:
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]
如何解决这个问题?
根据 documentation,您可以使用负值来移除限制。
通过使用 mvn -Djdk.xml.totalEntitySizeLimit=0 -DentityExpansionLimit=0 exec:java
我解决了我的问题。希望能有所帮助