6

I have built a Spring Boot application with Java 9 ... sourceCompatibility = 9 targetCompatibility = 9 ... and started it with: java --module-path lib -m my.app. ...

    Caused by: java.lang.NoClassDefFoundError: java/sql/SQLException
        at spring.beans@5.0.2.RELEASE/org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:161)
        at spring.boot@2.0.0.M7/org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:436)
        ... 5 more
Caused by: java.lang.ClassNotFoundException: java.sql.SQLException
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
        at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
        ... 7 more

Note: I have launched the application sucessfully using classpath instead of --module-path

Edit: Thank you for your advices! Finally, I have found a "magic mix" to start application. I have modified command line, removed javax.transaction-api-1.2.jar from lib and placed it on classpath to remove package (javax.transaction.xa) splitting conflict between modules java.sql and javax.transaction.api

java --module-path lib --add-modules java.sql,java.instrument,java.xml.bind -cp javax.transaction-api-1.2.jar -m my.app
zncoder
  • 61
  • 1
  • 3
  • 4
    can you show us the module info definitions ? – Barath Dec 17 '17 at 06:44
  • 2
    Additionally, do edit your question with the complete command used to startup the application for both the classpath way and the modulepath way? Would also be good to know the version of spring boot in use. – Naman Dec 17 '17 at 07:22
  • 4
    Is spring.beans an automatic module? I assume the issue is that no module `requires java.sql` so the java.sql module is not in the set of modules that are resolved as startup (run with --show-module-resolution to check this). This is difficult area with automatic modules, you will sometimes need to use `--add-modules` to force additional explicit modules to be resolved. In this case, you will need `--add-modules java.sql` as no module requires it and so it will not be resolved. – Alan Bateman Dec 17 '17 at 07:42
  • @Barath there is no module definition - automatic module. – zncoder Dec 17 '17 at 15:21
  • @nullpointer command line for module path is in the original post. In order to start with cp I used standard bat, that had been created by installDist gradle task. The version of spring boot is in the stack trace. – zncoder Dec 17 '17 at 15:24
  • 1
    @zncoder since you are reading those as automatic modules, Alan's suggestion of using `--add-modules java.sql` should help. As I said, the complete commands are yet not visible in the question. Would be good to see what works and what doesn't in terms of commands. – Naman Dec 17 '17 at 15:26
  • @AlanBateman You are right. This is automatic module. I tried --add-module java.sql - the same error. – zncoder Dec 17 '17 at 15:27
  • 2
    Can you show the entire command? (Just checking that you put the `--add-modules` before the `-m` or `--module` option). – Alan Bateman Dec 17 '17 at 16:00
  • @AlanBateman, Thank you for hint. After I placed --add-modules before -m, original error disappeared. Now I have a problem with package splitting: "java.lang.module.ResolutionException: Modules java.sql and javax.transaction.api export package javax.transaction.xa to module com.fasterxml.jackson.core" – zncoder Dec 18 '17 at 09:40
  • I removed javax.transaction-api-1.2.jar from lib folder, hence from module path: "java.lang.ClassNotFoundException: java.lang.instrument.ClassFileTransformer". Now, it is time to find module, that contains "ClassFileTransformer" and try the same procedure, as with sqlexception. – zncoder Dec 18 '17 at 10:28
  • ClassFileTransformer is in java.instrument module ->NoClassDefFoundError: javax/transaction/SystemException. It looks I need to add some modules to --add-modules. – zncoder Dec 18 '17 at 10:32
  • 1
    If you run `jdeps` on the spring.boot JAR file then it will help you identify the modules that spring.boot requires. Alternatively, use `--add-modules java.se`. As regards javax.transaction-api-1.2.jar, there is a Maintenance Release of JSR 907 in progress that proposes to drop the javax.transaction.xa package. Java SE has provided the xa package since Java SE / JDK 1.4 so few will notice if the Java EE version of JTA drops it. – Alan Bateman Dec 18 '17 at 10:40
  • @AlanBateman, Thank you for information. So, after JSR 907 is applied, I will return javax.transaction-api-1.2.jar from classpath to module path. – zncoder Dec 18 '17 at 11:20

0 Answers0