简体   繁体   English

在Eclipse for Java和Jython中使用Nailgun

[英]Using Nailgun in Eclipse for Java and Jython

I have just set up Nailgun ( https://github.com/martylamb/nailgun , http://martiansoftware.com/nailgun/ ), which is a clever piece of kit which makes the JVM hang around in memory making Java and Jython (potentially) launch more quickly. 我刚刚建立了Nailgun( https://github.com/martylamb/nailgunhttp://martiansoftware.com/nailgun/ ),这是一个聪明的工具包片,这使得在JVM内存使得Java和Jython流连(可能)更快地启动。

This is great for Java, but it promises to be absolute gold dust for me for Jython, particularly during development (Jython is the best language in the world, but has a slow start-up time). 这对Java来说很棒,但是对于Jython来说,这对我来说绝对是金尘,尤其是在开发过程中(Jython是世界上最好的语言,但是启动时间很慢)。

Googling to see whether anyone had tackled running Nailgun on Eclipse I found a red herring, which is "nailgun/eclipse-gtkrc" at GitHub: "nailgun" is just the guy's handle. 谷歌搜索是否有人解决过在Eclipse上运行Nailgun的问题,我在GitHub上找到了一个红色的鲱鱼:“ nailgun / eclipse-gtkrc”:“ nailgun”只是这个家伙的句柄。 I also found a CS dept had in fact tackled this, at http://www.cs.dartmouth.edu/~jygsaw/getting_started.html . 我还在http://www.cs.dartmouth.edu/~jygsaw/getting_started.html上找到了一个CS部门实际上已经解决了此问题。 They seem actually to have managed getting this working for Jython, which was potentially brilliant, but unfortunately their system relies on using a BASH script (Mac OS), and I'm forced to work on Windows (W7) for the moment. 他们似乎实际上已经设法为Jython进行了这项工作,这可能很棒,但是不幸的是,他们的系统依赖于使用BASH脚本(Mac OS),并且目前我不得不在Windows(W7)上工作。

What I then did was 然后我做的是

1) Started up the Nailgun server outside Eclipse, including jython.jar in the CLASSPATH, 1)在Eclipse外部启动Nailgun服务器,包括CLASSPATH中的jython.jar,

2) Then I created a client.bat file consisting of a single line: 2)然后,我创建了一个由单行组成的client.bat文件:

ng org.python.util.jython %1

3) Then I set up an "external tool configuration" in Eclipse called "ng_client", as per the above CS dept's instructions, except that I set the Location to the above client.bat file, and I made the Arguments: "${selected_resource_loc}" (<-- including quotes, because unfortunately at the moment I have spaces in this path) 3)然后,按照上述CS部门的说明,在Eclipse中设置一个名为“ ng_client”的“外部工具配置”,除了将Location设置为上述client.bat文件,然后进行参数设置: "${selected_resource_loc}" (<-包括引号,因为很不幸,此刻我在该路径中有空格)

4) I ran this "ng_client" once so it failed, but was then included in this External tools list of tools. 4)我曾经运行过这个“ ng_client”,所以失败了,但是后来被包含在这个外部工具列表中。

5) I then selected a trivial Jython py file (trivial.py) and went Run --> External tools --> ng_client. 5)然后我选择了一个普通的Jython py文件(trivial.py),然后运行->外部工具-> ng_client。

The console showed the following result 控制台显示以下结果

C:\\Program Files (x86)\\eclipse-jee-luna-SR2-win32\\eclipse>ng org.python.util.jython "G:\\My Documents\\software projects\\trivial.py" C:\\ Program Files(x86)\\ eclipse-jee-luna-SR2-win32 \\ eclipse> ng org.python.util.jython“ G:\\ My Documents \\ software projects \\ trivial.py”

recv: No error recv:没有错误

NB "recv: No error" is in red. 注意:“ recv:无错误”为红色。 The program, I hasten to add, did not run. 我赶紧添加的程序没有运行。

Incidentally, for anyone interested, this led to the Nailgun server terminal giving out the following error message: 偶然地,对于任何有兴趣的人,这导致Nailgun服务器终端发出以下错误消息:

C:\Users\Mike>java com.martiansoftware.nailgun.NGServer
NGServer 0.9.2-SNAPSHOT started on all addresses, port 2113.
NGSession 1: 127.0.0.1: org.python.util.jython exited with status -1
java.lang.ClassCastException: org.python.util.JLineConsole$Stream cannot be cast
 to com.martiansoftware.nailgun.ThreadLocalInputStream
        at com.martiansoftware.nailgun.NGSession.run(NGSession.java:263)
Exception in thread "NGSession 2: 127.0.0.1: org.python.util.jython" java.lang.C
lassCastException: org.python.util.JLineConsole$Stream cannot be cast to com.mar
tiansoftware.nailgun.ThreadLocalInputStream
        at com.martiansoftware.nailgun.NGSession.run(NGSession.java:381)

I seem to be quite close ... does any Eclipse expert have any idea how I should proceed? 我似乎很接近……任何Eclipse专家都知道我应该如何进行吗?

