简体   繁体   English

命令行版IntelliJ IDEA运行配置

[英]Command line version of IntelliJ IDEA run configuration

I have a working IntelliJ IDEA run configuration.我有一个有效的 IntelliJ IDEA 运行配置。 It uses Spring Boot.它使用 Spring 引导。

I'd like to execute the same run from the MacOS command line.我想从 MacOS 命令行执行相同的运行。 How can I get IntelliJ IDEA to show the command (or commands) that I need execute the run configuration.如何让 IntelliJ IDEA 显示我需要执行运行配置的命令(或命令)。

This is the gradle build.gradle file:这是gradle build.gradle文件:

plugins {
    id 'org.springframework.boot' version '2.6.4'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

group = 'org.mountsinai'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = "15"

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
    runtimeOnly 'com.microsoft.sqlserver:mssql-jdbc'
    implementation group: 'org.springframework', name: 'spring-aspects', version: '5.3.15'
    implementation group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect', version: '3.0.0'
    implementation group: 'com.jayway.jsonpath', name: 'json-path', version: '2.7.0'
    implementation group: 'com.github.pcj', name: 'google-options', version: '1.0.0'
    implementation 'com.google.code.gson:gson:2.9.0'
}

tasks.named('test') {
    useJUnitPlatform()
    minHeapSize = "1024m" // initial heap size
    maxHeapSize = "2048m" // maximum heap size
}
targetCompatibility = JavaVersion.VERSION_15

And this is the configuration element in the ./.idea/workspace.xml corresponding to the run I'd like to automate on the command line:这是./.idea/workspace.xml中的configuration元素,对应于我想在命令行上自动执行的运行:

    <configuration name="IrwMetadataIntegrationApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot">
      <module name="org.mountsinai.IRWMetadataIntegration.main" />
      <option name="SPRING_BOOT_MAIN_CLASS" value="org.mountsinai.IRWMetadataIntegration.IrwMetadataIntegrationApplication" />
      <option name="PROGRAM_PARAMETERS" value="--algorithm=batch --numOfStudiesToRetrieve=600" />
      <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" />
      <option name="ALTERNATIVE_JRE_PATH" value="15" />
      <method v="2">
        <option name="Make" enabled="true" />
      </method>
    </configuration>

My original question can now be asked more concretely How can one convert an IDEA configuration and workspace.xml file into a command (or script) that can be executed outside IntelliJ IDEA?现在可以更具体地问我最初的问题如何将 IDEA 配置和workspace.xml文件转换为可以在 IntelliJ IDEA 外部执行的命令(或脚本)?

Using使用

IntelliJ IDEA 2021.3.2 (Ultimate Edition) Build #IU-213.6777.52, built on January 27, 2022

Thanks, Arthur谢谢,亚瑟

At the top of your console Notice there's a command something something... java, normally it collapses into such short form, but if you click on that:在控制台的顶部,请注意有一个命令 something something...java,通常它会折叠成如此短的形式,但如果您单击它:

在此处输入图像描述

Notice it will expand and show you the full command:请注意,它将展开并向您显示完整的命令: 在此处输入图像描述

In this case, for example, ultimately, the command is something like this :在这种情况下,例如,最终,命令是这样的

/Users/hoaphan/.sdkman/candidates/java/17.0.4-amzn/bin/java -XX:TieredStopAtLevel=1 
-Dspring.output.ansi.enabled=always 
-Dcom.sun.management.jmxremote 
-Dspring.jmx.enabled=true 
-Dspring.liveBeansView.mbeanDomain 
-Dspring.application.admin.enabled=true 
...blahblahblahblahblah...
com.example.bootgradlej17.Bootgradlej17Application

So you can mimic intelliJ by running such long command.所以你可以通过运行这么长的命令来模仿 intelliJ。 But I would suggest if this is springboot, and build by gradle, what you actually want to do is at project root, in the dir where your build.gradle is do:但我会建议,如果这是 springboot,并且由 gradle 构建,那么你真正想要做的是在项目根目录下,在你的 build.gradle 所在的目录中:

./gradlew bootRun

Now if you want to mimic the JVM option IntelliJ did, you can just capture such info from an IntelliJ run using tool like VisualVM:现在,如果您想模仿 IntelliJ 所做的 JVM 选项,您可以使用 VisualVM 等工具从 IntelliJ 运行中捕获此类信息: 在此处输入图像描述

