java - Maven 程序集插件使用类路径构建 jar

标签 java spring maven

我有一个 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/

相关文章:

java - Maven 循环依赖

maven - 休眠和 JPA 错误 : duplicate import on dependent Maven project

java - 如何快速构建Web Application?

java - Angular 网站的交互式屏幕指导

java - 我应该如何在 Spring boot 中配置 httpMessageConverters 以将消息转换为所需的格式?

java - Spring Openid、OpenIDAuthenticationToken

spring - 许多缓存在 spring 中的缺点

java - 如果我多次使用它,将 String 声明为 final 是否明智?

java - SLF4J 的 NoSuchMethodError

Eclipse Maven 一键构建和测试