Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8174694

improve error message shown when main class can't be loaded

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2
    • Resolution: Fixed
    • Affects Version/s: 8, 9
    • Fix Version/s: 9
    • Component/s: tools
    • Labels:
      None
    • Environment:

      Running JDK 9 EA build 156 on OS X 10.11.6

    • Subcomponent:
    • Resolved In Build:
      b158
    • CPU:
      x86
    • OS:
      iOS
    • Verification:
      Verified

      Backports

        Description

        When trying to run a jar on an image that does not contain all required modules, instead of a helpful error message I get:

        /img/bin/java -jar ./JDK9ModularJar/anagrams.jar
        Error: Could not find or load main class com.toy.anagrams.ui.Anagrams

        When trying to launch as a module I get a more understandable error:

        ./img/bin/java --module-path ./JDK9ModularJar -m AnagramGame
        Error occurred during initialization of VM
        java.lang.module.ResolutionException: Module java.desktop not found, required by AnagramGame
        at java.lang.module.Resolver.fail(java.base@9-ea/Resolver.java:850)
        at java.lang.module.Resolver.resolve(java.base@9-ea/Resolver.java:155)
        at java.lang.module.Resolver.resolveRequires(java.base@9-ea/Resolver.java:117)
        at java.lang.module.Configuration.resolveRequiresAndUses(java.base@9-ea/Configuration.java:311)
        at java.lang.module.ModuleDescriptor$1.resolveRequiresAndUses(java.base@9-ea/ModuleDescriptor.java:2522)
        at jdk.internal.module.ModuleBootstrap.boot(java.base@9-ea/ModuleBootstrap.java:278)
        at java.lang.System.initPhase2(java.base@9-ea/System.java:1928)

        Steps to reproduce:
        1) Create a modular jar that requires more than java.base, in my example I used the Anagram game sample from Netbeans.
        2) Use jlink to create a runtime that only includes the base module
        3) Try to run the jar with the custom image specifying it as a jar, not as a module.

        Expected: Some error saying that required modules XYZ are not found, similar to the error displayed if I try to launch the jar as a module.

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                vromero Vicente Arturo Romero Zaldivar
                Reporter:
                agarciar Aurelio Garcia-Ribeyro
                Votes:
                0 Vote for this issue
                Watchers:
                8 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: