如何防止 NetBeans 在打开 Web 应用程序项目时生成 context.xml?

How to prevent NetBeans from generating context.xml when opening a web application project?

在 NetBeans 8.1 中,我创建了一个 "Web Application with Existing Sources" 类型的新项目。我在 META-INF 中删除了 context.xml,因为我不想在那里(我有我的理由)。但是每当我重新启动 NetBeans 或只是关闭并重新打开项目时,NetBeans 都会再次生成 context.xml 文件。有什么办法可以避免吗?我试图搜索但没有成功。感谢您的帮助!

我还没有想出阻止它重新生成的方法,但我至少想出了一个解决方法(使用 maven)来阻止它 使用 生成的文件(这是真正引起头痛的原因)。我只是用测试 context.xml 文件覆盖生成的 context.xml(是的,对于此解决方法,您需要在某处有 some 类型的 context.xml 文件) .我还需要从生产 war 文件中排除测试 context.xml 文件。

我的测试 context.xml 文件已签入到 src/test/webapp/META-INF/context.xml。我希望它复制到目标目录(覆盖生成的文件)但不包含在 war 文件中。所以在我的 pom.xml 中,我配置了 maven-war-插件,如下所示:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <version>3.2.3</version>
  <configuration>
    <webResources>
      <resource>
        <!-- location of context.xml used for integration tests -->
        <directory>src/test/webapp/META-INF</directory>
        <!-- setting stuff in the test file, you might not need this -->
        <filtering>true</filtering>
        <!-- overwrites the context.xml file generated by Netbeans -->
        <targetPath>META-INF</targetPath>
      </resource>
    </webResources>
    <!-- don't include test context.xml with the war file -->
    <packagingExcludes>META-INF/context.xml</packagingExcludes>
  </configuration>
</plugin>

我知道这不能回答有关如何停止重新生成文件的问题,但如果您的情况与我一样,那么它可能仍然有帮助。

我发现如果我编辑项目的项目属性,并从“运行”选项卡下选定的“服务器”字段中删除 'Tomcat',netbeans 将停止创建 context.xml .

我可能还从 nb-configuration 中手动删除了这一行。xml:

        <org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>Tomcat</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>

虽然我不确定这是否有必要,但我的猜测是没有,但请随意尝试并在下面发表评论,或者如果您弄清楚了,请编辑此答案。