eclipse 在 IDE 中运行 Vertx

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24277301/
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-09-19 21:45:04  来源:igfitidea点击:

Run Vertx in an IDE

eclipsenetbeansintellij-ideaidevert.x

提问by j will

Is there any way to run Vertx from within an IDE? I know I can create a server in a file and then call

有没有办法从 IDE 中运行 Vertx?我知道我可以在文件中创建一个服务器,然后调用

vertx run server.java

from the command line, but is there a way to run the server.java file from within an IDE?

从命令行,但有没有办法从 IDE 中运行 server.java 文件?

回答by sscarduzio

  • create a maven project as the manualsays.

  • Then import the project as Maven project

  • Create a new launcher (Eclipse) using as main class

    • For Vert.x 2.x: "org.vertx.java.platform.impl.cli.Starter"
    • For Vert.x 3.x: "io.vertx.core.Starter"
  • In the tab "Program Arguments" type: "run your.package.ServerVerticle -conf conf.json"

  • 按照手册中的说明创建一个 Maven 项目。

  • 然后将项目导入为Maven项目

  • 使用作为主类创建一个新的启动器(Eclipse)

    • 对于 Vert.x 2.x:“ org.vertx.java.platform.impl.cli.Starter
    • 对于 Vert.x 3.x:“ io.vertx.core.Starter
  • 在“程序参数”选项卡中键入:“运行 your.package.ServerVerticle -conf conf.json

You can omit the conf.jsonif you don't have one, it's just an example to show you that you can put there any other option you'd put launching Vert.x from the command line.

如果没有conf.json,您可以省略它,这只是一个示例,向您展示您可以将任何其他选项放在那里,以便从命令行启动 Vert.x。

PRO TIP:if your verticle is written in another language, use the prefix with the name of the language as follows:

专业提示:如果您的 Verticle 是用另一种语言编写的,请使用带有语言名称的前缀,如下所示:

  • "run scala:com.acme.MainVerticle -conf conf.json"
  • "run jython:MainVerticle.py -conf conf.json"
  • "run jruby:MainVerticle.rb -conf conf.json"
  • "run rhino:MainVerticle.js -conf conf.json"
  • "run groovy:MainVerticle.groovy -conf conf.json"
  • "运行 scala:com.acme.MainVerticle -conf conf.json"
  • "运行 jython:MainVerticle.py -conf conf.json"
  • "运行 jruby:MainVerticle.rb -conf conf.json"
  • "运行 rhino:MainVerticle.js -conf conf.json"
  • "运行 groovy:MainVerticle.groovy -conf conf.json"

And so forth.

等等。

回答by Psyx

The accepted answer is perfectly fine. Just for completness's sake, you also simply can run a plain old java main class, having a the main start your vertx instance.

接受的答案非常好。只是为了完整起见,您也可以简单地运行一个普通的旧 java 主类,让主启动您的 vertx 实例。

Code should be something like:

代码应该是这样的:

public static void main(final String... args) {
    Vertx vertx = Vertx.vertx();
    vertx.deployVerticle(/* put your stuff here */);
}

There you go.

你去吧。

回答by Marc Savy

Vert.x 3

顶点.x 3

I previously edited an earlier answer, but I'm separating it out for the sakes of clarity.

我之前编辑过一个较早的答案,但为了清楚起见,我将其分开。

The example below is for eclipse, but the same basic premise should work with any IDE.

下面的示例适用于 Eclipse,但相同的基本前提应该适用于任何 IDE。

Setup

设置

  • Set up your Maven, Gradle, or other project and import it into Eclipse

  • Create a runor debugconfig, and set io.vertx.core.Launcheras your main class.

  • In the argumentstab, set the program arguments: run org.example.InitVerticle -conf <path to config>; where org.example.InitVerticleis your main, or intialiser, verticle.
  • 设置您的Maven、Gradle 或其他项目并将其导入 Eclipse

  • 创建运行调试配置,并设置io.vertx.core.Launcher为主类。

  • 参数选项卡,设置程序参数run org.example.InitVerticle -conf <path to config>; org.example.InitVerticle你的主要或初始化器,verticle在哪里。

Debugging

调试

During debugging in Vert.x 3 you may notice that a blocked thread watchdog continually outputs warnings (and, eventually, exceptions) onto the console. Whilst useful during production, you can inhibit this behaviour by setting the following property in VM argumentsof your debug config:

在 Vert.x 3 中调试期间,您可能会注意到阻塞的线程看门狗不断向控制台输出警告(并最终输出异常)。虽然在生产过程中很有用,但您可以通过在调试配置的VM 参数中设置以下属性来禁止此行为:

-Dvertx.options.blockedThreadCheckInterval=2147483647
注意事项

Be aware that your debugging is liable to trigger timeouts in a variety of scenarios, such as a breakpoint delaying a reply on the eventbus. You'll see warnings like:

请注意,您的调试可能会在各种情况下触发超时,例如断点延迟事件总线上的回复。您会看到如下警告:

WARNING: Message reply handler timed out as no reply was received - it will be removed

Clearly, this could mean different control flows under debugging than real execution if you aren't careful.

显然,如果您不小心的话,这可能意味着调试中的控制流与实际执行中的控制流不同。

回答by INsanityDesign

