简体   繁体   English

运行Java文件服务Mac

[英]Run Java file Service Mac

So far i've created a service using automator to compile a Java file. 到目前为止,我已经使用自动器创建了一个服务来编译Java文件。 This means that i can compile a java file through its contextual menu. 这意味着我可以通过其上下文菜单来编译Java文件。

Unfortunately I cannot do the same with running the Java file. 不幸的是,我无法对运行Java文件执行相同的操作。 Through automator I can get it to run the java file perfectly, showing the results in the automator window, however it will not open the Terminal window to view the java file. 通过自动器,我可以使它完美地运行Java文件,并在自动器窗口中显示结果,但是它不会打开“终端”窗口来查看Java文件。 I did this using this code: 我使用以下代码进行了此操作:

java -classpath `dirname "$1"` `basename "$1" | sed "s/.class//g"`

Applescript on the other hand can run Terminal commands into a Terminal window for all to see using code such as: 另一方面,Applescript可以将Terminal命令运行到Terminal窗口中,以供所有人使用以下代码查看:

on run {input, parameters}
    tell application "Terminal"
        activate
        do script with command "java -classpath" & input & input
    end tell
end run

The correct way to run a java file is: 运行Java文件的正确方法是:

java -classpath /path/to/ file

Can anybody please help? 有人可以帮忙吗? Thanks in advance. 提前致谢。

Utilities > Run Shell Script with Passing input: as arguments seems to work in this context. Utilities > Run Shell Script带有Passing input: as arguments Utilities > Run Shell Script Passing input: as arguments似乎在此上下文中有效。

Addendum: If you want to open Terminal, something like this may work. 附录:如果要打开终端,则可能需要执行以下操作。

open -a Terminal ~/your/script.sh

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

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