Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closure-compiler-v20240317 '(class file version 55.0)` and closure-compiler-unshaded-v20240317 'no main manifest attribute' using Java 8u431 #4208

Open
rioj7 opened this issue Jan 5, 2025 · 3 comments

Comments

@rioj7
Copy link

rioj7 commented Jan 5, 2025

Following the Getting Started with the Closure Compiler Application page I installed Java Version 8 Update 431 (64-bit) for Windows 11. Installed on disk in the confusing directory C:\Program Files\Java\jre1.8.0_431

Getting the latest closure-compiler from Maven repository (closure-compiler-v20240317.jar)

Running with

java -jar closure-compiler-v20240317.jar -js somefile.js --compilation_level ADVANCED_OPTIMIZATIONS

I get the error

Exception in thread "main" java.lang.UnsupportedClassVersionError:
    com/google/javascript/jscomp/CommandLineRunner has been compiled by a more recent version of the Java Runtime (class file version 55.0),
    this version of the Java Runtime only recognizes class file versions up to 52.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

Looking at some other issues I found that there is also a closure-compiler-unshaded version. Searching on Maven I downloaded closure-compiler-unshaded-v20240317.jar

Running with

java -jar closure-compiler-unshaded-v20240317.jar -js somefile.js --compilation_level ADVANCED_OPTIMIZATIONS

I get the error

no main manifest attribute, in /path/to/closure-compiler-unshaded-v20240317.jar

If I go back a few versions I can use the v20211201 without error.

What is the difference between closure-compiler and closure-compiler-unshaded?

Why does closure-compiler-v20240317 have a main manifest attribute but closure-compiler-unshaded-v20240317 not?

How to run closure-compiler with JavaRE 8u431?

Fixing the missing main manifest attribute in closure-compiler-unshaded-v20240317 results in a java.lang.ClassNotFoundException exception.
Even going back to 2013 that line, if present in the jar MANIFEST, is

Main-Class: com.google.javascript.jscomp.CommandLineRunner
@niloc132
Copy link
Contributor

niloc132 commented Jan 6, 2025

Note that Java 11 or newer is required at this time to run closure-compiler - see https://github.com/google/closure-compiler/wiki/FAQ#What-version-of-Java-is-required.

The unshaded jar isn't suitable for running directly via java -jar path/to/closure... - since the jar is not shaded, there are missing dependencies that will be absent when you run this way. Even if you added them and specified the main class, you still could not run on Java 8.

@rioj7
Copy link
Author

rioj7 commented Jan 7, 2025

@niloc132 Why do I need to download the JDK to just run a Java program? Java is notorious for version numbering confusion.

The JDK current version is named Java 23.

The latest release of JRE (Runtime) is Java 8 Update 431 (2024-10-15)

I may assume that JRE 8_u431 has the same JVM as JDK 23/22.

@niloc132
Copy link
Contributor

niloc132 commented Jan 7, 2025

I'm afraid that assumption is wrong - there is no more "JRE" as of Java 9 - instead the JDK (which includes everything in the JRE) is provided and can be used as a JRE. Alternatively, some applications will use the jlink tool to produce a standalone executable, including on the parts of the JDK that the application uses. Typically, this will be a subset of the JRE that was shipped prior to Java 9.

Some older versions of Java continue to be supported by some maintainers - notably, 8, 11, 17, and 21 at this time.

As my link indicates, at this time closure-compiler can run on Java 11+, so you need a version of Java (that is, a JDK) at least that new.

In theory you could run jlink yourself to let the closure-compiler run standalone, but the closure-compiler project does not do that for you. There are however "native" builds of closure-compiler that are available, using Graal - but these must be made per OS/platform, and it is technically possible that your own computer might not have a build appropriate to it. In that case, the tooling that uses these native builds will download the jar file, and will need an appropriate Java version to run it on. See https://github.com/google/closure-compiler-npm/blob/master/packages/google-closure-compiler/README.md for more information on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants