2015-12-17 62 views
1

我只是按照这个question修改我的pom来创建不同的war文件。这里是原来的配置更改maven生成的war文件名问题

<build> 

    <finalName>${project.artifactId}</finalName> 
    <plugins> 
     <!-- Run with Jetty --> 
     <plugin> 
      <groupId>org.mortbay.jetty</groupId> 
      <artifactId>maven-jetty-plugin</artifactId> 
      <version>6.1.10</version> 
      <configuration> 
       <scanIntervalSeconds>5</scanIntervalSeconds> 
       <stopKey>foo</stopKey> 
       <stopPort>9999</stopPort> 
      </configuration> 
      <executions> 
       <execution> 
        <id>start-jetty</id> 
        <phase>pre-integration-test</phase> 
        <goals> 
         <goal>run</goal> 
        </goals> 
        <configuration> 
         <scanIntervalSeconds>0</scanIntervalSeconds> 
         <daemon>true</daemon> 
        </configuration> 
       </execution> 
       <execution> 
        <id>stop-jetty</id> 
        <phase>post-integration-test</phase> 
        <goals> 
         <goal>stop</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <!-- Compile java --> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.3.2</version> 
      <configuration> 
       <source>1.6</source> 
       <target>1.6</target> 
      </configuration> 
     </plugin> 
     <!-- Build war --> 
     <plugin> 
      <artifactId>maven-war-plugin</artifactId> 
      <groupId>org.apache.maven.plugins</groupId> 
      <version>2.1.1</version> 
     </plugin> 
     <!-- Pack zips --> 
     <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <version>2.2</version> 
      <executions> 
       <execution> 
        <id>webapp</id> 
        <phase>package</phase> 
        <goals> 
         <goal>single</goal> 
        </goals> 
        <configuration> 
         <finalName>LabSystem${packname}</finalName> 
         <appendAssemblyId>false</appendAssemblyId> 
         <descriptors> 
          <descriptor>src/main/assembly/webapp.xml</descriptor> 
         </descriptors> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

下面是修改的(要创建Cambellton.war)

<build> 

    <finalName>Cambellton</finalName> 
    <plugins> 
     <!-- Run with Jetty --> 
     <plugin> 
      <groupId>org.mortbay.jetty</groupId> 
      <artifactId>maven-jetty-plugin</artifactId> 
      <version>6.1.10</version> 
      <configuration> 
       <scanIntervalSeconds>5</scanIntervalSeconds> 
       <stopKey>foo</stopKey> 
       <stopPort>9999</stopPort> 
      </configuration> 
      <executions> 
       <execution> 
        <id>start-jetty</id> 
        <phase>pre-integration-test</phase> 
        <goals> 
         <goal>run</goal> 
        </goals> 
        <configuration> 
         <scanIntervalSeconds>0</scanIntervalSeconds> 
         <daemon>true</daemon> 
        </configuration> 
       </execution> 
       <execution> 
        <id>stop-jetty</id> 
        <phase>post-integration-test</phase> 
        <goals> 
         <goal>stop</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <!-- Compile java --> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.3.2</version> 
      <configuration> 
       <source>1.6</source> 
       <target>1.6</target> 
      </configuration> 
     </plugin> 
     <!-- Build war --> 
     <plugin> 
      <artifactId>maven-war-plugin</artifactId> 
      <groupId>org.apache.maven.plugins</groupId> 
      <version>2.1.1</version> 
     </plugin> 
     <!-- Pack zips --> 
     <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <version>2.2</version> 
      <executions> 
       <execution> 
        <id>webapp</id> 
        <phase>package</phase> 
        <goals> 
         <goal>single</goal> 
        </goals> 
        <configuration> 
         <finalName>Cambellton{packname}</finalName> 
         <appendAssemblyId>false</appendAssemblyId> 
         <descriptors> 
          <descriptor>src/main/assembly/webapp.xml</descriptor> 
         </descriptors> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

当尝试构建,它提供了错误,但创建war文件。我想在尝试创建zip文件时会出现问题。以下是错误消息

> [INFO] 
[INFO] --- maven-war-plugin:2.1.1:war (default-war) @ LabSystem --- 
[INFO] Packaging webapp 
[INFO] Assembling webapp [LabSystem] in [F:\MyDocuments\Java\ZK7LabSystem\LabSystem\LabSystem\target\Cambellton] 
[INFO] Processing war project 
[INFO] Copying webapp resources [F:\MyDocuments\Java\ZK7LabSystem\LabSystem\LabSystem\src\main\webapp] 
[INFO] Webapp assembled in [4554 msecs] 
[INFO] Building war: F:\MyDocuments\Java\ZK7LabSystem\LabSystem\LabSystem\target\Cambellton.war 
[WARNING] Warning: selected war files include a WEB-INF/web.xml which will be ignored 
(webxml attribute is missing from war task, or ignoreWebxml attribute is specified as 'true') 
[INFO] 
[INFO] --- maven-assembly-plugin:2.2:single (webapp) @ LabSystem --- 
[INFO] Reading assembly descriptor: src/main/assembly/webapp.xml 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 17.543s 
[INFO] Finished at: Thu Dec 17 11:29:29 IST 2015 
[INFO] Final Memory: 16M/348M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2:single (webapp) on project LabSystem: Failed to create assembly: Error adding file to archive: F:\MyDocuments\Java\ZK7LabSystem\LabSystem\LabSystem\target\LabSystem.war isn't a file. -> [Help 1] 
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 
[ERROR] Re-run Maven using the -X switch to enable full debug logging. 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles: 
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException 

