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

Add support to read classpath from the CLASSPATH environment variable #256

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

andirady
Copy link

Some workflows doesn't use maven, gradle or bazel. This PR allows the user to declare the CLASSPATH environment variable.

@brown
Copy link
Contributor

brown commented May 29, 2023

Setting an explicit Java classpath is currently supported via the java.classPath JSON initialization parameter. I too use the language server with Java source code that is not compiled using Maven, Gradle, or Bazel. When I do, I configure my editor to supply the language server with a classpath and documentation path using java.classPath and java.docPath. By using JSON to make these settings, I can work on more than one project at a time in my editor, with each running language server receiving the right classpath for the project it is handling.

@andirady
Copy link
Author

andirady commented Jun 2, 2023

Setting an explicit Java classpath is currently supported via the java.classPath JSON initialization parameter. I too use the language server with Java source code that is not compiled using Maven, Gradle, or Bazel. When I do, I configure my editor to supply the language server with a classpath and documentation path using java.classPath and java.docPath. By using JSON to make these settings, I can work on more than one project at a time in my editor, with each running language server receiving the right classpath for the project it is handling.

Sometimes I just want to write a single file which is to be run using java source launcher. Or I can have the classpath stored in a file and I can use it like so:

export CLASSPATH=`cat classpath.txt`
vim hello.java

and in the hello.java, I can have the following:

///usr/bin/env java -cp `cat classpath.txt` $0 $@; exit
class myScript {
   /* ... */
}

If the lang server have support for CLASSPATH environment variable, I don't have to create a separate file.

@georgewfraser
Copy link
Owner

Can you please add a test @andirady ?

@andirady
Copy link
Author

andirady commented Jul 6, 2023

Can you please add a test @andirady ?

Done.

The behavior is, when it's a simple project and CLASSPATH is specified, it'll read from that environment variable,
if the project uses a build tool, it's up to the build tool to handle the CLASSPATH.

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

Successfully merging this pull request may close these issues.

3 participants