I have a maven project when i need to parse abig rdf file.
my code is :
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();
}
}
}
The code word fine for small file but with big file i get the following excpetion
JAXP00010001: The parser has encountered more than "64000" entity expansions in this document; this is the limit imposed by the JDK
In eclipse i run the project by click on run>>runconfiguration>>argument then set in VM argument -DentityExpansionLimit=1000000.i get the a new excpetion due to memory limit:
the Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
so the max heap i can set is small to what the file needs. So I want to execute my code on a server. Usually i compile and run my maven on the server by:
mvn compile
mv exec:java
My question: i set -DentityExpansionLimit=5000000 in maven by
mvn -DentityExpansionLimit=5000000 exec:java
but i get a original exception :
[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]
how can solve this issue?
By using
mvn -Djdk.xml.totalEntitySizeLimit=0 -DentityExpansionLimit=0 exec:java
i solved my issue. Hope that will help