我有一个 hadoop 任务作为 spring-boot 应用程序的组件,我使用 maven-assemble-plugin
单独编译每个文件。
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
如果我使用以下命令启动服务器,则在目标目录中:
java -cp target/xx-server-0.0.1-SNAPSHOT-jar-with-dependencies.jar com.example.MyApplication
发生错误:
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
,这是由于缺少类路径引起的。如何设置 jar 的类路径?或者我需要编写脚本来启动我的服务器吗?在 IDE 中,可以使用类路径标志启动服务器:
/usr/lib/jvm/jdk1.8.0_121/bin/java -XX:TieredStopAtLevel=1
-noverify -Dspring.output.ansi.enabled=always
-javaagent:/home/knh190/idea/idea-IU 171.3780.95/lib/idea_rt.jar=39181:/home/knh190/idea/idea-IU-171.3780.95/bin
-Dfile.encoding=UTF-8
-classpath # list of dependencies
最佳答案
您可以尝试以下操作:
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.my.App</mainClass>
</manifest>
<manifestEntries>
<Class-Path>your-classpath-here</Class-Path>
</manifestEntries>
</archive>
</configuration>
关于java - Maven 程序集插件使用类路径构建 jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43779527/