Then you can configure your bootRun to start with such config for JVM like:然后你可以配置你的 bootRun 以这样的配置开始 JVM 像:

bootRun {
   jvmArgs = "-Dspring.application.admin.enabled=true", "-Dnannana=nenenene" (etc)....
}

Execute your program through the run configuration and check the first line of the output. It should contain the call that is executed by the IDE, often something like java -jar … .通过运行配置执行您的程序并检查 output 的第一行。它应该包含由 IDE 执行的调用,通常类似于java -jar …

eg when running a Scratch file, I get the following in the output window as first line:例如,当运行 Scratch 文件时,我在 output window 中得到以下第一行:

/usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/java -javaagent:/home/user/bin/idea-IU-222.3345.47/lib/idea_rt.jar=37117:/home/user/bin/idea-IU-222.3345.47/bin -Dfile.encoding=UTF-8 -classpath /home/user/.cache/JetBrains/IntelliJIdea2022.3/compile-server/backend_dd2372d5/scratches/out:... Scratch

Continuing my comment above...继续我上面的评论......

  1. On my computer (running macOS Big Sur 11.6) VisualVM cannot find the JVM arguments:在我的电脑上(运行 macOS Big Sur 11.6)VisualVM 找不到 JVM arguments:

在此处输入图像描述

Instead, they can be found in the java command that you explain how to reveal.相反,它们可以在您解释如何显示的 java 命令中找到。 Eg, mine are:例如,我的是:

-Dspring.output.ansi.enabled=always
-Dcom.sun.management.jmxremote
-Dspring.jmx.enabled=true
-Dspring.liveBeansView.mbeanDomain
-Dspring.application.admin.enabled=true
...

Please explain your请解释你的

bootRun {
   jvmArgs = "-Dspring.application.admin.enabled=true", "-Dnannana=nenenene" (etc)....
}

example.例子。 Where and how should this text be used?应该在哪里以及如何使用该文本?

  1. One also needs to provide any command-line arguments that are in the IDEA configuration.还需要提供 IDEA 配置中的任何命令行 arguments。 These can be passed via the gradlew --args option , like this:这些可以通过gradlew --args选项传递,如下所示:

    --args='--algorithm=batch --numOfStudiesToRetrieve=600' --args='--algorithm=batch --numOfStudiesToRetrieve=600'

Overall, however, this approach is more ad hoc than I'd like.然而,总的来说,这种方法比我想要的更临时 It requires that one hack a) IDEA's java command to obtain the JVM arguments, b) the command-line arguments in via gradlew 's --args .它需要一个 hack a) IDEA 的 java 命令来获取 JVM arguments,b) 通过gradlew的 --args 中的命令行--args But I assume that the silence of IntelliJ IDEA's developers indicates that they do not support this important functionality.但我认为 IntelliJ IDEA 开发人员的沉默表明他们不支持这一重要功能。

Another comment in an answer because the formatting limitations of comments are so limiting:答案中的另一条评论,因为评论的格式限制非常有限:

Thanks, @HoaPhan.谢谢,@HoaPhan。 However, when I insert a bootRun section like this in build.gradle ,但是,当我在build.gradle中插入这样的bootRun部分时,

bootRun {
  jvmArgs = "-Dspring.output.ansi.enabled=always"
}

IntelliJ IDEA raises IntelliJ IDEA 提出

Could not compile build file '<path>/build.gradle'.
> startup failed:
  build file '<path>/build.gradle': 1: Unexpected input: '{' @ line 1, column 9.
     bootRun {
             ^

This appears to occur wherever the section is placed in the file.这似乎发生在该部分位于文件中的任何位置。

However, this does work:但是,这确实有效:

bootRun {
    jvmArgs = [ "-Dspring.output.ansi.enabled=always",
                "-Dcom.sun.management.jmxremote",
                "-Dspring.jmx.enabled=true",
                "-Dspring.liveBeansView.mbeanDomain",
                "-Dspring.application.admin.enabled=true",
                "-Dfile.encoding=UTF-8"
    ]
}

It's unclear why the first bootRun { appears to generate a syntax error and this does not.目前还不清楚为什么第一个bootRun {似乎会产生语法错误,而这不会。

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

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