maven - 如何使用tomcat :run?运行maven war依赖

标签 maven tomcat plugins

我正在为我当前的项目使用 maven。现在,我有了 war 依赖:

<dependency>
   <groupId>org.dojotoolkit</groupId>
   <artifactId>dojo-war</artifactId>
   <version>1.8.1</version>
   <type>war</type>
   <scope>runtime</scope>
</dependency>

我在构建 war 神器时没有任何问题。为此,我添加了这个插件:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1.1</version>
        <configuration>
            <overlays>
                <overlay>
                    <groupId>org.dojotoolkit</groupId>
                    <artifactId>dojo-war</artifactId>
                    <targetPath>js/dojo-1.8.1</targetPath>
                    <excludes>
                        <exclude>WEB-INF/**</exclude>
                        <exclude>META-INF/**</exclude>
                    </excludes>
                </overlay>
            </overlays>
        </configuration>
    </plugin>

但是,当我运行以下 mvn 命令时 mvn tomcat7:run 我看不到任何 javascript 资源。看起来没有添加 war 依赖。

有人可以帮我吗?

提前致谢。

最佳答案

欢迎来到 Stack Overflow Emelendez。

你应该阅读这篇文章:http://webtide.intalio.com/2008/07/dojo-toolkit-maven-repository/

确实,dojo-war 依赖项允许您将一些文件添加到源中,但您必须指定一些额外的操作才能将其包含在最终 war 中。

在 Maven 中,依赖项只能是您尝试编译的语言(虽然不是很准确,但这已经足够了)。如果你想添加包含在 zip/war/targz 中的其他资源(文件、图像、javascript),你必须明确地提取它们。这是我之前提供的链接中提到的内容:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>unpack dojo</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>unpack</goal>
            </goals>
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>org.dojotoolkit</groupId>
                        <artifactId>dojo</artifactId>
                        <version>${project.version}</version>
                        <type>zip</type>
                    </artifactItem>
                </artifactItems>
                <outputDirectory>${project.build.directory}/dojo</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

(小心,我不确定这个配置是否准确,根据你的 pom.xml,你的依赖项似乎是 dojo-war,而不是文档所说的 dojo)

这会将 dojo 库提取到输出目录中,然后放入您的 war 中。

关于maven - 如何使用tomcat :run?运行maven war依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15595608/

相关文章:

google-app-engine - Appengine 框架未运行

java - 无法使用 Tomcat Manager 部署 war 文件

jquery - 有 jQuery jEditable 多选插件吗?

java - 如何在指定 Artifact 时自动引入 jar-with-dependencies

java - javax.servlet.jsp-api 的用途是什么

java - 抛出 java.net.UnknownHostException 时在哪里检查/设置超时?

spring-mvc - Spring Boot Tomcat 容器部署错误

java - 如何在 Apache Tomcat 中部署带定时器的 POJO 文件

python - pytest_runtest_teardown 是否要求跳过测试而 pytest_runtest_setup 不是?

plugins - System.IO.FileNotFoundException : Could not load file or assembly 'Microsoft. Xrm.Client