There are two way to add modules to jshell.
Add module at the time of launching jshell
Syntax
jshell --add-modules module1 module2 …. moduleN
Example
jshell --add-modules java.logging
Add module using /env command
Syntax
env --add-modules module1 module2 …. moduleN
Example
/env --add-modules java.logging
Follow below steps to add logging module and work with it.
Step 1: Open terminal and execute the command jshell.
$jshell
| Welcome to JShell -- Version 10.0.2
| For an introduction type: /help intro
jshell>
Step 2: Add logging module by executing below command.
/env --add-modules java.logging
jshell> /env --add-modules java.logging
| Setting new options and restoring state.
jshell>
Step 3: Import logging package by executing below command.
import java.util.logging.*;
Step 4: Get an instance of Logger by executing below statement.
Logger logger = Logger.getLogger("demo");
Step 5: Use methods of Logger to log the information.
jshell> import java.util.logging.*;
jshell> Logger logger = Logger.getLogger("demo");
logger ==> java.util.logging.Logger@887af79
jshell> logger.info("Hello World")
Apr 28, 2020 12:31:10 PM REPL.$JShell$13 do_it$
INFO: Hello World
No comments:
Post a Comment