The jar tool currently allows the main class to be set to a class that does not exist in the JAR file. The bug may be limited to the case where the JAR file does not contain any classes in named packages. Here's an example where the error is caught at runtime rather than at packaging time.
cat > module-info.java << EOF
module m { }
EOF
javac module-info.java
jar --create --file foo.jar module-info.class
jar --update --file foo.jar --main-class p.Main
$ java -p foo.jar -d m
Error occurred during initialization of boot layer
java.lang.module.FindException: Error reading module: foo.jar
Caused by: java.lang.module.InvalidModuleDescriptorException: Package p not found in module
cat > module-info.java << EOF
module m { }
EOF
javac module-info.java
jar --create --file foo.jar module-info.class
jar --update --file foo.jar --main-class p.Main
$ java -p foo.jar -d m
Error occurred during initialization of boot layer
java.lang.module.FindException: Error reading module: foo.jar
Caused by: java.lang.module.InvalidModuleDescriptorException: Package p not found in module