tomcat - IntelliJ 中的 "Update Resources"从目标目录中删除更新的文件

标签 tomcat intellij-idea spring-boot thymeleaf tomcat8

精简版

当我更改我的应用程序中的资源,然后尝试热部署它们时,文件被删除而不是从 target/ 目录中更新,我不明白为什么。

长版

我有一个 Java 8 + Tomcat 8 + Spring Boot + Thymeleaf 项目,我正在用完 IntelliJ。当我更改文件时,例如 src/main/resources/static/css 目录中的 CSS 文件,并运行 Update ResourcesUpdate classes and resources,文件从target/classes/static/css删除而不是更新。 Tomcat 日志中未打印任何有关该文件的内容,IntelliJ 日志(~/Library/Logs/IntelliJIdea13/idea.log)中未打印任何有关删除文件的内容...它就消失了。

Tomcat 8 设置为外部应用服务器(不是内置的 Spring Boot 嵌入式服务器),配置如下。我在 IntelliJ 运行配置设置中唯一自定义的是将 CATALINA_BASE 指定为与​​“Tomcat Base”相同的值,如下所示:

Tomcat Home: /usr/local/tomcat8
Tomcat Base: /path/to/my/catalina/base
Java Env Vars: CATALINA_BASE=/path/to/my/catalina/base

...如果我不这样做,CATALINA_BASE 将设置为 /Users/me/Library/Caches/IntelliJIdea13/tomcat/Unnamed_demo_app,这似乎是我的 < strong>real catalina base,我到处都是 404。这可能是一个转移注意力的问题,或者是解开谜团的关键。

额外的,可能无用的信息

这是 idea.log 中的相关(但无趣)输出:

INFO - ij.compiler.impl.CompileDriver - COMPILATION STARTED (BUILD PROCESS)
INFO - j.compiler.server.BuildManager - BUILDER_PROCESS [stdout]: Build process started. Classpath: /Applications/IntelliJ IDEA 13.app/lib/jps-launcher.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/lib/tools.jar:/Applications/IntelliJ IDEA 13.app/lib/optimizedFileManager.jar:/Applications/IntelliJ IDEA 13.app/lib/ecj-4.3.2.jar
INFO - lij.compiler.impl.CompilerUtil -   COMPILATION FINISHED (BUILD PROCESS); Errors: 0; warnings: 0 took 3709 ms: 0 min 3sec

该应用程序配置为进行 WAR 部署,自定义 catalina 基础包含库存 conf/server.xmlconf/web.xml,以及各种第 3 方lib 中提供的库。

这是我的 POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>myapp</artifactId>
    <version>0.1-BETA</version>
    <packaging>war</packaging>

    <properties>
        <spring-boot-version>1.2.1.RELEASE</spring-boot-version>
        <spring-version>4.1.4.RELEASE</spring-version>
    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.1.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
            <version>${spring-boot-version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
            <version>${spring-boot-version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <version>${spring-boot-version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.34</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>dojo</artifactId>
            <version>1.10.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <!-- for equals/hash/toString builder -->
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <!-- Spring/Mail integration -->
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.7</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <!-- Spring/Mail integration -->
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${spring-version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <!-- connection pooling -->
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
            <version>2.3.5</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

</project>

我不确定关于这个问题还有什么值得一提的,尽管我觉得我提供的内容没有用。如果有任何我应该添加的信息,请添加评论。

最佳答案

我猜你正在使用 maven 插件。

By default, any src/main/resources folder will be added to the application classpath when you run the application and any duplicate found in target/classes will be removed. This allows hot refreshing of resources which can be very useful when developing web applications. For example, you can work on HTML, CSS or JavaScipt files and see your changes immediately without recompiling your application. It is also a helpful way of allowing your front end developers to work without needing to download and install a Java IDE.

如果您可以直接从 IDEA 启动应用程序(只需运行主类),我会这样做。否则,通过配置插件禁用该功能:

<build>
  ...
  <plugins>
    ...
    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
      <version>1.2.3.RELEASE</version>
      <configuration>
        <addResources>false</addResources>
      </configuration>
    </plugin>
    ...
  </plugins>
  ...
</build>

http://docs.spring.io/spring-boot/docs/current/maven-plugin/usage.html

关于tomcat - IntelliJ 中的 "Update Resources"从目标目录中删除更新的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29640437/

相关文章:

eclipse - 访问Eclipse启动的Tomcat失败

apache - Tomcat 关闭时禁用 Apache 503 响应

Java Jar - 类路径问题

Ubuntu 显示不正确的 IntelliJ 应用程序标题

java - Gradle未在intelliJ idea 2016.2中下载依赖项

java - 集群 tomcat 的同步/互斥

java - 在另一台机器上运行 Spring Boot 应用程序

java - 如何使用 Java Spring Boot 更新 MongoDB 中的数组字段?

maven - Spring 启动 : is there a way to show the POM version number in some endpoint easily?

java - 如何正确重启 Spring Boot 应用程序?