更改maven生成的war文件名时的问题

时间:2015-12-17 06:12:25

标签: maven war

我刚跟着这个question并修改了我的pom来创建不同的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>

这是Modified(想要创建Cambellton.war)

> [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

尝试构建时,会出错,但会创建war文件。我认为在尝试创建zip文件时会出现问题。这是错误消息

<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>

编辑1

这是webapp.xml

<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>

编辑2: 还添加了$符号,但仍然给出了同样的错误 正如

<?php
date_default_timezone_set('Asia/Kolkata');

$timestamp = time();
$date_time = date("d-m-Y (D) H:i:s", $timestamp);
echo "Current date and local time on this server is $date_time";
?>

1 个答案:

答案 0 :(得分: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>

<强>更新
根据您的最新编辑(添加装配配置),我看到了一些可以改进的事情以及潜在的错误原因:

  • 您在source元素中定义的文件正在使用项目的artifactId,但您将其重命名为Cambellton,因此您还应使其与此更改保持一致(${project.build.directory}/Cambellton.war而不是{{ 1}})。这很可能导致构建错误
  • 而不是指向${project.build.directory}/${project.artifactId}.war我会将其替换为/${project.artifactId}/src${project.basedir}/src输出目录相同)