0

I have a java project built with maven and jdk 1.8. Some classes use javax.naming.* and javax.xml.* classes in the jdk. From Java 9 onwards those javax packages have been removed from the jdk. So how do I upgrade the project to run on java 9 or later?

Here are the classes,

import javax.naming.Binding;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NameClassPair;
import javax.naming.NameParser;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.NoInitialContextException;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.ModificationItem;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import javax.naming.event.EventContext;
import javax.naming.event.EventDirContext;
import javax.naming.event.NamingListener;
import javax.naming.ldap.Control;
import javax.naming.ldap.ExtendedRequest;
import javax.naming.ldap.ExtendedResponse;
import javax.naming.ldap.LdapContext;
import javax.naming.spi.InitialContextFactory;
import javax.naming.spi.InitialContextFactoryBuilder;
import javax.naming.spi.NamingManager;
import javax.xml.namespace.QName;

I have found out jndi contains javax.naming.* classes. But I am not sure how to include them. Just adding as a maven dependency does not work.

tharinduwijewardane
  • 2,593
  • 2
  • 16
  • 28
  • 6
    1. I would suggest if you're planning to upgrade, try out Java 11(LTS). 2. You shall share what exact classes as well. – Naman Sep 29 '18 at 11:57
  • updated my question. I think this question is valid for java 11 as well – tharinduwijewardane Sep 29 '18 at 12:02
  • 4
    You are possibly looking for migration guide from Java9 https://docs.oracle.com/javase/9/migrate/toc.htm#JSMIG-GUID-F7696E02-A1FB-4D5A-B1F2-89E7007D4096 ... But with that entire list of classes, you might end up looking at different sections of the release notes as well. – Naman Sep 29 '18 at 12:10
  • I have found out jndi (https://mvnrepository.com/artifact/javax.naming/jndi/1.2.1) contains javax.naming.* classes. But I am not sure how to include them. Just adding as a maven dependency does not work. – tharinduwijewardane Sep 29 '18 at 12:14
  • 2
    The java.naming and java.xml modules have not been removed. If you have an existing project that makes use of the APIs exported by these modules then you should find that it compiles and run as before, no changes. So I'm puzzled by the question and just wonder if, by chance, you've migrated an existing project to a module have have forgotten `requires java.naming` and `requires java.xml`. – Alan Bateman Sep 29 '18 at 12:21
  • I am not using java modules. This is an old java 8 project and i am just trying to get it to run on 10 – tharinduwijewardane Sep 29 '18 at 12:23
  • JNDI has been part of the JRE since 1.4. It is not a separate thing. – user207421 Mar 21 '19 at 22:55

1 Answers1

1

These classes have not been removed, see the JavaDoc for javax.naming and javax.xml.namespace. Unless you are building a module and forgot to add the modules java.xml and java.naming as dependencies, the mistake lies outside of Java, most likely with the tooling.

To convince yourself, compile a simple class on the command line with javac and watch it work. Then make sure you are running recent versions of the involved tools (particularly build tool and IDE). If that's the case and the error persists, improve your question with a more detailed description of the error.

Nicolai Parlog
  • 47,972
  • 24
  • 125
  • 255