OWLOntology ontology1 = manager.createOntology(IRI
.create(importsBothNameAndVersion));
OWLOntology ontology2 = manager.createOntology(IRI
.create(importsBothNameAndOther));
List<AddImport> changes = new ArrayList<>();
changes.add(new AddImport(ontology1, factory
.getOWLImportsDeclaration(IRI.create(ontologyByName))));
changes.add(new AddImport(ontology1, factory
.getOWLImportsDeclaration(IRI.create(ontologyByVersion))));
changes.add(new AddImport(ontology2, factory
.getOWLImportsDeclaration(IRI.create(ontologyByName))));
changes.add(new AddImport(ontology2, factory
.getOWLImportsDeclaration(IRI.create(ontologyByOtherPath))));
manager.applyChanges(changes);
manager.saveOntology(ontology1, IRI.create(importsBothNameAndVersion));
manager.saveOntology(ontology2, IRI.create(importsBothNameAndOther));
// when