Java 如何查看eclipse“运行配置”使用的shell命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2976515/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 15:09:07  来源:igfitidea点击:

How to view shell commands used by eclipse "run configurations"

javaeclipseapache-flexmavenflash-builder

提问by gMale

Given a "run configuration" in Eclipse, I want to print out the associated shell command that would be used to run it.

给定 Eclipse 中的“运行配置”,我想打印出将用于运行它的关联 shell 命令。

For example: Right now, in Eclipse, if I click "play" it will run:

mvn assembly:directory -Dmaven.test.skip=true

例如:现在,在 Eclipse 中,如果我单击“播放”,它将运行:

mvn assembly:directory -Dmaven.test.skip=true

I don't see that command, I just know that's what the IDE must run, at some point. However, some of the other run configurations are far more complex with long classpaths and virtual machine options and, frankly, sometimes I have no idea what the equivalent shell command would be (particularly when it comes to Flex).

我没有看到那个命令,我只知道 IDE 在某些时候必须运行它。但是,其他一些运行配置要复杂得多,具有长类路径和虚拟机选项,坦率地说,有时我不知道等效的 shell 命令是什么(尤其是在涉及 Flex 时)。

There must be some way to access the shell command that would be associated with a "Run Configuration" in Eclipse/Flex Builder. This information must be available, which leads me to believe someone has written a plugin to display it. Or maybe there's already an option built into Eclipse for accessing this.

必须有某种方式来访问与 Eclipse/Flex Builder 中的“运行配置”相关联的 shell 命令。这些信息必须可用,这让我相信有人编写了一个插件来显示它。或者,也许 Eclipse 中已经内置了一个用于访问它的选项。

So is there a way to, essentially, convert an Eclipse run configuration into a shell command?

那么,从本质上讲,有没有办法将 Eclipse 运行配置转换为 shell 命令?

(for context only: I'm asking because I'm writing a bash script that automates everything I do, during development--from populating the Database all the way to opening Firefox and clearing the cache before running the web app. So every command I run from the IDE needs to exist in the script. Some are tricky to figure out.)

(仅用于上下文:我之所以这么问是因为我正在编写一个 bash 脚本,该脚本可以在开发过程中自动执行我所做的一切——从填充数据库一直到打开 Firefox 并在运行 Web 应用程序之前清除缓存。所以每个命令我从 IDE 运行需要存在于脚本中。有些很难弄清楚。)

采纳答案by splash

This should work for Java and Maven processes. You can get the command line from the Process properties.

这应该适用于 Java 和 Maven 进程。您可以从 Process 属性中获取命令行。

  • run the process in debug mode
  • right click on the process item in the "Debug" view and choose "Properties"
  • the command line is displayed
  • 在调试模式下运行进程
  • 右键单击“调试”视图中的进程项并选择“属性”
  • 显示命令行

回答by miki

thanks so much splash. one thing to add-- i was getting a weird error at the commandline:

非常感谢飞溅。要添加的一件事 - 我在命令行中遇到一个奇怪的错误:

ERROR: transport error 202: connect failed: Connection refused ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510) JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [../../../src/share/back/debugInit.c:708] FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197) Aborted!

错误:传输错误 202:连接失败:连接被拒绝错误:JDWP 传输 dt_socket 初始化失败,TRANSPORT_INIT(510) JDWP 退出错误 AGENT_ERROR_TRANSPORT_INIT(197):没有传输初始化 [../../../src/share/back /debugInit.c:708] 本地方法中的致命错误:JDWP 未初始化传输,jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197) 中止!

this can be avoided by just taking out the agentlib argument:

这可以通过取出 agentlib 参数来避免:

-agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:56431

-agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:56431

回答by Alex

Another trick if you're running on a Unix OS (although you have to be snappy about this...) is to initiate your Run.. within Eclipse and then switch over to a command prompt and run this command (Mac syntax):

如果您在 Unix 操作系统上运行,另一个技巧(尽管您必须对此保持敏锐...)是在 Eclipse 中启动您的 Run.. 然后切换到命令提示符并运行此命令(Mac 语法):

ps -ef | grep java

This will print out the command line Java process invocations that are currently running. Look for the one that corresponds to your Eclipse process (check the main class, which is the last parameter on the command line) and voila!

这将打印出当前正在运行的命令行 Java 进程调用。查找与您的 Eclipse 进程相对应的那个(检查主类,这是命令行上的最后一个参数),瞧!