17

I use OSGI and this is the main reason that I want to disable modules, as I really don't need another module framework. Is it possible to do it, for example using command line option? If yes, then how?

Pavel_K
  • 10,748
  • 13
  • 73
  • 186
  • generic questions are not well-suited for SO. Please kindly consider being more specific – blurfus Sep 05 '17 at 19:26
  • You want to disable module and still be able to use other features introduced in Java 9? – syntagma Sep 05 '17 at 19:42
  • 2
    This was termed as a ["big kill switch"](https://youtu.be/CMMzG8I23lY?t=5m14s) by Simon in one of the conferences and describes the backward compatibility. – Naman Sep 06 '17 at 04:04
  • @nullpointer Thank you - it is every useful info. But I get `Unrecognized option: --permit-illegal-access Error: Could not create the Java Virtual Machine.` Is this switch supported in java 9? – Pavel_K Sep 06 '17 at 07:08
  • the whole java is redesigned for modulize in java 9 through proejct Jigsaw, you don't need to care much about it now for your existing code. one of its big issue before is that can't access internal java class. but changed as "Proposal (revised): Allow illegal access to internal APIs by default in JDK 9", see: http://mail.openjdk.java.net/pipermail/jigsaw-dev/2017-June/012841.html – Ben Xu Sep 06 '17 at 14:36

2 Answers2

11

There is no option to turn off the module system - it will always be active. This impacts access to JDK-internal APIs, dependencies on Java EE modules, Split packages, and a lot of other small details. Your code and your dependencies have to deal with those migration challenges if you want your application to run on Java 9.

You are by no means forced to create modules, though. You can completely ignore module-info.java and continue to place all your JARs onto the class path. The module system will silently bundle them all into the unnamed module, which was created for maximum compatibility. You won't even notice the module system is there (assuming you've overcome the challenges I described earlier).

Nicolai Parlog
  • 47,972
  • 24
  • 125
  • 255
  • 1
    How do you ignore module-info.java in an Eclipse SWT project? – Steve Dec 26 '19 at 19:07
  • I don't know about the details of Eclipse SWT, but, generally speaking, if you don't create `module-info.java` files yourself, your build tool should only use the class path, where all `module-info.class` files in your dependencies are ignored. – Nicolai Parlog Dec 29 '19 at 07:46
  • 1
    I have a problem where default system libraries are conflicting with dependencies in this "unnamed" module. – Cardinal System Feb 03 '21 at 18:14
  • @CardinalSystem I recommend you open a new question for that (if you didn't already) - feel free to leave a link here, so I can take a look. – Nicolai Parlog Feb 09 '21 at 08:11
5

Yes surely you can as the interviewee said here

Trisha Gee: Many people don’t realize you can use Java 9 and all its shiny new features WITHOUT using Jigsaw, i.e. you can use Java 9 very happily without migrating any of your code. There are some things which have changed in Java 9 (e.g. hiding away internal APIs) but theoretically, if your application was doing all the right things to begin with, there should be no problem compiling and running with Java 9.

have a look for the entire interview but As you saw we will have two types for Java Applications one for modular world and another for non-module system that's why Red Hat and IBM voted no for JSR 376 as mentioned here but they vote okay after that!

for more about Java 9 Module System with OSGI have a look here

Hope this is useful

Anas
  • 688
  • 7
  • 24
  • 1
    +1 for initial important information. But I don't accept it as it has no answer to more important part - `If yes, then how?` – Pavel_K Sep 05 '17 at 20:19
  • @Pavel_K this is what all I knew at this moment, I just read articles and blogs waiting for the final release (:- I think you will need to use JVM options to disable it and for more info have a look [here](https://docs.oracle.com/javase/9/migrate/toc.htm#JSMIG-GUID-7BB28E4D-99B3-4078-BDC4-FC24180CE82B) – Anas Sep 05 '17 at 20:41
  • Just to sum this up: there was an option "--illegal-access=permit". But this was removed in Java 17. – wknauf Dec 29 '21 at 19:55