我当时所做的是 1)在Eclipse外部启动Nailgun服务器,包括CLASSPATH中的jython.jar, 2)然后,我创建了一个由单行组成的client.bat文件:ng org.python.util.jython %1 3)然后,按照上述CS部门的指示,在Eclipse中设置一个名为"ng_client"的外部工具配置",除了将Location设置为上述client.bat文件之外,并进行了参数讨论: "${selected_resource_loc}"(<-包括引号,因为不幸的是此刻我在此路径中有空格) 4)我运行了一次此"ng_client",因此失败了,但随后被包含在此外部工具"工具列表中. 5)然后,我选择了一个普通的Jython py文件(trivial.py),然后运行->外部工具-> ng_client.控制台显示以下结果 C:\ Program Files(x86)\ eclipse-jee-luna-SR2-win32 \ eclipse> ng org.python.util.jython"G:\ My Documents \ software projects \ trivial.py" recv:没有错误 NB"recv:无错误"为红色.我赶紧添加的程序没有运行.偶然地,对于任何感兴趣的人,这导致Nailgun服务器终端发出以下错误消息:C:\Users\Mike>java com.martiansoftware.nailgun.NGServerNGServer 0.9.2-SNAPSHOT started on all addresses, port 2113.NGSession 1: 127.0.0.1: org.python.util.jython exited with status -1java.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.ClassCastException: org.python.util.JLineConsole$Stream cannot be cast to com.martiansoftware.nailgun.ThreadLocalInputStream at com.martiansoftware.nailgun.NGSession.run(NGSession.java:381)我似乎已经很接近了……任何Eclipse专家都知道我应该如何进行吗? PS我还尝试过在Eclipse外部运行一个普通的Jython程序.到目前为止,它始终会像上面那样使Nailgun服务器跳闸.有很多证据表明人们成功地做到了这一点,但是他们似乎总是在Linux机器上,而不是Windows.很自然地,我打算看一下在适当的时候发生错误的服务器源代码.解决方案结果!这使Jython的初创企业超快.我向所有Jythonistas推荐.正如我昨天最终意识到的那样(PS评论),第一件事是让Jython在Eclipse之外运行.我发现我要做的就是注释文件nailgun-master \ nailgun-server \ src \ main \ java \ com \ martiansoftware \ nailgun \ NGSession.java中的6行:ll 263-265ll 381-383然后按照Nailgun设置说明(即mvn clean install)重新构建jar.此后,我制作了一个方便的.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之后,要从DOS窗口运行,请执行以下操作:ng org.python.util.jython "G:\My Documents\software projects\my_jython_project\__main__.py"然后,在Eclipse中,按照上述设置ng_client的步骤操作后,选择要运行的.py文件(在项目浏览器"窗口中)并进入运行->外部工具-> ng_client注意sys.out& sys.err输出定向到服务器窗口...大概这是对NGSession.java所做的更改的结果.如果Nailgun的作者Marty Lamb曾经读过这篇文章,首先感谢这款出色的应用程序,其次,如果您对我对NGSession.java所做的更改有任何评论,那就太好了. 以后有些奇怪的事情发生了……希望只是会带来麻烦.特别是,我想将其用于单元测试,就像大多数开发一样,它涉及不断地运行内容.麻烦的是,我倾向于发现我正在开发的类有时似乎在"Nailgun内存"中徘徊".我什至曾经看到,当NG服务器停止运行并启动新的类时,类会运行其自身的旧版本……这简直令人莫名其妙.它倾向于表明,当我不希望将.class文件的较旧版本以某种方式缓存"在Nailgun内存中时.即使使用"ng-cp"选项在客户端(而不是服务器)中指定CLASSPATH添加,也会发生这种情况!不幸的是,这一切都是利基"的:将Jython与unittest模块一起使用,运行Nailgun.叹气.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.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).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.I also found a CS dept had in fact tackled this, at http://www.cs.dartmouth.edu/~jygsaw/getting_started.html. 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.What I then did was1) Started up the Nailgun server outside Eclipse, including jython.jar in the CLASSPATH,2) Then I created a client.bat file consisting of a single line:ng org.python.util.jython %13) 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)4) I ran this "ng_client" once so it failed, but was then included in this External tools list of tools.5) I then selected a trivial Jython py file (trivial.py) and went Run --> External tools --> 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" recv: No errorNB "recv: No error" is in red. 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:C:\Users\Mike>java com.martiansoftware.nailgun.NGServerNGServer 0.9.2-SNAPSHOT started on all addresses, port 2113.NGSession 1: 127.0.0.1: org.python.util.jython exited with status -1java.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.ClassCastException: org.python.util.JLineConsole$Stream cannot be cast to com.martiansoftware.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?PS I've also tried running a trivial Jython program outside of Eclipse. So far it always trips up the Nailgun server as above. 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. 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. I recommend this to all Jythonistas.As I realised eventually yesterday (PS comment), the first thing was to get Jython to run outside 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:ll 263-265ll 381-383And then rebuild the jar as per Nailgun setup instructions (i.e. 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): set classpath=d:/apps/jython2.7.0/jython.jar;d:/apps/jython2.7.0/jars/*java com.martiansoftware.nailgun.NGServerAfter this, to run from a DOS window go: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 goRun --> External tools --> ng_clientNB the sys.out & sys.err output is directed to the server window... presumably this is a consequence of the changes made to 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.laterSome 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". 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. 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. And this happens even when using the "ng-cp" option to specify CLASSPATH additions in the client, not the server!Unfortunately this is all quite "niche": using the Jython with the unittest module, running Nailgun. Sigh. 这篇关于在Eclipse for Java和Jython中使用Nailgun的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-29 20:12
查看更多