Start shell/REPL without launching java monitor?

Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Start shell/REPL without launching java monitor?

Tzu-Li Chen
Hi Groovy community,

I am new to Groovy and when running `groovysh` with "3.0.0-alpha-3, JVM: 1.8.0_171" on macOS, I see a, hmm, Java monitor(?), named "GroovyShell" launched.

If I kill it, process `groovysh` quit with exception below. I'd like to know if we can suppress the launch of "GroovyShell" process. It switch the focus of cursor and quite annoying for me.

Best,
tison.

[printStackTrace]:

➜  ~ groovysh
Groovy Shell (3.0.0-alpha-3, JVM: 1.8.0_171)
Type ':help' or ':h' for help.
-------------------------------------------------------------------------------
groovy:000> 2018-10-12 10:51:09.084 java[34387:1479007] java.lang.SecurityException: Use of System.exit() is forbidden!
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:59)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:238)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:250)
at org.codehaus.groovy.tools.shell.util.NoExitSecurityManager.checkExit(NoExitSecurityManager.groovy:51)
at java.lang.Runtime.exit(Runtime.java:107)
at java.lang.System.exit(System.java:971)
at com.apple.eawt._AppEventHandler.performQuit(_AppEventHandler.java:145)
at com.apple.eawt.QuitResponse.performQuit(QuitResponse.java:51)
at com.apple.eawt._AppEventHandler$_QuitDispatcher.performDefaultAction(_AppEventHandler.java:390)
at com.apple.eawt._AppEventHandler$_AppEventDispatcher.dispatch(_AppEventHandler.java:512)
at com.apple.eawt._AppEventHandler.handleNativeNotification(_AppEventHandler.java:202)

Reply | Threaded
Open this post in threaded view
|

Re: Start shell/REPL without launching java monitor?

Tzu-Li Chen
Any thoughts?

Tzu-Li Chen <[hidden email]> 于2018年10月12日周五 上午10:54写道:
Hi Groovy community,

I am new to Groovy and when running `groovysh` with "3.0.0-alpha-3, JVM: 1.8.0_171" on macOS, I see a, hmm, Java monitor(?), named "GroovyShell" launched.

If I kill it, process `groovysh` quit with exception below. I'd like to know if we can suppress the launch of "GroovyShell" process. It switch the focus of cursor and quite annoying for me.

Best,
tison.

[printStackTrace]:

➜  ~ groovysh
Groovy Shell (3.0.0-alpha-3, JVM: 1.8.0_171)
Type ':help' or ':h' for help.
-------------------------------------------------------------------------------
groovy:000> 2018-10-12 10:51:09.084 java[34387:1479007] java.lang.SecurityException: Use of System.exit() is forbidden!
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:59)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:238)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:250)
at org.codehaus.groovy.tools.shell.util.NoExitSecurityManager.checkExit(NoExitSecurityManager.groovy:51)
at java.lang.Runtime.exit(Runtime.java:107)
at java.lang.System.exit(System.java:971)
at com.apple.eawt._AppEventHandler.performQuit(_AppEventHandler.java:145)
at com.apple.eawt.QuitResponse.performQuit(QuitResponse.java:51)
at com.apple.eawt._AppEventHandler$_QuitDispatcher.performDefaultAction(_AppEventHandler.java:390)
at com.apple.eawt._AppEventHandler$_AppEventDispatcher.dispatch(_AppEventHandler.java:512)
at com.apple.eawt._AppEventHandler.handleNativeNotification(_AppEventHandler.java:202)

Reply | Threaded
Open this post in threaded view
|

Re: Start shell/REPL without launching java monitor?

Keith Suderman
In reply to this post by Tzu-Li Chen
Hi Tison,

I am not sure what you are asking... groovysh is the "Groovy Shell" so you should see a terminal window named "GroovyShell" launched that allows you to execute Groovy commands interactively.  This is the expected behaviour.  Or are you just pointing out the exception when quitting groovysh?  How did you kill groovysh?  With the Unix `kill` command (or Windows equivalent) or using one of the "exit" commands in the shell itself (:exit, :x, etc)?

I suspect you may simply want the `groovy` command that you can use to run Groovy scripts/programs. 

$ echo "println 'hello world'" > test.groovy
$ cat test.groovy
println 'hello world'
$ groovy test.groovy 
hello world

Hope this helps,
Keith

On Oct 11, 2018, at 10:54 PM, Tzu-Li Chen <[hidden email]> wrote:

Hi Groovy community,

I am new to Groovy and when running `groovysh` with "3.0.0-alpha-3, JVM: 1.8.0_171" on macOS, I see a, hmm, Java monitor(?), named "GroovyShell" launched.

If I kill it, process `groovysh` quit with exception below. I'd like to know if we can suppress the launch of "GroovyShell" process. It switch the focus of cursor and quite annoying for me.