PS I've also tried running a trivial Jython program outside of Eclipse. PS我也曾尝试在Eclipse之外运行一个普通的Jython程序。 So far it always trips up the Nailgun server as above. 到目前为止,它始终会像上面那样使Nailgun服务器跳闸。 There is a bit of evidence out there of people doing it successfully, but they always seem to be on a Linux box, not Windows. 有很多证据表明人们成功地做到了这一点,但是他们似乎总是在Linux机器上,而不是Windows。 Naturally enough I'm planning to take a look at the server source code where the errors are happening in due course. 很自然地,我计划看一下在适当时候发生错误的服务器源代码。

Result! 结果!

And it makes Jython start-ups super-fast. 而且,它使Jython的初创企业变得超快。 I recommend this to all Jythonistas. 我向所有Jythonistas推荐。

As I realised eventually yesterday (PS comment), the first thing was to get Jython to run outside Eclipse. 正如我最终在昨天意识到的那样(PS评论),第一件事是让Jython在Eclipse之外运行。 What I found I had to do was comment out 6 lines in the file nailgun-master\\nailgun-server\\src\\main\\java\\com\\martiansoftware\\nailgun\\NGSession.java: 我发现我要做的就是注释文件nailgun-master \\ nailgun-server \\ src \\ main \\ java \\ com \\ martiansoftware \\ nailgun \\ NGSession.java中的6行:
ll 263-265 ll 263-265
ll 381-383 ll 381-383
And then rebuild the jar as per Nailgun setup instructions (ie mvn clean install ). 然后按照Nailgun安装说明重新构建jar(即mvn clean install )。

After this, I made a handy .bat file to run the Nailgun server ("...\\jars" is the place where I put nailgun-server-0.9.2-SNAPSHOT.jar and all the other jars I want to include): 之后,我制作了一个方便的.bat文件来运行Nailgun服务器(“ ... \\ jars”是我放置nailgun-server-0.9.2-SNAPSHOT.jar以及我要包括的所有其他jar的地方) :

set classpath=d:/apps/jython2.7.0/jython.jar;d:/apps/jython2.7.0/jars/*
java com.martiansoftware.nailgun.NGServer

After this, to run from a DOS window go: 之后,要从DOS窗口运行,请执行以下操作:

ng org.python.util.jython "G:\My Documents\software projects\my_jython_project\__main__.py"

And then, in Eclipse, after following the steps above for setting up ng_client, select the .py file you want to run (in Project explorer window) and go 然后,在Eclipse中,按照上述设置ng_client的步骤操作之后,选择要运行的.py文件(在Project Explorer窗口中),然后转到

Run --> External tools --> ng_client 运行->外部工具-> ng_client

NB the sys.out & sys.err output is directed to the server window... presumably this is a consequence of the changes made to NGSession.java. 注意,sys.out&sys.err输出定向到服务器窗口...大概这是对NGSession.java进行更改的结果。 If the Nailgun author, Marty Lamb, ever reads this, first Thanks for this great app, and second it'd be nice if you have any comments about the changes I made to NGSession.java. 如果Nailgun的作者Marty Lamb读过这篇文章,首先感谢这款出色的应用程序,其次,如果您对我对NGSession.java所做的更改有任何评论,那将是很好的。

later 后来

Some strange things happen... hopefully just teething troubles. 发生了一些奇怪的事情……希望只是会带来麻烦。

In particular, I wanted to use this for unit testing which, like most development, involves constantly running things over and over. 特别是,我想将其用于单元测试,就像大多数开发一样,它涉及不断地运行内容。 The trouble is I tend to find that the classes I am developing sometimes seem to "linger" in the "Nailgun memory". 麻烦的是,我倾向于发现我正在开发的类有时似乎在“ Nailgun内存”中“徘徊”。 I've even seen classes run an older version of themselves when the NG server is stopped and a new one started... which is utterly baffling. 我什至曾经看到,当NG服务器停止运行并启动新的类时,类会运行其自身的旧版本……这简直令人莫名其妙。 It tends to suggest that older versions of .class files are somehow being "cached" in the Nailgun memory when I don't want them to be. 它倾向于表明,当我不希望较旧版本的.class文件被“缓存”在Nailgun内存中时。 And this happens even when using the "ng-cp" option to specify CLASSPATH additions in the client, not the server! 即使使用“ ng-cp”选项在客户端(而不是服务器)中指定CLASSPATH添加,也会发生这种情况!

Unfortunately this is all quite "niche": using the Jython with the unittest module, running Nailgun. 不幸的是,这一切都是“利基”的:将Jython与unittest模块一起使用,运行Nailgun。 Sigh. 叹。

除了建议迈克建议对Nailgun进行代码更改以防止java.lang.ClassCastException之外,另一种方法是在启动Nailgun时提供以下系统属性,从而将Jython使用的控制台更改为PlainConsole:-Dpython.console = org.python.core.PlainConsole这可以防止类强制转换异常,并导致控制台输出也返回到客户端而不是服务器窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM