5

JShell is a REPL for Java. To use additional classes outside the default JRE it contains a /classpath command to add a path to the current classpath.

Is there however a way to view the current classpath within the JShell environment?


Note that I'm using the following early release:

java version "9-ea"
Java(TM) SE Runtime Environment (build 9-ea+111)
Java HotSpot(TM) 64-Bit Server VM (build 9-ea+111, mixed mode)
Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263
  • 2
    Did you try `System.getProperty("java.class.path")`? – Maroun Apr 07 '16 at 13:06
  • @MarounMaroun `-> System.out.println(System.getProperty("java.class.path"))` returns `-Xdebug`. Something tells me they're not there yet :) Thanks for the idea though, fully skipped my mind. – Maarten Bodewes Apr 07 '16 at 13:26
  • That's what I also get, looks like they're indeed not there yet.. Meanwhile I'm trying to find a workaround. – Maroun Apr 07 '16 at 13:29
  • Did a lot of things to the classpath, but I seem only to be able to run classes that are in the boot class path. – Maarten Bodewes Apr 07 '16 at 13:49
  • @MarounMaroun This indeed seems to be a bug. Then again, I can see the class path using your method and a workaround. I can still not load any Java 8 compiled classes using this classpath though. Furthermore, I don't seem to be able to change it either, so I cannot confirm it shows the updates classpath. *I would expect it to use a different class loader*, but I'm not sure. – Maarten Bodewes Apr 07 '16 at 16:17
  • Try System.out.println(System.getProperty("java.class.path")) with "build 118 on 05-12-2016 (#4987)". It works. – B. S. Rawat May 16 '16 at 22:31
  • @B.Singh Does it include paths that have been added using `/classpath`? – Maarten Bodewes May 16 '16 at 22:44
  • It doesn't assign the newly added in to "java.class.path" variable but it finds the added one. See below: jshell> /classpath C:\temp\websocket-server-9.3.8.v20160314.jar | Path 'C:\temp\websocket-server-9.3.8.v20160314.jar' added to classpath jshell> import org.eclipse.jetty.websocket.server.WebSocketHandler; – B. S. Rawat May 18 '16 at 16:16

1 Answers1

3

The /env command, without arguments, will list your environmental settings, including classpath.

Sᴀᴍ Onᴇᴌᴀ
  • 8,218
  • 8
  • 36
  • 58
Robert Field
  • 479
  • 4
  • 5