I would suggest what Fran already hinted at. Best you create your Maven project from the archetype (http://vertx.io/maven_dev.html) such as

我会建议弗兰已经暗示过的内容。最好从原型(http://vertx.io/maven_dev.html)创建您的 Maven 项目,例如

mvn archetype:generate -Dfilter=io.vertx: -DgroupId=your.group.id -DartifactId=your-artifact -Dversion=0.0.1-SNAPSHOT

and add the IDE specifics via maven, for example for Eclipse

并通过 maven 添加 IDE 细节,例如 Eclipse

mvn eclipse:eclipse

By that you have an ready to import and ready to use project in Eclipse.

这样,您就可以在 Eclipse 中导入并准备使用项目了。

To actually start it then, I wouldn't go directly for a Main or Starter Verticle as but just simple run it through Maven in Eclipse as new Run Configuration. Create a new Maven Run Configuration and set as goals

要真正启动它,我不会直接使用 Main 或 Starter Verticle,而是简单地通过 Eclipse 中的 Maven 作为新的运行配置运行它。创建一个新的 Maven 运行配置并设置为目标

clean compile vertx:runMod

It will start the mod.jsonconfigured "Main" class.

它将启动mod.json配置的“Main”类。

Note: clean compileis not necessary, but if you build it once and have installed jars of your project running around, the auto-deploy doesn't work anymore as it picks the build instead of the developed code.

注意:clean compile不是必需的,但是如果您构建一次并安装了项目的 jars 运行,自动部署将不再工作,因为它选择构建而不是开发的代码。

Like that you have the example PingVerticle directly running and can also fool around as auto-redeploy is enabled in the mod.json.

就像这样,您可以直接运行示例 PingVerticle 并且还可以在mod.json 中启用自动重新部署。

If you then need more, configs etc. you can work with Starter Verticles, the parameters or even add it to the pom.xmlvertx-maven-plugin.

如果您需要更多配置等,您可以使用 Starter Verticles、参数,甚至将其添加到pom.xmlvertx-maven-plugin 中。

I hope this helps.

我希望这有帮助。

Best

最好的事物

回答by cchcc

My setting below is done at IntelliJ 15.0.1 with vert.x 3.2.0 for Java

我下面的设置是在 IntelliJ 15.0.1 上完成的,vert.x 3.2.0 for Java

  1. download and extract vertx library (http://vertx.io/download/) to somewhere
  2. at IntelliJ, 'New Project' -> select Java and Project SDK 1.8 -> Next
  3. check 'Create project from template' and 'Command Line App' -> Next
  4. input 'Project Name' you want -> Finish
  5. 'File' -> 'Project Structure...' -> select 'Libraries'
  6. '+'(New Project Library) -> 'Java' -> add (somewhere)/vert.x-3.2.0-full/lib -> 'OK'
  7. add New Verticle like :

    public class HiVerticle extends AbstractVerticle {
    @Override
    public void start() throws Exception {
        super.start();
        System.out.println("Hi");
    }}
    
  8. 'Run' -> 'Edit Configurations...' -> replace 'Main class:' to 'io.vertx.core.Launcher',

    input 'run cchcc.hi.HiVerticle' at 'Program arguments:' -> 'OK'

  9. Run and Debug!

  1. 下载 vertx 库(http://vertx.io/download/)并将其解压到某个地方
  2. 在 IntelliJ,“新项目”-> 选择 Java 和 Project SDK 1.8 -> 下一步
  3. 选中“从模板创建项目”和“命令行应用程序”->下一步
  4. 输入您想要的“项目名称”-> 完成
  5. “文件”->“项目结构...”-> 选择“库”
  6. '+'(新项目库)-> 'Java' -> 添加(某处)/vert.x-3.2.0-full/lib -> 'OK'
  7. 添加新的 Verticle,如:

    public class HiVerticle extends AbstractVerticle {
    @Override
    public void start() throws Exception {
        super.start();
        System.out.println("Hi");
    }}
    
  8. “运行”->“编辑配置...”-> 将“主类:”替换为“ io.vertx.core.Launcher”,

    在“程序参数:”->“确定”处输入“运行 cchcc.hi.HiVerticle

  9. 运行和调试!

result

结果

回答by nachi

If you are looking for options apart from creating a maven project (suggested in the other answers), you could do the following:

如果您正在寻找除创建 Maven 项目(在其他答案中建议)之外的选项,您可以执行以下操作:

  • Download the the latest release from http://vertx.io/downloads.html
  • Unzip it and add all the JARs in the lib folder to the library of your project i.e, add it to your classpath
  • Create a run configuration for your project with org.vertx.java.platform.impl.cli.Starteras the Main class.
  • Add run your.package.Server -cp ${project_loc:/YourProject}/binas arguments to your run configuration.
  • Run your project using the newly created run configuration!
  • http://vertx.io/downloads.html下载最新版本
  • 解压并将 lib 文件夹中的所有 JAR 添加到您的项目库中,即,将其添加到您的类路径中
  • 使用org.vertx.java.platform.impl.cli.Starter作为 Main 类为您的项目创建运行配置。
  • 添加run your.package.Server -cp ${project_loc:/YourProject}/bin作为运行配置的参数。
  • 使用新创建的运行配置运行您的项目!