编辑1

这里是webapp.xml

<assembly 
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> 
    <id>webapp</id> 
    <formats> 
     <format>zip</format> 
    </formats> 
    <fileSets> 
     <fileSet> 
      <directory>${project.basedir}/src/main/java</directory> 
      <outputDirectory>/${project.artifactId}/src</outputDirectory> 
     </fileSet> 
     <fileSet> 
      <directory>${project.basedir}/src/main/webapp</directory> 
      <outputDirectory>/${project.artifactId}/WebContent</outputDirectory> 
     </fileSet> 
    </fileSets> 
    <files> 
     <file> 
      <source>${project.build.directory}/${project.artifactId}.war</source> 
      <outputDirectory>/</outputDirectory> 
     </file> 
    </files> 
</assembly> 

编辑2: 加$符号也行,不过还是给了同样的错误 作为

<build> 

     <finalName>$Cambellton</finalName> 
     <plugins> 
      <!-- Run with Jetty --> 
      <plugin> 
       <groupId>org.mortbay.jetty</groupId> 
       <artifactId>maven-jetty-plugin</artifactId> 
       <version>6.1.10</version> 
       <configuration> 
        <scanIntervalSeconds>5</scanIntervalSeconds> 
        <stopKey>foo</stopKey> 
        <stopPort>9999</stopPort> 
       </configuration> 
       <executions> 
        <execution> 
         <id>start-jetty</id> 
         <phase>pre-integration-test</phase> 
         <goals> 
          <goal>run</goal> 
         </goals> 
         <configuration> 
          <scanIntervalSeconds>0</scanIntervalSeconds> 
          <daemon>true</daemon> 
         </configuration> 
        </execution> 
        <execution> 
         <id>stop-jetty</id> 
         <phase>post-integration-test</phase> 
         <goals> 
          <goal>stop</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
      <!-- Compile java --> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>2.3.2</version> 
       <configuration> 
        <source>1.6</source> 
        <target>1.6</target> 
       </configuration> 
      </plugin> 
      <!-- Build war --> 
      <plugin> 
       <artifactId>maven-war-plugin</artifactId> 
       <groupId>org.apache.maven.plugins</groupId> 
       <version>2.3</version> 
      </plugin> 
      <!-- Pack zips --> 
      <plugin> 
       <artifactId>maven-assembly-plugin</artifactId> 
       <version>2.2</version> 
       <executions> 
        <execution> 
         <id>webapp</id> 
         <phase>package</phase> 
         <goals> 
          <goal>single</goal> 
         </goals> 
         <configuration> 
          <finalName>Cambellton${packname}</finalName> 
          <appendAssemblyId>false</appendAssemblyId> 
          <descriptors> 
           <descriptor>src/main/assembly/webapp.xml</descriptor> 
          </descriptors> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 
+0

您可以发布您webapp.xml文件还更换呢? –

+0

添加了webapp.xml文件并添加了$ –

+0

我更新了我的答案,错误很可能在webapp.xml文件中 –

回答

1

在Maven Assembly Plugin配置中,检查

<finalName>Cambellton{packname}</finalName> 

{packname}不被认为是因为缺少$前缀的属性。假设你将packname定义为你的pom中的一个属性。

在你原来的配置,这是

<finalName>LabSystem${packname}</finalName> 

同时检查一致性与src/main/assembly/webapp.xml文件,其中可能包括任何或指定生成的WAR文件,如下面的例子:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> 
    <id>zip</id> 
    <formats> 
    <format>zip</format> 
    </formats> 
    <fileSets> 
    <fileSet> 
     <directory>${project.build.directory}</directory> 
     <includes> 
     <include>*.war</include> 
     </includes> 
     <useDefaultExcludes>true</useDefaultExcludes> 
    </fileSet> 
    </fileSets> 
</assembly> 

更新
根据您最近的编辑(添加程序集配置),我看到了几件可以改进的事情以及可能的错误原因还有:在源元素定义

  • 你的文件正在使用该项目的artifactId的,但你给它改名为Cambellton,所以你也应该让这种变化是一致的(${project.build.directory}/Cambellton.war,而不是${project.build.directory}/${project.artifactId}.war)。这是最有可能导致生成错误
  • 而不是指向/${project.artifactId}/src我会通过${project.basedir}/src(同为WebContent输出目录)