Best,
tison.

[printStackTrace]:

➜  ~ groovysh
Groovy Shell (3.0.0-alpha-3, JVM: 1.8.0_171)
Type ':help' or ':h' for help.
-------------------------------------------------------------------------------
groovy:000> 2018-10-12 10:51:09.084 java[34387:1479007] java.lang.SecurityException: Use of System.exit() is forbidden!
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:59)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:238)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:250)
at org.codehaus.groovy.tools.shell.util.NoExitSecurityManager.checkExit(NoExitSecurityManager.groovy:51)
at java.lang.Runtime.exit(Runtime.java:107)
at java.lang.System.exit(System.java:971)
at com.apple.eawt._AppEventHandler.performQuit(_AppEventHandler.java:145)
at com.apple.eawt.QuitResponse.performQuit(QuitResponse.java:51)
at com.apple.eawt._AppEventHandler$_QuitDispatcher.performDefaultAction(_AppEventHandler.java:390)
at com.apple.eawt._AppEventHandler$_AppEventDispatcher.dispatch(_AppEventHandler.java:512)
at com.apple.eawt._AppEventHandler.handleNativeNotification(_AppEventHandler.java:202)




----------------------
Keith Suderman
Research Associate
Department of Computer Science
Vassar College, Poughkeepsie NY




Reply | Threaded
Open this post in threaded view
|

Re: Start shell/REPL without launching java monitor?

Tzu-Li Chen
Hi Keith,

Thanks for your reply! I think I know `groovy` command and now I exactly suffer from `groovysh`. Let me try to speak it clearly.

(on macOS)
1. I open a terminal.
2. Type "groovysh" and <CR>
3. A new window looks like a Java applet, named "Groovy Shell" launched, and the focus switch to it.
4. I switch the focus back to the terminal, and start to interact with REPL.

What I am suffering is 3 and 4, each time I want to interact with REPL I have to switch the focus. Think about `jshell` or `python`, the REPL is of course a process, but not another window and even force switch the focus.

Also photos in attach links, please pay attention to the focus is switched from 1 to 2.

Best,
tison.


Keith Suderman <[hidden email]> 于2018年10月15日周一 下午10:44写道:
Hi Tison,

I am not sure what you are asking... groovysh is the "Groovy Shell" so you should see a terminal window named "GroovyShell" launched that allows you to execute Groovy commands interactively.  This is the expected behaviour.  Or are you just pointing out the exception when quitting groovysh?  How did you kill groovysh?  With the Unix `kill` command (or Windows equivalent) or using one of the "exit" commands in the shell itself (:exit, :x, etc)?

I suspect you may simply want the `groovy` command that you can use to run Groovy scripts/programs. 

$ echo "println 'hello world'" > test.groovy
$ cat test.groovy
println 'hello world'
$ groovy test.groovy 
hello world

Hope this helps,
Keith

On Oct 11, 2018, at 10:54 PM, Tzu-Li Chen <[hidden email]> wrote:

Hi Groovy community,

I am new to Groovy and when running `groovysh` with "3.0.0-alpha-3, JVM: 1.8.0_171" on macOS, I see a, hmm, Java monitor(?), named "GroovyShell" launched.

If I kill it, process `groovysh` quit with exception below. I'd like to know if we can suppress the launch of "GroovyShell" process. It switch the focus of cursor and quite annoying for me.

Best,
tison.

[printStackTrace]:

➜  ~ groovysh
Groovy Shell (3.0.0-alpha-3, JVM: 1.8.0_171)
Type ':help' or ':h' for help.
-------------------------------------------------------------------------------
groovy:000> 2018-10-12 10:51:09.084 java[34387:1479007] java.lang.SecurityException: Use of System.exit() is forbidden!
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:59)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:238)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:250)
at org.codehaus.groovy.tools.shell.util.NoExitSecurityManager.checkExit(NoExitSecurityManager.groovy:51)
at java.lang.Runtime.exit(Runtime.java:107)
at java.lang.System.exit(System.java:971)
at com.apple.eawt._AppEventHandler.performQuit(_AppEventHandler.java:145)
at com.apple.eawt.QuitResponse.performQuit(QuitResponse.java:51)
at com.apple.eawt._AppEventHandler$_QuitDispatcher.performDefaultAction(_AppEventHandler.java:390)
at com.apple.eawt._AppEventHandler$_AppEventDispatcher.dispatch(_AppEventHandler.java:512)
at com.apple.eawt._AppEventHandler.handleNativeNotification(_AppEventHandler.java:202)




----------------------
Keith Suderman
Research Associate
Department of Computer Science
Vassar College, Poughkeepsie NY




Reply | Threaded
Open this post in threaded view
|

Re: Start shell/REPL without launching java monitor?

