Spring启动maven插件没有在Openshift环境中打包java类

时间:2016-08-29 16:42:26

标签: maven spring-boot openshift

我有一个多模块maven项目,其中一个模块使用Spring Boot。

当我将我的jar打包到我的电脑中时它运行正常并且所有java类都包含在jar中,但是当我在Openshift环境中执行此操作时,只包含Web资源,而不是java类。

我有一个Openshift DIY墨盒,其中使用动作挂钩设置环境,打包我的jar并运行它。

这个程序运行正常,直到我做了一些最近的更改,将我的maven项目划分为模块。

父pom.xml

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                    http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion> 
<groupId>XXXX</groupId>
<artifactId>XXXX</artifactId>
<version>XXXX</version>
<packaging>pom</packaging>

<modules>
    <module>data</module>
    <module>web</module>
</modules>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>

    <maven.compiler.plugin.version>3.5</maven.compiler.plugin.version>
    <maven.jar.plugin.version>3.0.2</maven.jar.plugin.version>
    <maven.clean.plugin.version>2.5</maven.clean.plugin.version>
    <maven.spring-boot-maven-plugin.version>1.3.3.RELEASE</maven.spring-boot-maven-plugin.version>
</properties>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <version>${maven.clean.plugin.version}</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.plugin.version}</version>
            </plugin>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${maven.spring-boot-maven-plugin.version}</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>${maven.jar.plugin.version}</version>
            </plugin>
        </plugins>
    </pluginManagement>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencyManagement>
    <dependencies>
        ...
    </dependencies>
</dependencyManagement>

<dependencies>
    ....
</dependencies>

web模块pom.xml

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                    http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
    <groupId>XXXX</groupId>
    <artifactId>XXXX</artifactId>
    <version>1.2.3</version>
</parent>

<artifactId>XXXX</artifactId>
<packaging>jar</packaging>

<properties>
    ...
</properties>

<build>
    <finalName>${project.name}-${project.version}</finalName>
    <resources>
        <resource>
            <directory>${project.resources.path}</directory>
        </resource>
    </resources>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-clean-plugin</artifactId>
            <configuration>
                <filesets>
                    <fileset>
                        <directory>deployments</directory>
                        <includes>
                            <include>*.jar</include>
                            <followSymlinks>false</followSymlinks>
                        </includes>
                    </fileset>
                </filesets>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
        </plugin>

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <mainClass>XXXX</mainClass>
                <finalName>XXXX</finalName>
                <outputDirectory>../deployments</outputDirectory>
                <excludeGroupIds>org.seleniumhq.selenium,org.projectlombok</excludeGroupIds>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>
   ....
</dependencies>

数据模块pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
                    http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
    <groupId>XXXX</groupId>
    <artifactId>XXXX</artifactId>
    <version>1.2.3</version>
</parent>

<artifactId>XXXX</artifactId>
<packaging>jar</packaging>

<properties>
....
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
        </plugin>
    </plugins>
</build>

<dependencies>
....
</dependencies>

Maven命令我用来打包jar(在Openshift盒中执行)

${OPENSHIFT_DATA_DIR}${MVN_LINK}/bin/mvn clean install -s     
.openshift/action_hooks/settings.xml -DskipTests=true -P prod
我的Openshift框中的

mvn -v命令

Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-  10T11:41:47-05:00)
Maven home: /var/lib/openshift/5713d8630c1e66bfc5000085/app- root/data/maven
Java version: 1.8.0_101, vendor: Oracle Corporation
Java home: /var/lib/openshift/5713d8630c1e66bfc5000085/app-   root/data/jdk1.8.0_101/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "2.6.32-573.26.1.el6.x86_64", arch: "i386",  family: "unix"

生成的jar包含所有lib,.properties文件,Web资源等,但没有java类的标志...

我错过了什么?为什么不打包java类呢?

非常感谢

1 个答案:

答案 0 :(得分:0)

CASE CLOSED

我发现了这个问题。我错误地gitignored web模块的src文件夹,因此没有任何东西被提交到Openshift盒式磁带的git存储库,因此它没有在jar中包装任何java文件,因为没有!对我感到羞耻! ; - )