0
<?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> 
    <artifactId>JavaExeDemo</artifactId> 
    <packaging>jar</packaging> 
    <version>1.0-SNAPSHOT</version> 
    <name>JavaExeDemo</name> 
    <url>http://maven.apache.org</url> 
    <properties> 
     <maven.compiler.target>1.8</maven.compiler.target> 
     <maven.compiler.source>1.8</maven.compiler.source> 
    </properties> 

    <dependencies> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-context</artifactId> 
      <version>4.2.5.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-jdbc</artifactId> 
      <version>4.2.5.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-orm</artifactId> 
      <version>4.2.5.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-aop</artifactId> 
      <version>4.2.5.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-aspects</artifactId> 
      <version>4.2.5.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>log4j</groupId> 
      <artifactId>log4j</artifactId> 
      <version>1.2.17</version> 
     </dependency> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-api</artifactId> 
      <version>1.6.4</version> 
     </dependency> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-log4j12</artifactId> 
      <version>1.6.4</version> 
      <scope>runtime</scope> 
     </dependency> 

     <dependency> 
      <groupId>javax.el</groupId> 
      <artifactId>el-api</artifactId> 
      <version>2.2</version> 
     </dependency> 

     <dependency> 
      <groupId>org.hsqldb</groupId> 
      <artifactId>hsqldb</artifactId> 
      <version>2.3.1</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.commons</groupId> 
      <artifactId>commons-dbcp2</artifactId> 
      <version>2.0</version> 
     </dependency> 
     <dependency> 
      <groupId>commons-io</groupId> 
      <artifactId>commons-io</artifactId> 
      <version>2.5</version> 
     </dependency> 



     <!-- Hibernate EHCache API --> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-core</artifactId> 
      <version>5.0.4.Final</version> 
     </dependency> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-entitymanager</artifactId> 
      <version>5.0.4.Final</version> 
     </dependency> 

     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-ehcache</artifactId> 
      <version>5.0.4.Final</version> 
     </dependency> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-validator</artifactId> 
      <version>5.2.2.Final</version> 
     </dependency> 
     <dependency> 
      <groupId>javax.transaction</groupId> 
      <artifactId>jta</artifactId> 
      <version>1.1</version> 
      <scope>runtime</scope> 
     </dependency> 

     <dependency> 
      <groupId>org.controlsfx</groupId> 
      <artifactId>controlsfx</artifactId> 
      <version>8.40.10</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.poi</groupId> 
      <artifactId>poi-ooxml</artifactId> 
      <version>3.12</version> 
     </dependency> 
     <!-- Test --> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.11</version> 
     </dependency> 
    </dependencies> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>2.5.1</version> 
       <configuration> 
        <source>1.8</source> 
        <target>1.8</target> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-shade-plugin</artifactId> 
       <version>2.3</version> 
       <executions> 
        <execution> 
         <phase>package</phase> 
         <goals> 
          <goal>shade</goal> 
         </goals> 
         <configuration> 
          <transformers> 
           <!-- add Main-Class to manifest file --> 
           <transformer 
            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
            <mainClass>application.Main</mainClass> 
           </transformer> 
           <transformer 
            implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer"> 
            <resource>application/application.css</resource> 
            <file>/testProject/src/main/java/application/application.css</file> 
           </transformer> 
          </transformers> 
          <outputDirectory>testProject/target/classes</outputDirectory> 
          <includeEmptyDirs>true</includeEmptyDirs> 
          <resources> 
           <resource> 
            <directory>testProject/src/main/resources/ui/</directory> 
            <filtering>false</filtering> 
           </resource> 
           <resource> 
            <directory>testProject/src/main/java/com/xyz/internal/installer</directory> 
            <filtering>false</filtering> 
           </resource> 
           <resource> 
            <directory>testProject/src/main/java/application</directory> 
            <filtering>false</filtering> 
           </resource> 
          </resources> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
     </plugins> 
    </build> 

    <groupId>test</groupId> 
</project> 

我是Maven的新手,一直在嘗試爲我的應用程序創建一個超級罐子。我已經能夠包括在包括變壓器(僅當「不是」所使用的資源標籤)中提到的application.css但是我有散落的項目有如下路徑的幾個資源:無法創建一個包含所有資源的超級罐子

  1. /SRC /主/資源/ UI/
  2. /SRC /主/ JAVA/COM/XYZ /內部/安裝

我試圖將它們包括在代碼資源,然而,圖像內 /src/main/resources/ui/都包含在內,但其他位置不包含在內。另外,當我不使用資源標籤時,jar包含'application.css',否則不是。

回答

0

您的pom.xml看起來不正確。你有resource filtering與maven陰影插件配置混合。

您應該配置您的POM像下面,

<build>  
    <resources>   
     <resource>   
      <directory>${project.basedir}/src/main/resources/ui/</directory> 
      <filtering>false</filtering> 
     </resource> 
     <resource> 
      <directory>${project.basedir}/src/main/java/xyz/internal/installer/</directory> 
      <filtering>false</filtering> 
     </resource> 
     <resource> 
      <directory>${project.basedir}/src/main/java/application</directory> 
      <filtering>false</filtering> 
     </resource> 
    </resources> 
    <!... 0ther stuff like dependencies...... > 
    <plugins> 
    <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-shade-plugin</artifactId> 
      <version>2.3</version> 
      <configuration> 
       <transformers> 
        <!-- add Main-Class to manifest file --> 
        <transformer 
         implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
         <mainClass>application.Main</mainClass> 
        </transformer> 
        <transformer 
         implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer"> 
         <resource>application/application.css</resource> 
          <file>${project.basedir}/src/main/java/application/application.css</file> 
        </transformer> 
       </transformers> 
      </configuration> 
      <executions> 
       <execution> 
        <phase>package</phase> 
        <goals> 
         <goal>shade</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     </plugins> 
    </build> 

幾個點,

  1. 我用$ {} project.basedir代替testproject/src目錄/ ......這是一個最好的練習,你不應該硬編碼你的項目名稱。同樣使用$ {project.build.directory}作爲目標目錄。請參閱this
  2. 如果要將資源過濾器中指定的資源複製到特定位置,必須使用copy resource plugin
  3. include empty directory是複製資源插件的配置之一
相關問題