Keith Suderman
Ok, I see what you mean now.  I don't use groovysh enough for that to be an issue for me, but I wonder if the issue is the same on Windows machines? 

However, I see that the "inspect" command uses a Swing GUI and I suspect this is what is causing the issue.  I also see that the "inspect" command is disabled if Java is running in "headless" mode.  So a relatively simple work around is to set java.awt.headless=true in JAVA_OPTS before running groovysh. I.E.

$> export JAVA_OPTS=-Djava.awt.headless=true
$> groovysh

-or-

$> JAVA_OPTS=-Djava.awt.headless=true groovysh

-or-

$> alias gsh='JAVA_OPTS=-Djava.awt.headless=true groovysh'
$> gsh

Now the applet is not launched and doesn't steal the focus away from the terminal window.  However, I haven't tested the above (other to ensure the applet isn't started) so I don't know what else might be affected.

Hope this helps,
- Keith

On Oct 15, 2018, at 4:22 PM, Tzu-Li Chen <[hidden email]> wrote:

 1.png<img src="x-msg://ssl.gstatic.com/ui/v1/icons/common/x_8px.png" style="opacity: 0.55; cursor: pointer; float: right; position: relative; top: -1px; display: none;" class="">
 2.png<img src="x-msg://ssl.gstatic.com/ui/v1/icons/common/x_8px.png" style="opacity: 0.55; cursor: pointer; float: right; position: relative; top: -1px; display: none;" class="">
 diag.png<img src="x-msg://ssl.gstatic.com/ui/v1/icons/common/x_8px.png" style="opacity: 0.55; cursor: pointer; float: right; position: relative; top: -1px; display: none;" class="">
Hi Keith,

Thanks for your reply! I think I know `groovy` command and now I exactly suffer from `groovysh`. Let me try to speak it clearly.

(on macOS)
1. I open a terminal.
2. Type "groovysh" and <CR>
3. A new window looks like a Java applet, named "Groovy Shell" launched, and the focus switch to it.
4. I switch the focus back to the terminal, and start to interact with REPL.

What I am suffering is 3 and 4, each time I want to interact with REPL I have to switch the focus. Think about `jshell` or `python`, the REPL is of course a process, but not another window and even force switch the focus.

Also photos in attach links, please pay attention to the focus is switched from 1 to 2.

Best,
tison.


Keith Suderman <[hidden email]> 于2018年10月15日周一 下午10:44写道:
Hi Tison,

I am not sure what you are asking... groovysh is the "Groovy Shell" so you should see a terminal window named "GroovyShell" launched that allows you to execute Groovy commands interactively.  This is the expected behaviour.  Or are you just pointing out the exception when quitting groovysh?  How did you kill groovysh?  With the Unix `kill` command (or Windows equivalent) or using one of the "exit" commands in the shell itself (:exit, :x, etc)?

I suspect you may simply want the `groovy` command that you can use to run Groovy scripts/programs. 

$ echo "println 'hello world'" > test.groovy
$ cat test.groovy
println 'hello world'
$ groovy test.groovy 
hello world

Hope this helps,
Keith

On Oct 11, 2018, at 10:54 PM, Tzu-Li Chen <[hidden email]> wrote:

Hi Groovy community,

I am new to Groovy and when running `groovysh` with "3.0.0-alpha-3, JVM: 1.8.0_171" on macOS, I see a, hmm, Java monitor(?), named "GroovyShell" launched.

If I kill it, process `groovysh` quit with exception below. I'd like to know if we can suppress the launch of "GroovyShell" process. It switch the focus of cursor and quite annoying for me.

Best,
tison.

[printStackTrace]:

➜  ~ groovysh
Groovy Shell (3.0.0-alpha-3, JVM: 1.8.0_171)
Type ':help' or ':h' for help.
-------------------------------------------------------------------------------
groovy:000> 2018-10-12 10:51:09.084 java[34387:1479007] java.lang.SecurityException: Use of System.exit() is forbidden!
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:59)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:238)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:250)
at org.codehaus.groovy.tools.shell.util.NoExitSecurityManager.checkExit(NoExitSecurityManager.groovy:51)
at java.lang.Runtime.exit(Runtime.java:107)
at java.lang.System.exit(System.java:971)
at com.apple.eawt._AppEventHandler.performQuit(_AppEventHandler.java:145)
at com.apple.eawt.QuitResponse.performQuit(QuitResponse.java:51)
at com.apple.eawt._AppEventHandler$_QuitDispatcher.performDefaultAction(_AppEventHandler.java:390)
at com.apple.eawt._AppEventHandler$_AppEventDispatcher.dispatch(_AppEventHandler.java:512)
at com.apple.eawt._AppEventHandler.handleNativeNotification(_AppEventHandler.java:202)




----------------------
Keith Suderman
Research Associate
Department of Computer Science
Vassar College, Poughkeepsie NY







