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

What is the executable for Linux? #5

Open
fhuonder opened this issue May 20, 2021 · 2 comments
Open

What is the executable for Linux? #5

fhuonder opened this issue May 20, 2021 · 2 comments

Comments

@fhuonder
Copy link

Hi

What do I have to configure for the google-java-format.executable-path for linux?
There is no apt or snap package of the google-java-format. Only the JAR file.

Regards,
Florian

@crdrost
Copy link

crdrost commented Jun 4, 2021

Great question!

Given a JAR you'll want to provide a script to glue the two together. For example on my OSX I have the google-java-format installed in ~/.local/lib and a script at ~/.local/bin/google-java-format which contains

#!/bin/bash
export JAVA_HOME="${JAVA_HOME:-/usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home}"
exec "${JAVA_HOME}/bin/java" \
  --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
  --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
  --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
  --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
  --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \
  -jar "/Users/crdrost/.local/lib/google-java-format-1.10.0-all-deps.jar" "$@"

Of course that first line won't work for you directly but,

  • fill in the appropriate paths for your distro
  • fill in your JAVA_HOME and your path/to/google-java-format.jar
  • don't forget the hashbang line up-top , the --add-exports are only for if you're running on newer JDKs (see below)
  • and don't forget to chmod +x the file,

and then Linux will treat it like any other executable.

Be aware also that it's in the code of ilkka/vscode-google-java-format that if anything appears on stderr then the file won't be reformatted. This bit me with an Illegal Reflective Access notification, which is why I added all of the --add-exports lines above (see the google-java-format v1.10.0 release notes).

@lucidfrontier45
Copy link

I suggest you use GraalVM to create a native binary. It is easier to use and has much less startup overhead.
I created build scripts and also hosted prebuild binary for Windows and Linux x86_64.
https://github.com/lucidfrontier45/google-java-format-native

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

3 participants