java - Maven 命令行中的 Java Build Path 模拟是什么?

标签 java eclipse maven tomcat

我正在尝试从 Maven 命令行运行一个已经在 Eclipse 中正常运行的项目。当我在 Eclipse 构建路径上有“Apache Tomcat 7.0”时,它可以工作。当我不这样做时,它会失败,并显示它从命令行给出的确切错误。因此,我怀疑这种差异是从命令行运行它所需要的。如果使用 Maven 在命令行上运行,那么在 Eclipse 中将“Apache Tomcat 7.0”添加为目标运行时的等效项是什么?

最佳答案

Eclipse 为你添加了一些东西,如果你想避免这个问题,你必须使用 maven 手动添加所有你需要的东西,在 <build> tag 你可以添加一个名为 <resources> 的标签,在那里你可以手动添加你在 java 构建路径中添加的所有东西,例如:

<build>
    <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <filtering>true</filtering>
                    <includes>
                        <include>configProperties/serverContextConfig.properties</include>
                    </includes>
                </resource>
                <resource>
                    <directory>src/main/resources</directory>
                    <filtering>false</filtering>
                    <includes>
                        <include>**/*.properties</include>
                    </includes>
                </resource>
                <resource>
                    <directory>src/main/resources</directory>
                    <filtering>false</filtering>
                    <includes>
                        <include>report/documents/*.*</include>
                    </includes>
                </resource>
            </resources>
</build>

默认情况下,Maven 会在 src/main/resources 下查找您项目的资源。

Project
|-- pom.xml
`-- src
    `-- main
        `-- resources

但是,您的所有资源可能不在 src/main/resources 中。因此,您必须通过将以下内容添加到 POM 来指定这些目录。

<project>
 ...
 <build>
   ...
   <resources>
     <resource>
       <directory>[your folder here]</directory>
     </resource>
   </resources>
   ...
 </build>
 ...
</project>

点击here获取更多信息。

关于java - Maven 命令行中的 Java Build Path 模拟是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31617215/

相关文章:

java - RegisterNatives 失败,原因为 'android/webkit/BrowserFrame'

java - 如何创建动态二维数组并在其中存储打乱数组

java - 使用泛型类型扩展类 AsyncTask<Params, Progress, Result>

java - Netbeans 新项目向导不显示 Maven Web 应用程序

java - Maven项目转java项目

java - 如何在 firefox 中使用 webdriver 将 key 发送到电话字段?

eclipse - Grails 3 Eclipse支持

java - Android Cordova 应用程序因 ClassNotFoundException 崩溃?

Eclipse 插件 - TFS(Team Explorer Everywhere)未连接到 TFS 存储库

java - Maven Update Project 在 Eclipse 中到底做了什么?