----------------------
Keith Suderman
Research Associate
Department of Computer Science
Vassar College, Poughkeepsie NY




Reply | Threaded
Open this post in threaded view
|

Re: Start shell/REPL without launching java monitor?

Tzu-Li Chen
Hi Keith,

I confirm your workaround did the job on macOS, thank you very much!

Best,
tison.


Keith Suderman <[hidden email]> 于2018年10月20日周六 下午11:48写道:
Ok, I see what you mean now.  I don't use groovysh enough for that to be an issue for me, but I wonder if the issue is the same on Windows machines? 

However, I see that the "inspect" command uses a Swing GUI and I suspect this is what is causing the issue.  I also see that the "inspect" command is disabled if Java is running in "headless" mode.  So a relatively simple work around is to set java.awt.headless=true in JAVA_OPTS before running groovysh. I.E.

$> export JAVA_OPTS=-Djava.awt.headless=true
$> groovysh

-or-

$> JAVA_OPTS=-Djava.awt.headless=true groovysh

-or-

$> alias gsh='JAVA_OPTS=-Djava.awt.headless=true groovysh'
$> gsh

Now the applet is not launched and doesn't steal the focus away from the terminal window.  However, I haven't tested the above (other to ensure the applet isn't started) so I don't know what else might be affected.

Hope this helps,
- Keith

On Oct 15, 2018, at 4:22 PM, Tzu-Li Chen <[hidden email]> wrote:

Hi Keith,

Thanks for your reply! I think I know `groovy` command and now I exactly suffer from `groovysh`. Let me try to speak it clearly.

(on macOS)
1. I open a terminal.
2. Type "groovysh" and <CR>
3. A new window looks like a Java applet, named "Groovy Shell" launched, and the focus switch to it.
4. I switch the focus back to the terminal, and start to interact with REPL.

What I am suffering is 3 and 4, each time I want to interact with REPL I have to switch the focus. Think about `jshell` or `python`, the REPL is of course a process, but not another window and even force switch the focus.

Also photos in attach links, please pay attention to the focus is switched from 1 to 2.

Best,
tison.


Keith Suderman <[hidden email]> 于2018年10月15日周一 下午10:44写道:
Hi Tison,

I am not sure what you are asking... groovysh is the "Groovy Shell" so you should see a terminal window named "GroovyShell" launched that allows you to execute Groovy commands interactively.  This is the expected behaviour.  Or are you just pointing out the exception when quitting groovysh?  How did you kill groovysh?  With the Unix `kill` command (or Windows equivalent) or using one of the "exit" commands in the shell itself (:exit, :x, etc)?

I suspect you may simply want the `groovy` command that you can use to run Groovy scripts/programs. 

$ echo "println 'hello world'" > test.groovy
$ cat test.groovy
println 'hello world'
$ groovy test.groovy 
hello world

Hope this helps,
Keith

On Oct 11, 2018, at 10:54 PM, Tzu-Li Chen <[hidden email]> wrote:

Hi Groovy community,

I am new to Groovy and when running `groovysh` with "3.0.0-alpha-3, JVM: 1.8.0_171" on macOS, I see a, hmm, Java monitor(?), named "GroovyShell" launched.

If I kill it, process `groovysh` quit with exception below. I'd like to know if we can suppress the launch of "GroovyShell" process. It switch the focus of cursor and quite annoying for me.

Best,
tison.

[printStackTrace]:

➜  ~ groovysh
Groovy Shell (3.0.0-alpha-3, JVM: 1.8.0_171)
Type ':help' or ':h' for help.
-------------------------------------------------------------------------------
groovy:000> 2018-10-12 10:51:09.084 java[34387:1479007] java.lang.SecurityException: Use of System.exit() is forbidden!
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:59)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:238)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:250)
at org.codehaus.groovy.tools.shell.util.NoExitSecurityManager.checkExit(NoExitSecurityManager.groovy:51)
at java.lang.Runtime.exit(Runtime.java:107)
at java.lang.System.exit(System.java:971)
at com.apple.eawt._AppEventHandler.performQuit(_AppEventHandler.java:145)
at com.apple.eawt.QuitResponse.performQuit(QuitResponse.java:51)
at com.apple.eawt._AppEventHandler$_QuitDispatcher.performDefaultAction(_AppEventHandler.java:390)
at com.apple.eawt._AppEventHandler$_AppEventDispatcher.dispatch(_AppEventHandler.java:512)
at com.apple.eawt._AppEventHandler.handleNativeNotification(_AppEventHandler.java:202)




----------------------
Keith Suderman
Research Associate
Department of Computer Science
Vassar College, Poughkeepsie NY







----------------------
Keith Suderman
Research Associate
Department of Computer Science
Vassar College, Poughkeepsie NY