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

[BUG] cli doesn't support JAVA_HOME, requires the java executable to be on the PATH #661

Closed
ardc-shorn opened this issue Sep 1, 2022 · 2 comments · Fixed by #756
Closed
Assignees
Labels
bug Something isn't working released

Comments

@ardc-shorn
Copy link
Contributor

ardc-shorn commented Sep 1, 2022

🐛 Bug Report:

Describe the bug

When running openapi-generator-cli via NPM script:
Error: 'java' is not recognized as an internal or external command, operable program or batch file.

Steps to Reproduce

Have a clean operating system, with no Java installation.

"Install" the JDK by downloading and then unzipping the portable zip archive, then set JAVA_HOME to that location.

Expected behavior

Like all other tooling in the Java ecosystem, openapi-generator-cli should try to execute the JDK via $JAVA_HOME/bin/java before falling back to looking for the java executable on the path.

Operation System (please complete the following information):

  • OS: Windows (problem exists on any other OS too)
  • Version 2.5.1

Package System (please complete the following information):

  • whatever NPM comes by default with Node.js 16.17.0

Additional context

This is a problem for developers working in more complex environments where they might need to work on multiple separate projects that require different JDK versions. It's not viable to always be swapping the global path between different JDK installations.

This is actually a thing in the Node ecosystem too, you can (and people do) install and run Node via a portable archive, without adding the node / npm executables to the global path.

If JAVA_HOME support is added, the readme should be updated to reflect that users don't necessarily need to have java on their PATH any more.

@ardc-shorn ardc-shorn added the bug Something isn't working label Sep 1, 2022
@ardc-shorn
Copy link
Contributor Author

Workaround

Use a different tool to invoke openapi-generator, that does support JAVA_HOME.

I use Gradle, with wrapper for the gradlew script and the org.openapi.generator Gradle plugin to call the OpenAPI Generator. Then hook it up to your NPM project via pre scripts:

    "generate-api": "../gradlew openApiGenerate",
    "prestart": "npm run generate-api",
    "start":  "react-scripts start",
    "prebuild": "npm run generate-api",
    "build": "react-scripts build",

adnbrownie added a commit to adnbrownie/openapi-generator-cli that referenced this issue Jan 6, 2023
wing328 pushed a commit that referenced this issue Mar 3, 2024
* support JAVA_HOME environment variable

fixes  #661

* test(generator-cmd): add consideration of the JAVA_HOME variable

* docs: add instructions for the use of JAVA_HOME

* fix: add quotes to accept spaces in the JAVA_HOME path

* fix: add quotation marks only for windows paths

---------

Co-authored-by: Nils Braune <78608305+adnbrownie@users.noreply.github.com>
Copy link

github-actions bot commented Mar 3, 2024

🎉 This issue has been resolved in version 2.10.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

mok-liee added a commit to mok-liee/openapi-generator-cli that referenced this issue Mar 12, 2024
* support JAVA_HOME environment variable

fixes  OpenAPITools#661

* test(generator-cmd): add consideration of the JAVA_HOME variable

* docs: add instructions for the use of JAVA_HOME

* fix: add quotes to accept spaces in the JAVA_HOME path

* fix: add quotation marks only for windows paths

---------

Co-authored-by: Nils Braune <78608305+adnbrownie@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
2 participants