9

I have a project that uses Java webstart technology. I decided to upgrade the Java version from 8 to 9. However, I faced the following error on compiling:

error: package javax.jnlp is not visible
import javax.jnlp.DownloadServiceListener;
        ^
(package javax.jnlp is declared in module java.jnlp, which is not in the module graph)

I tried to include C:\Program Files\Java\jdk-9\lib\javaws.jar to the classpath, but still the same issue remains.

Eng.Fouad
  • 115,165
  • 71
  • 313
  • 417
  • Did you add `requires javaws;` to your `module-info.java`? If so could you add the build version and your module-info.java file please. – Naman Jul 31 '17 at 16:00
  • 1
    @nullpointer I was not using `module-info.java` at all. All other packages were included by default except `javaws`. I think the reason behind this is what @Nicolai explained in his answer. Anyway, the problem has been resolved by using modules. Thanks – Eng.Fouad Jul 31 '17 at 17:45
  • Similar: [*“package javax.xml.soap is declared in module java.xml.ws, which is not in the module graph”*](https://stackoverflow.com/q/46084302/642706) – Basil Bourque Jul 23 '18 at 00:19

2 Answers2

10

It looks like java.jnlp is not resolved by default for code on the class path (much like Java EE modules). The solution is to add it explicitly with --add-modules java.jnlp (both javac and java accepts that parameter).

This option is discussed in JEP 261: Module System or in this blog post.

Nicolai Parlog
  • 47,972
  • 24
  • 125
  • 255
  • 4
    Nicolai is correct, more details in "Root modules" section of JEP 261. The original question also mentioned lib/javaws.jar - that JAR file is used when JDK 8 or older releases use the deploy bits in JDK 9, it's not intended to be used on the class path. – Alan Bateman Jul 31 '17 at 22:55
  • `--add-modules xxxx` is not a **solution**, it is a **workaround**. – Honza Zidek Sep 19 '18 at 14:25
0

In IntelliJ IDEA: Add javaws.jar to Classpath(File -> Project Structure -> SDKs ->Class) C:\Program Files\Java\jdk-version\lib\javaws.jar

Dave Wang
  • 71
  • 1
  • 4