question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't use wildcards in IJAVA_CLASSPATH option

See original GitHub issue

I’m using IJava to explore some Java libraries that I want to familiarise myself with, and it’s working out really well for me so far. However, I came upon a minor issue when pointing the IJava classpath to multiple libraries in multiple .jar files stored in the same directory.

Explicitly pointing to the individual .jar files in kernel.json works perfectly:

"IJAVA_CLASSPATH" : "/path/to/lib/Lib1.jar:/path/to/lib/Lib2.jar:/path/to/lib/Lib3.jar"

However, it is possible to use wildcards in Java classpaths to point to multiple .jar files in one directory. For example, this works for me when launching jshell:

jshell --class-path "/path/to/lib/*"

However, if I try to similarly use a wildcard in kernel.json,

"IJAVA_CLASSPATH" : "/path/to/lib/*"

then IJava reports that it does not work:

|   import path.to.class.ClassName;
package path.to.class does not exist

It’s a small issue with an easy workaround (explicitly pointing to all the libraries), but I thought I’d report it regardless.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
SpencerParkcommented, Jun 17, 2018

Related to this, there is now a magic %jars that can be used to add jars to the classpath at runtime (also using this glob syntax). See magics.md for more information about that.

1reaction
SpencerParkcommented, May 26, 2018

Hi @erlendviggen, thanks for reporting the issue.

I’ve been playing around with various options in the JShell API but unfortunately I can’t get anything to do the expansion. Little disappointed that addToClasspath doesn’t do this so it looks like we will have to handle it ourselves.

The wildcard patterns that classpath usually supports are very restricted (just a single * to match a directory and nothing after it) so it shouldn’t be too difficult to implement. But since we are going to implement it we can go one step better and just support glob syntax (getPathMatcher).

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use a wildcard in the classpath to add multiple jars?
Class path entries can contain the basename wildcard character * , which is considered equivalent to specifying a list of all the files...
Read more >
JDK-7146424 Wildcard expansion for single entry classpath
2600] A DESCRIPTION OF THE PROBLEM : Wildcard expansion doesn't work correctly for -classpath (-cp) parameter when only one entry is specified. REGRESSION. ......
Read more >
Setting the class path
The CLASSPATH environment variable is not treated any differently from the -classpath (or -cp ) command-line option. That is, wildcards are honored in...
Read more >
[JDK-7146424] Wildcard expansion for single entry classpath
A DESCRIPTION OF THE PROBLEM : Wildcard expansion doesn't work correctly for -classpath (-cp) parameter when only one entry is specified. ... option[...
Read more >
Class-Path Wildcards in Mustang | Mark Reinhold
lib CP=$LIB/foo.jar:$LIB/bar.jar:$LIB/baz.jar java -classpath $CP ... we figured that anyone clever enough to use class-path wildcards would ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found