0

There is a legacy but working application running on an old machine. I rebuilt it with existing Ant file. I put it on a new machine, and when I run the JAR file, I get this:

Exception in thread "main" java.lang.IllegalStateException: Cannot load configuration class: test.mybooker.config.ApplicationConfig
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:378)
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:263)
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:265)
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:126)
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:609)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
        at test.mybooker.batchjobs.RunJob.main(RunJob.java:48)
Caused by: java.lang.ExceptionInInitializerError
        at org.springframework.cglib.core.KeyFactory$Generator.generateClass(KeyFactory.java:166)
        at org.springframework.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
        at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
        at org.springframework.cglib.core.KeyFactory$Generator.create(KeyFactory.java:144)
        at org.springframework.cglib.core.KeyFactory.create(KeyFactory.java:116)
        at org.springframework.cglib.core.KeyFactory.create(KeyFactory.java:108)
        at org.springframework.cglib.core.KeyFactory.create(KeyFactory.java:104)
        at org.springframework.cglib.proxy.Enhancer.<clinit>(Enhancer.java:69)
        at org.springframework.context.annotation.ConfigurationClassEnhancer.newEnhancer(ConfigurationClassEnhancer.java:112)
        at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:100)
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:368)
        ... 6 more
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,ja                va.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @774bd0a2
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
        at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:200)
        at java.base/java.lang.reflect.Method.setAccessible(Method.java:194)
        at org.springframework.cglib.core.ReflectUtils$2.run(ReflectUtils.java:56)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
        at org.springframework.cglib.core.ReflectUtils.<clinit>(ReflectUtils.java:46)
        ... 17 more

What does it mean? What is likely the cause and how can I solve this?

Inside the ANT script, I have build defined as such:

    <target name="build" description="Compile main source tree java files and move needed resources">
        <mkdir dir="${build.dir}" />
        <javac destdir="${build.dir}" source="1.8" target="1.8" failonerror="true" debug="${compile.debug}">
            <src path="${src.dir}" />
            <classpath refid="master-classpath" />
        </javac>
        <copy todir="${build.dir}">
            <fileset dir="${res.dir}" />
        </copy>
    </target>

The source and target versions are 1.8. The JRE version to run the ANT script is JDK-18.0.1. Does that matter to this issue?

user2526586
  • 972
  • 2
  • 12
  • 27
  • 2
    cause: `module java.base does not "opens java.lang" to unnamed module @774bd0a2` - search this site for "module does not opens", maybe one of the [1k+ questions/answers](https://stackoverflow.com/search?q=%5Bjava%5D+module+does+not+opens) can help || I *vaguely* remember using the `--add-opens=...` [option](https://docs.oracle.com/en/java/javase/18/docs/specs/man/java.html#extra-options-for-java) – user16320675 Jul 14 '22 at 08:41
  • [Understanding Java 9 Modules](https://www.oracle.com/il-en/corporate/features/understanding-java-9-modules.html) article by Paul Deitel in Oracle Java Magazine, September/October 2017 issue. – Abra Jul 14 '22 at 08:54
  • @Abra If I rebuild it for, say, target JRE 8, would that solve the problem straight away? – user2526586 Jul 14 '22 at 09:07
  • Yes. Java 8 is the last Java version before the introduction of modular Java. – Abra Jul 14 '22 at 13:32
  • @Abra According to the Ant script, I think I have been building it for target Java 8 already – user2526586 Jul 14 '22 at 14:31
  • @user16320675 Could it be the JRE that runs the JAR, even if the JAR was built of target for Java 8? What I don't understand about the mentioned "Java 9 version", is that, does "the version" mean the application Java target version, the version of JDK that builds the application, or the version that the JRE runs the application? Or something else? – user2526586 Jul 15 '22 at 14:00
  • See https://stackoverflow.com/questions/15492948/javac-source-and-target-options I suspect you need to set the bootclasspath in the compile. – martin clayton Jul 26 '22 at 09:40

0 Answers0