[英]Command line version of IntelliJ IDEA run configuration
我有一個有效的 IntelliJ IDEA 運行配置。 它使用 Spring 引導。
我想從 MacOS 命令行執行相同的運行。 如何讓 IntelliJ IDEA 顯示我需要執行運行配置的命令(或命令)。
這是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
這是./.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>
現在可以更具體地問我最初的問題如何將 IDEA 配置和workspace.xml
文件轉換為可以在 IntelliJ IDEA 外部執行的命令(或腳本)?
使用
IntelliJ IDEA 2021.3.2 (Ultimate Edition) Build #IU-213.6777.52, built on January 27, 2022
謝謝,亞瑟
在控制台的頂部,請注意有一個命令 something something...java,通常它會折疊成如此短的形式,但如果您單擊它:
在這種情況下,例如,最終,命令是這樣的:
/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
所以你可以通過運行這么長的命令來模仿 intelliJ。 但我會建議,如果這是 springboot,並且由 gradle 構建,那么你真正想要做的是在項目根目錄下,在你的 build.gradle 所在的目錄中:
./gradlew bootRun
現在,如果您想模仿 IntelliJ 所做的 JVM 選項,您可以使用 VisualVM 等工具從 IntelliJ 運行中捕獲此類信息:
然后你可以配置你的 bootRun 以這樣的配置開始 JVM 像:
bootRun {
jvmArgs = "-Dspring.application.admin.enabled=true", "-Dnannana=nenenene" (etc)....
}
通過運行配置執行您的程序並檢查 output 的第一行。它應該包含由 IDE 執行的調用,通常類似於java -jar …
例如,當運行 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
繼續我上面的評論......
相反,它們可以在您解釋如何顯示的 java 命令中找到。 例如,我的是:
-Dspring.output.ansi.enabled=always
-Dcom.sun.management.jmxremote
-Dspring.jmx.enabled=true
-Dspring.liveBeansView.mbeanDomain
-Dspring.application.admin.enabled=true
...
請解釋你的
bootRun {
jvmArgs = "-Dspring.application.admin.enabled=true", "-Dnannana=nenenene" (etc)....
}
例子。 應該在哪里以及如何使用該文本?
還需要提供 IDEA 配置中的任何命令行 arguments。 這些可以通過gradlew
--args
選項傳遞,如下所示:
--args='--algorithm=batch --numOfStudiesToRetrieve=600'
然而,總的來說,這種方法比我想要的更臨時。 它需要一個 hack a) IDEA 的 java 命令來獲取 JVM arguments,b) 通過gradlew
的 --args 中的命令行--args
。 但我認為 IntelliJ IDEA 開發人員的沉默表明他們不支持這一重要功能。
答案中的另一條評論,因為評論的格式限制非常有限:
謝謝,@HoaPhan。 但是,當我在build.gradle
中插入這樣的bootRun
部分時,
bootRun {
jvmArgs = "-Dspring.output.ansi.enabled=always"
}
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 {
^
這似乎發生在該部分位於文件中的任何位置。
但是,這確實有效:
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"
]
}
目前還不清楚為什么第一個bootRun {
似乎會產生語法錯誤,而這不會。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.