Migrating from Jena1 to Jena 2
Jena 2 supports the Jena 1 API. However a number of changes have been made that will cause existing code not to run out of the box. The Jena team expect that there will be tools to help with the migration of Jena 1 code, but they don't exist yet, as we are not encouraging folks to migrate.
The changes are conceptually minor, mostly just renaming things into a more sensible pattern.
What Must be changed:
package renaming:
- com.hp.hpl.mesa.rdf.jena.model -> com.hp.hpl.jena.rdf.model
- com.hp.hpl.mesa.rdf.jena.vocabulary -> com.hp.hpl.jena.vocabulary
new model factory:
- Models in Jena 1 were created using new on the model class. With Jena 2 there is factory for creating new models com.hp.hpl.jena.rdf.model.ModelFactory. Use that instead of new. If for some reason you don't want to do that, the memory model class has moved to com.hp.hpl.jena.mem.
iterators now implement java.util.iterator
- which means the .next() method returns an Object rather than a typed object. You need to either cast the return from the .next() method to the appropriate type or use the .nextType() (where Type is Resource, Literal, Ns, RDFNode or Statement depending on the iterator) to avoid casting.
What Should be Changed
new SimpleSelector
- SelectorImpl was the only case (other than creating models - see above) where applications had to use a specific implementation class rather than a class defined in the API. A new SimpleSelector class has been added into the API package. This is a clone of the old SelectorImpl class. The old class still exists in the com.hp.hpl.jena.rdf.model.impl package so existing code won't break with the right import, but moving to the new class is encouraged. The old one will eventually be deprecated.
*Impl classes
- Some folks have used some of the implementation classes directly instead of using the factory methods provided in, e.g. Model. We are tidying up the javadoc so that the implementation classes are no longer so visible. Rather than renaming the import, it would be better to switch to using the factory methods. However, the *Impl classes still exist, and if you need a quick fix, many of them can be found in com.hp.hpl.jena.rdf.model.impl.