Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用maven war插件从依赖项jar文件中排除配置文件_Maven_Maven War Plugin - Fatal编程技术网

如何使用maven war插件从依赖项jar文件中排除配置文件

如何使用maven war插件从依赖项jar文件中排除配置文件,maven,maven-war-plugin,Maven,Maven War Plugin,我有一个maven war项目。在这个项目中,我包括两个依赖项,如 <parent> <groupId>com.softech.ls360.proxy</groupId> <artifactId>LS360ProxyAPI</artifactId> <version>0.0.1</version> </parent> <artifactId>LS360ProxyA

我有一个maven war项目。在这个项目中,我包括两个依赖项,如

<parent>
    <groupId>com.softech.ls360.proxy</groupId>
    <artifactId>LS360ProxyAPI</artifactId>
    <version>0.0.1</version>
</parent>

<artifactId>LS360ProxyAPIWeb</artifactId>
<packaging>war</packaging>
...
<properties>
    ...
    <tomcat-directory-path>D:\Basit\apache-tomcat-8.0.18</tomcat-directory-path>    
</properties>
<dependencies>
    <dependency>
        <groupId>com.softech.ls360.proxy</groupId>
        <artifactId>LmsProxy</artifactId>
        <version>0.0.1</version>
    </dependency>
    <dependency>
        <groupId>com.softech.ls360.proxy</groupId>
        <artifactId>StoreFrontProxy</artifactId>
        <version>0.0.1</version>
    </dependency>
    ....
</dependencies>
<build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <warName>${project.artifactId}</warName>
                <outputDirectory>${tomcat-directory-path}\webapps</outputDirectory>
            </configuration>
        </plugin>
    </plugins>
</build>

LmsProxy
是一个Maven项目吗?一种方法是更改
LmsProxy
build并创建另一个不包含要过滤掉的资源的人工制品(使用maven assembly插件)。然后,在
LS360ProxyAPIWeb
@Tunaki Yes中,您将依赖于该新的人工制品,这两个项目都是maven项目。实际上我有一个模块化的maven项目。在war项目中,我包含了这两个依赖项。请检查我的编辑。在我的编辑中,我展示了我的LmsProxy.pom文件。我曾经建立了一个Maven项目,该项目在基于概要文件的最终包中包含或排除了资源。看看能不能帮你。
<parent>
    <groupId>com.softech.ls360.proxy</groupId>
    <artifactId>LS360ProxyAPI</artifactId>
    <version>0.0.1</version>
</parent>

<artifactId>LmsProxy</artifactId>

<name>LmsProxy</name>
...

<properties>
   <maven-dependency-plugin.version>2.9</maven-dependency-plugin.version>
   <maven-jar-plugin.version>2.5</maven-jar-plugin.version>
</properties>

<dependencies>
</dependencies>

<plugins>
<!--  uses maven-dependency-plugin to copy all dependencies to "target/lms-proxy-dependency-jars/" 
              folder, and defines the dependency classpath with maven-jar-plugin 
        -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>${maven-dependency-plugin.version}</version>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <includeGroupIds>
                            org.springframework, org.springframework.ws, org.springframework.data, 
                            org.springframework.security, org.aspectj, javax.servlet, javax.servlet.jsp, 
                            javax.inject, javax.validation, org.hibernate, org.jadira.usertype, 
                            com.microsoft.sqlserver, joda-time, com.google.guava, org.apache.httpcomponents,
                            org.apache.commons, com.fasterxml.jackson.core, com.fasterxml.jackson.module, 
                            com.fasterxml.jackson.datatype, org.jvnet.jaxb2_commons, org.slf4j, log4j,
                            org.hamcrest, junit, org.mockito, com.jayway.jsonpath
                        </includeGroupIds>
                        <outputDirectory>${project.build.directory}/lms-proxy-dependency-jars/</outputDirectory>
                        <overWriteReleases>false</overWriteReleases>
                        <overWriteSnapshots>false</overWriteSnapshots>
                        <overWriteIfNewer>true</overWriteIfNewer>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <!-- To make jar file like a exe file, you need to define a manifest file and declare the application
             entry point inside via maven-jar-plugin in pom.xml. 

             - create executable JAR with the specified mainClass
             - exclude all .properties files located in src/main/resources from the JAR
             - add conf folder to the manifest, providing access to it from your executable JAR
        -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>${maven-jar-plugin.version}</version>

            <!-- The configuration of the plugin -->
            <configuration>

                <excludes>
                    <exclude>**/*.properties</exclude>
                    <exclude>**/*.xml</exclude>
                    <exclude>**/*.vm</exclude>
                </excludes> 

                <!-- Configuration of the archiver -->
                <archive>

                    <!-- Manifest specific configuration -->
                    <manifest>

                        <!-- Classpath is added to the manifest of the created jar file. -->
                        <addClasspath>true</addClasspath>

                        <!--
                           Configures the classpath prefix. This configuration option is
                           used to specify that all needed libraries are found under Lms-Proxy-Dependency-jars/
                           directory.

                           Use “classpathPrefix” to specify folder name in which all properties will be placed.
                       -->
                        <classpathPrefix>lms-proxy-dependency-jars/</classpathPrefix>

                        <!-- Specifies the main class of the application -->
                        <mainClass>com.softech.ls360.lms.proxy.LmsProxy</mainClass>
                    </manifest>

                    <!-- Use “Class-Path” to specify the folder. “.” Indicate current folder, while 
                         “propertiesFiles” specifies “propertiesFiles” folder in same directory as JAR. 
                    -->
                    <manifestEntries>
                        <Class-Path>lms-proxy-conf/</Class-Path>
                     </manifestEntries> 
                </archive>
            </configuration>
        </plugin>

        <!-- copy all .properties, .xml and .vm files located in src/main/resources into a conf folder in your project root. Note that this 
             step is an optional convenience for your users of the JAR. You can require the explicitly create this file in the 
             conf directory. This conf directory is effectively added to your runtime classpath via the manifest. 
        -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>install</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${basedir}/target/lms-proxy-conf</outputDirectory>
                        <resources>
                            <resource>
                                <directory>src/main/resources</directory>
                                <includes>
                                    <include>**/*.properties</include>
                                    <include>**/*.xml</include>
                                    <include>**/*.vm</include>
                                </includes>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
</plugins>