View classpath in jshell - java

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)

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

Related

Don't see java version 14 in command prompt

I installed jdk-14.0.1_windows-x64_bin.exe from https://www.oracle.com/java/technologies/javase-jdk14-downloads.html.
I added C:\Program Files\Java\jdk-14.0.1\bin to my PATH and JAVA_HOME variables.
After this I start a new command prompt and type java -version, and I see the list below, but I don't see java version "14.0.1", why not?
java version "1.8.0_251" Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)
I already checked this post.
when you add a new version of Java to your PATH to use it as default you should also make sure that it is the only one in your PATH.
in this case, you already had Java 8 in your PATH and it was being used as default instead of the new Java 14, so the solution is to remove Java 8 from the PATH.

set the CLASSPATH

I am using Mac os Sierra 10.12.3 ,I want to execute the byte code on the Java(TM) Virtual Machine
(JVM) I need to set the CLASSPATH,
Using my terminal
CLASSPATH=</Users/.../Documents/jj2000/jj2000-4.1\ 3>/jj2000-4.1.jar:$CLASSPATH export CLASSPATH
show me
-bash: /jj2000-4.1.jar:: Permission denied
I am confusing with command line how can I set the CLASSPATH.
My java is
java version "1.8.0_20-ea"
Java(TM) SE Runtime Environment (build 1.8.0_20-ea-b20)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b20, mixed mode)
Please help.
Don't, ever, set a global CLASSPATH environment variable. Pass the classpath to each java program you launch: each one has its own, specific classpath.
java -cp /path/to/jj2000-4.1.jar:your-application.jar com.yourcompany.youapp.Main

Cannot find SNIServerName class

I am working with SSL connections using javax.net.ssl.HttpsURLConnection. I upgraded from java 1.7 to java 1.8. I need to set SNI host names in SSLParameters using javax.net.ssl.SSLParameters.setServerNames(List<SNIServerName> serverNames). But the compiler cannot resolve the class SNIServerName. The compiler displays this error:
unable to resolve class javax.net.ssl.SNIServerName
My java version:
java version "1.8.0_121" Java(TM) SE Runtime
Environment (build 1.8.0_121-b13) Java HotSpot(TM) 64-Bit Server VM
(build 25.121-b13, mixed mode)
How do I import SNIServerName or SNIHostName? AFAIK they have been introduced in Java 8. Is there an issue with my java version?
Just make sure that your JAVA_HOME is correctly configured. Just follow the steps mentioned below
vim ~/.bashrc
JAVA_HOME = <path to your java8 bin>
PATH = $JAVA_HOME:$PATH
save this and then
source ~/.bashrc
after this just verify by $JAVA_HOME on your terminal.

Java - Mac os x - two versions

I recently updated my java version to "Java 8 update 77".
As far as i know, this is the newest version...
My Java Control Panel prints the same information,
but when i switch to terminal to verify the java version:
java -version
it outputs:
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
When i type:
/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -version
it prints correctly:
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)
So, did i anything wrong?
Why are there two different versions listed ?
Thanks and Greetings!
When Java is updated, it doesn't override the older version. It keeps the older version and also installs new version.
You have to change your $JAVA_HOME environment variable if you want to use new version.
This Link May help
Open the terminal. Type...
nano ~/.bash_profile
Search for export JAVA_HOME. When you find the line, comment it out by placing a # in front of the line.
Type on the next line...
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home
assuming that is where the jdk is. Press ctrl+o, ctrl+x.
Type source ~/.bash_profile. And you should be all set.
The second option that you have written about is where you are checking the java applet plugin version which does not need to be the same as the jdk runtime environment.
To make your .bash_profile future proof, you can try this
export JAVA_HOME="$(/usr/libexec/java_home)"

Ignore Java.exe from Path and use the one from directory I am in

I setup Java 6 to be used by all other application. Normal setup with JAVA_HOME, JRE_HOME, etc. This is working fine.
I have another application that needs Java 7. I downloaded Java 7.exe and extraced tools.zip from it to a folder. Now I am trying to check the version going to the bin folder. When I type in java -version, I get the following error.
error occurred during initialization of vm
java/lang/noclassdeffounderror java/lang/object
where as java -fullversion shows Java 7. It looks like even though I am in the bin folder where Java.exe exists, it still getting the one from PATH?!?!
How do I use the java.exe from a folder ignoring the one from PATH?
You need much more than java to run java. You need all the rt.jar and lib which come with Java. It sounds like you are missing some part of the JRE or it can't find your JRE.
I suggest you re-install the version you need and run it using the full path name like
c:\>"c:\Program Files\Java\jdk1.7.0_60\bin\java" -version
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)
c:\>"c:\Program Files\Java\jdk1.8.0_45\bin\java" -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
By using the full path name you can use any specific version from any directory.

Categories

Resources