4

I'm very new to java. starting from yesterday! i installed eclipse and imported spring libraries inside it. but a weird problem happened. in import statement there was an error telling The type org.springframework.context.ApplicationContext is not accessible. after running the project another error happened (related to same subject ApplicationContext cannot be resolved to a type).

Anyway! i was confused. it took one day for me. searching forums such as stackoverflow and googling didn't resolve my problem. suddenly i saw a popup message in eclipse suggesting some solutions. ignoring some worthless one of them was adding module to module-info.java file. unbelievably that solved the problem! strangest thing was that i never saw this solution in related forums! and most annoying thing is that what if i never saw that popup? where did i do a mistake? and why this solution doesn't exist on the internet?

Lots of thanks!

Amin.Qarabaqi
  • 661
  • 7
  • 19
  • 1
    Possible duplicate of [How to get Eclipse to stop asking to create a module-info java file on new Java project creation?](https://stackoverflow.com/questions/52158125/how-to-get-eclipse-to-stop-asking-to-create-a-module-info-java-file-on-new-java) – Hassam Abdelillah Aug 28 '19 at 13:56
  • 1
    thanks! I think although questions are related but they are different. – Amin.Qarabaqi Aug 28 '19 at 14:15
  • 1
    [JPMS](https://en.wikipedia.org/wiki/Java_Platform_Module_System) (= having a `module-info.java` file) is one way of modularization (resolved at compile time in contrast to OSGi where modules/bundles can be started and stopped at run time). When using JPMS, you can build via `jlink` a Java application with an embedded Java VM with a minimal instead of the whole system library. This saves some disk space and the application starts a bit faster. If you don't use `jlink`, the only advantage is that you explicitly define the dependencies, preventing accidental using classes from unwanted modules. – howlger Aug 28 '19 at 15:04
  • 1
    Related: https://stackoverflow.com/questions/11844829/why-project-jigsaw-jpms – Mark Rotteveel Aug 28 '19 at 17:46
  • Now i have another problem with classpath. likely eclipse doesn't add libraries to classpath? I don't know. now i'm trying to change my IDE to IntelliJ. Hope solve! – Amin.Qarabaqi Aug 29 '19 at 06:34
  • 1
    @Amin.Qarabaqi When using JPMS (= having a `module-info.java` file) you have to add libraries to the modulepath, not to the classpath. JPMS is optional. I recommend deleting the `module-info.java` file. If necessary, you can create it again later. – howlger Aug 29 '19 at 14:50
  • @howlger Thank you. i solved the problem via throwing away the eclipse and installing IntelliJ. first time worked! – Amin.Qarabaqi Aug 30 '19 at 07:42
  • @Amin.Qarabaqi In this case, please delete your question as it adds no value for anyone. – howlger Aug 30 '19 at 08:37
  • I tried to delete. but the site doesn't allow me. due to others time and effort invested on this question. – Amin.Qarabaqi Aug 30 '19 at 16:37

1 Answers1

3

Java modules are a new feature of Java 9; they allow you to specify exactly which dependencies you need for your program, hence allowing greater control of the size of your application - no need to bring along library code you don't use. That seems to imply that you need to explicitly say what you want, I guess so that you realise that you are pulling in more modules.

So the reason that you don't see much information about modules in general is that they are comparatively new and doubt that I'm alone in being a long-standing Java developer who has never seen a module-info file!

I wonder whether Eclipse gave you some options when you were creating your project and you inadvertently took an option meaning "yes I want the extra control of doing mocules and I don't mind doing a bit more work."

djna
  • 54,992
  • 14
  • 74
  • 117
  • 2
    Eclipse does have a 'create module-info file' option in the new Java project wizard. Unfortunately it is hidden way on the second page of the wizard and is easy to miss. It defaults to creating the file. – greg-449 Aug 28 '19 at 14:55