英文:
Since 2.2.0 spring-boot-maven-plugin create 2 java process (may cause CreateProcess error=206). Need workaround to fix it
问题
自 Spring Boot 2.2.0.RELEASE 起,使用 spring-boot-maven-plugin 运行应用时,可能会创建两个 Java 进程。这可能会导致类似于 https://github.com/spring-projects/spring-boot/issues/17766 的问题。在我的情况下,可能出现类似以下的进程:
14811 ? Sl 1:34 /usr/lib/jvm/java-11-oracle/bin/java -classpath ...
14841 ? Sl 8:01 /usr/lib/jvm/java-11-oracle/bin/java -Xverify:none ...
这种情况可能会引发 Windows 下的“错误 CreateProcess error=206,文件名或扩展名过长”的问题(参考链接:https://stackoverflow.com/questions/54246648/jhipster-5-7-microservice-failed-to-start-on-windows-with-error-createprocess-er)。
为了解决这个问题,你可以采取以下方式之一(不包括回退到之前的版本):
-
使用短路径和文件名:尝试将 Maven 仓库和项目路径放在较短的目录中,以减少文件路径长度。例如,将 Maven 仓库和项目移动到根目录下的一个短目录。
-
将依赖项提取到外部目录:将一些大型依赖项(例如,JAR 包)从类路径中提取到一个外部目录,然后通过
-classpath
参数引用它们。 -
使用更短的类路径:通过删除一些不必要的依赖项,减小类路径的长度。
-
使用可执行的 JAR 文件:使用 Spring Boot 可执行的 JAR 文件,这样可以将所有依赖项打包在一个 JAR 中,减少类路径的长度。
-
分离应用:将应用拆分成更小的模块,每个模块有自己的依赖项,以减少单个模块的类路径长度。
-
使用类路径通配符:在类路径中使用通配符来引用一组相关的 JAR 包,从而减少类路径的长度。
-
检查不必要的依赖项:检查是否有一些不必要的依赖项,可以移除它们以减少类路径长度。
请选择适合你项目的方法来解决这个问题。
英文:
Since Spring Boot 2.2.0.RELEASE spring-boot-maven-plugin
mvn spring-boot:run -Drun.profiles=prod
create two java process (see https://github.com/spring-projects/spring-boot/issues/17766). In my case:
14811 ? Sl 1:34 /usr/lib/jvm/java-11-oracle/bin/java -classpath /opt/maven/boot/plexus-classworlds-2.5.2.jar -Dclassworlds.conf=/opt/maven/bin/m2.conf -Dmaven.home=/opt/maven -Dlibrary.jansi.path
=/opt/maven/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/opt/javaops org.codehaus.plexus.classworlds.launcher.Launcher spring-boot:run -Drun.profiles=prod
14841 ? Sl 8:01 /usr/lib/jvm/java-11-oracle/bin/java -Xverify:none -XX:TieredStopAtLevel=1 -cp /opt/javaops/target/classes:/opt/maven_repo/com/google/http-client/google-http-client/1.34.0/google-
http-client-1.34.0.jar:/opt/maven_repo/javax/xml/bind/jaxb-api/2.4.0-b180830.0359/jaxb-api-2.4.0-b180830.0359.jar:/opt/maven_repo/org/springframework/spring-beans/5.2.3.RELEASE/spring-beans-5.2.3.RELEASE.ja
r:/opt/maven_repo/org/apache/tomcat/embed/tomcat-embed-core/9.0.30/tomcat-embed-core-9.0.30.jar:/opt/maven_repo/com/sun/xml/fastinfoset/FastInfoset/1.2.15/FastInfoset-1.2.15.jar:/opt/maven_repo/com/google/h
ttp-client/google-http-client-jackson2/1.34.1/google-http-client-jackson2-1.34.1.jar:/opt/maven_repo/jakarta/persistence/jakarta.persistence-api/2.2.3/jakarta.persistence-api-2.2.3.jar:/opt/maven_repo/com/g
oogle/oauth-client/google-oauth-client/1.30.5/google-oauth-client-1.30.5.jar:/opt/maven_repo/com/google/apis/google-api-services-admin-directory/directory_v1-rev20191003-1.30.8/google-api-services-admin-dir
ectory-directory_v1-rev20191003-1.30.8.jar:/opt/maven_repo/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar:/opt/maven_repo/org/springframework/spring-expression/5.2.3.RELEASE/spring-expr
ession-5.2.3.RELEASE.jar:/opt/maven_repo/com/sun/activation/jakarta.activation/1.2.1/jakarta.activation-1.2.1.jar:/opt/maven_repo/org/springframework/boot/spring-boot-starter-security/2.2.3.RELEASE/spring-b
oot-starter-security-2.2.3.RELEASE.jar:/opt/maven_repo/org/springframework/boot/spring-boot-starter-web/2.2.3.RELEASE/spring-boot-starter-web-2.2.3.RELEASE.jar:/opt/maven_repo/org/hibernate/common/hibernate
-commons-annotations/5.1.0.Final/hibernate-commons-annotations-5.1.0.Final.jar:/opt/maven_repo/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar:/opt/maven_repo/javax/annotation/javax.annotatio
n-api/1.3.2/javax.annotation-api-1.3.2.jar:/opt/maven_repo/org/glassfish/jaxb/jaxb-runtime/2.4.0-b180830.0438/jaxb-runtime-2.4.0-b180830.0438.jar:/opt/maven_repo/org/projectlombok/lombok/1.18.12/lombok-1.18
.12.jar:/opt/maven_repo/org/springframework/boot/spring-boot-autoconfigure/2.2.3.RELEASE/spring-boot-autoconfigure-2.2.3.RELEASE.jar:/opt/maven_repo/org/springframework/spring-aop/5.2.3.RELEASE/spring-aop-5
.2.3.RELEASE.jar:/opt/maven_repo/org/springframework/spring-web/5.2.3.RELEASE/spring-web-5.2.3.RELEASE.jar:/opt/maven_repo/javax/activation/javax.activation-api/1.2.0/javax.activation-api-1.2.0.jar:/opt/mav
en_repo/io/grpc/grpc-context/1.22.1/grpc-context-1.22.1.jar:/opt/maven_repo/org/jvnet/staxex/stax-ex/1.8/stax-ex-1.8.jar:/opt/maven_repo/org/hibernate/hibernate-core/5.4.10.Final/hibernate-core-5.4.10.Final
.jar:/opt/maven_repo/org/jboss/jandex/2.1.1.Final/jandex-2.1.1.Final.jar:/opt/maven_repo/org/apache/httpcomponents/httpcore/4.4.13/httpcore-4.4.13.jar:/opt/maven_repo/org/springframework/boot/spring-boot/2.
2.3.RELEASE/spring-boot-2.2.3.RELEASE.jar:/opt/maven_repo/org/thymeleaf/extras/thymeleaf-extras-java8time/3.0.4.RELEASE/thymeleaf-extras-java8time-3.0.4.RELEASE.jar:/opt/maven_repo/org/slf4j/jul-to-slf4j/1.
7.30/jul-to-slf4j-1.7.30.jar:/opt/maven_repo/com/zaxxer/HikariCP/3.4.2/HikariCP-3.4.2.jar:/opt/maven_repo/com/sun/istack/istack-commons-runtime/3.0.7/istack-commons-runtime-3.0.7.jar:/opt/maven_repo/org/spr
ingframework/spring-orm/5.2.3.RELEASE/spring-orm-5.2.3.RELEASE.jar:/opt/maven_repo/org/apache/logging/log4j/log4j-api/2.12.1/log4j-api-2.12.1.jar:/opt/maven_repo/org/springframework/security/spring-security
-config/5.2.1.RELEASE/spring-security-config-5.2.1.RELEASE.jar:/opt/maven_repo/ch/qos/logback/logback-core/1.2.3/logback-core-1.2.3.jar:/opt/maven_repo/org/springframework/boot/spring-boot-starter-logging/2
.2.3.RELEASE/spring-boot-starter-logging-2.2.3.RELEASE.jar:/opt/maven_repo/javax/activation/activation/1.1.1/activation-1.1.1.jar:/opt/maven_repo/org/springframework/spring-core/5.2.3.RELEASE/spring-core-5.
2.3.RELEASE.jar:/opt/maven_repo/org/apache/tomcat/embed/tomcat-embed-websocket/9.0.30/tomcat-embed-websocket-9.0.30.jar:/opt/maven_repo/com/fasterxml/jackson/core/jackson-annotations/2.10.2/jackson-annotati
ons-2.10.2.jar:/opt/maven_repo/org/springframework/security/spring-security-core/5.2.1.RELEASE/spring-security-core-5.2.1.RELEASE.jar:/opt/maven_repo/com/fasterxml/jackson/core/jackson-databind/2.10.2/jacks
on-databind-2.10.2.jar:/opt/maven_repo/com/h2database/h2/1.3.176/h2-1.3.176.jar:/opt/maven_repo/jakarta/validation/jakarta.validation-api/2.0.2/jakarta.validation-api-2.0.2.jar:/opt/maven_repo/org/springfra
mework/boot/spring-boot-starter-aop/2.2.3.RELEASE/spring-boot-starter-aop-2.2.3.RELEASE.jar:/opt/maven_repo/com/fasterxml/jackson/module/jackson-module-parameter-names/2.10.2/jackson-module-parameter-names-
2.10.2.jar:/opt/maven_repo/com/fasterxml/classmate/1.5.1/classmate-1.5.1.jar:/opt/maven_repo/org/springframework/spring-context/5.2.3.RELEASE/spring-context-5.2.3.RELEASE.jar:/opt/maven_repo/org/springframe
work/spring-aspects/5.2.3.RELEASE/spring-aspects-5.2.3.RELEASE.jar:/opt/maven_repo/org/springframework/boot/spring-boot-starter-json/2.2.3.RELEASE/spring-boot-starter-json-2.2.3.RELEASE.jar:/opt/maven_repo/
io/opencensus/opencensus-api/0.24.0/opencensus-api-0.24.0.jar:/opt/maven_repo/org/springframework/boot/spring-boot-starter-validation/2.2.3.RELEASE/spring-boot-starter-validation-2.2.3.RELEASE.jar:/opt/mave
n_repo/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar:/opt/maven_repo/org/checkerframework/checker-compat-qual/2.5
.5/checker-compat-qual-2.5.5.jar:/opt/maven_repo/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.10.2/jackson-datatype-jsr310-2.10.2.jar:/opt/maven_repo/org/springframework/security/spring-security
-web/5.2.1.RELEASE/spring-security-web-5.2.1.RELEASE.jar:/opt/maven_repo/antlr/antlr/2.7.7/antlr-2.7.7.jar:/opt/maven_repo/jakarta/annotation/jakarta.annotation-api/1.3.5/jakarta.annotation-api-1.3.5.jar:/o
pt/maven_repo/com/ibm/icu/icu4j/66.1/icu4j-66.1.jar:/opt/maven_repo/org/springframework/boot/spring-boot-starter-cache/2.2.3.RELEASE/spring-boot-starter-cache-2.2.3.RELEASE.jar:/opt/maven_repo/org/springfra
mework/boot/spring-boot-starter-thymeleaf/2.2.3.RELEASE/spring-boot-starter-thymeleaf-2.2.3.RELEASE.jar:/opt/maven_repo/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar:/opt/maven_repo/org/yaml/
snakeyaml/1.25/snakeyaml-1.25.jar:/opt/maven_repo/net/bytebuddy/byte-buddy/1.10.6/byte-buddy-1.10.6.jar:/opt/maven_repo/jakarta/activation/jakarta.activation-api/1.2.1/jakarta.activation-api-1.2.1.jar:/opt/
maven_repo/org/slf4j/slf4j-api/1.7.30/slf4j-api-1.7.30.jar:/opt/maven_repo/com/fasterxml/jackson/datatype/jackson-datatype-jdk8/2.10.2/jackson-datatype-jdk8-2.10.2.jar:/opt/maven_repo/org/springframework/sp
ring-webmvc/5.2.3.RELEASE/spring-webmvc-5.2.3.RELEASE.jar:/opt/maven_repo/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar:/opt/maven_repo/org/springframework/spring-context-support/5.2.3.RELEASE/spri
ng-context-support-5.2.3.RELEASE.jar:/opt/maven_repo/androidx/annotation/annotation/1.1.0/annotation-1.1.0.jar:/opt/maven_repo/jakarta/transaction/jakarta.transaction-api/1.3.3/jakarta.transaction-api-1.3.3
.jar:/opt/maven_repo/org/springframework/data/spring-data-jpa/2.2.4.RELEASE/spring-data-jpa-2.2.4.RELEASE.jar:/opt/maven_repo/org/apache/commons/commons-lang3/3.9/commons-lang3-3.9.jar:/opt/maven_repo/org/s
pringframework/boot/spring-boot-starter-data-jpa/2.2.3.RELEASE/spring-boot-starter-data-jpa-2.2.3.RELEASE.jar:/opt/maven_repo/org/jboss/logging/jboss-logging/3.4.1.Final/jboss-logging-3.4.1.Final.jar:/opt/m
aven_repo/org/springframework/boot/spring-boot-configuration-processor/2.2.3.RELEASE/spring-boot-configuration-processor-2.2.3.RELEASE.jar:/opt/maven_repo/org/springframework/boot/spring-boot-starter-tomcat
/2.2.3.RELEASE/spring-boot-starter-tomcat-2.2.3.RELEASE.jar:/opt/maven_repo/com/google/errorprone/error_prone_annotations/2.3.4/error_prone_annotations-2.3.4.jar:/opt/maven_repo/org/springframework/spring-t
x/5.2.3.RELEASE/spring-tx-5.2.3.RELEASE.jar:/opt/maven_repo/org/attoparser/attoparser/2.0.5.RELEASE/attoparser-2.0.5.RELEASE.jar:/opt/maven_repo/com/google/api-client/google-api-client/1.30.8/google-api-cli
ent-1.30.8.jar:/opt/maven_repo/org/thymeleaf/thymeleaf-spring5/3.0.11.RELEASE/thymeleaf-spring5-3.0.11.RELEASE.jar:/opt/maven_repo/com/fasterxml/jackson/core/jackson-core/2.10.2/jackson-core-2.10.2.jar:/opt
/maven_repo/org/hibernate/validator/hibernate-validator/6.0.18.Final/hibernate-validator-6.0.18.Final.jar:/opt/maven_repo/org/apache/httpcomponents/httpclient/4.5.10/httpclient-4.5.10.jar:/opt/maven_repo/co
m/google/guava/guava/28.2-android/guava-28.2-android.jar:/opt/maven_repo/org/springframework/data/spring-data-commons/2.2.4.RELEASE/spring-data-commons-2.2.4.RELEASE.jar:/opt/maven_repo/org/unbescape/unbesc
ape/1.1.6.RELEASE/unbescape-1.1.6.RELEASE.jar:/opt/maven_repo/org/springframework/boot/spring-boot-starter-mail/2.2.3.RELEASE/spring-boot-starter-mail-2.2.3.RELEASE.jar:/opt/maven_repo/org/jsoup/jsoup/1.13.
1/jsoup-1.13.1.jar:/opt/maven_repo/org/aspectj/aspectjweaver/1.9.5/aspectjweaver-1.9.5.jar:/opt/maven_repo/org/springframework/spring-jcl/5.2.3.RELEASE/spring-jcl-5.2.3.RELEASE.jar:/opt/maven_repo/org/glass
fish/jaxb/txw2/2.3.2/txw2-2.3.2.jar:/opt/maven_repo/commons-codec/commons-codec/1.13/commons-codec-1.13.jar:/opt/maven_repo/com/sun/mail/jakarta.mail/1.6.4/jakarta.mail-1.6.4.jar:/opt/maven_repo/org/apache/
logging/log4j/log4j-to-slf4j/2.12.1/log4j-to-slf4j-2.12.1.jar:/opt/maven_repo/org/springframework/boot/spring-boot-starter-jdbc/2.2.3.RELEASE/spring-boot-starter-jdbc-2.2.3.RELEASE.jar:/opt/maven_repo/org/t
hymeleaf/thymeleaf/3.0.11.RELEASE/thymeleaf-3.0.11.RELEASE.jar:/opt/maven_repo/org/apache/tomcat/embed/tomcat-embed-el/9.0.30/tomcat-embed-el-9.0.30.jar:/opt/maven_repo/org/springframework/boot/spring-boot-
starter/2.2.3.RELEASE/spring-boot-starter-2.2.3.RELEASE.jar:/opt/maven_repo/org/javassist/javassist/3.24.0-GA/javassist-3.24.0-GA.jar:/opt/maven_repo/io/opencensus/opencensus-contrib-http-util/0.24.0/opence
nsus-contrib-http-util-0.24.0.jar:/opt/maven_repo/org/springframework/spring-jdbc/5.2.3.RELEASE/spring-jdbc-5.2.3.RELEASE.jar:/opt/maven_repo/org/dom4j/dom4j/2.1.1/dom4j-2.1.1.jar ru.javaops.JavaOPsApplicat
ion
It is too verbose and for Windows could cause of "error CreateProcess error=206, The filename or extension is too long" (see https://stackoverflow.com/questions/54246648/jhipster-5-7-microservice-failed-to-start-on-windows-with-error-createprocess-er).
What is the best way to fix it (exclude return to previous version:)?
答案1
得分: 15
显然,自从Spring Boot 2.2以来,默认情况下启用了forking。
要禁用它,可以尝试以下方法:
在您的Maven命令中添加 -Dspring-boot.run.fork=false
,或者在您的pom.xml中进行配置:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>false</fork>
</configuration>
</plugin>
英文:
Apparently, forking is enabled by default since Spring Boot 2.2.
Disable it again might help.
Add -Dspring-boot.run.fork=false
to your maven command or configure it in your pom.xml:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>false</fork>
</configuration>
</plugin>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论