当前位置: 首页 > 知识库问答 >
问题:

使用Spring Boot和wro4j在IntelliJ中进行热交换

卓云
2023-03-14

我目前正在用AngularJs开发嵌入式服务器的前端/webapp(打包在一个. jar文件中,作为Tomcat运行)。服务器有一些我希望能够在前端使用的APIendpoint。

我目前的方法是使用webjar加载我选择的angularjs版本,然后在webapp文件夹中构建应用程序。结构如下:

├───src
│   ├───main
│   │   ├───docker
│   │   ├───java
│   │   │   └───com
│   │   │       └───...    
│   │   ├───resources
│   │   └───webapp
│   │       └───public
│   │           ├───css
│   │           └───js
│   │               └───controllers
└───target
    ├───classes
    │   ├───com
    │   │   └───... 
    │   └───public
    │       ├───css
    │       └───js
    │           └───controllers
    ├───generated-sources
    │   └───annotations
    ├───generated-test-sources
    │   └───test-annotations
    └───test-classes
        └───com
            └───...

我正在编辑的文件位于 src/main/webapp/public 文件夹中,它们被“编译”到目标/类/公共文件夹中。如果我想在服务器运行时重新加载文件,我必须执行 Run -

但是由于我最初来自“独立”的AngularJs开发,我习惯于拥有真正的livereload和一个构建链,该构建链缩小并连接了js / css文件以进行优化(grunt,bower)。

现在我已经研究了wro4j,并且能够很好地设置它。我仍然缺少的一件事是热重新加载。甚至上述方法也不再适用于wro4j,因此唯一的选择是重新编译整个应用程序,以查看css/javascript或HTML内部的更改。有没有一个简单的方法来解决这个问题?

我的首选方法是在开发(在调试中运行服务器)时使用未合并/未连接的版本,并且仅在部署应用程序时执行整个构建链(或仅运行)

我有什么选择?


共有2个答案

孙莫希
2023-03-14
匿名用户

我最终做的可能有点过头了,但是我没有找到任何其他合适的解决方案。

我构建了一个Gruntfile.js(基于angularjs的yeoman生成器),能够拥有livereload和构建链特性(concat、minify等)。).有了这个,我也可以在前端工作,而不必启动服务器。这个文件中唯一的“恶意代码”是< code>grunt build将它的dist文件夹复制到< code >/src/main/resources/static 文件夹,这样它就被“编译”到。战争档案。

我使用了一些maven插件,以便能够在构建时执行所需的命令(npm install、bowerinstall、gruntbuild、gruntcle)

<plugin>
 <groupId>com.github.eirslett</groupId>
 <artifactId>frontend-maven-plugin</artifactId>
 <version>0.0.22</version> <!-- last version supported by maven 2 -->
 <dependencies>
     <dependency>
         <groupId>org.codehaus.plexus</groupId>
         <artifactId>plexus-utils</artifactId>
         <version>2.1</version>
     </dependency>
 </dependencies>
 <configuration>
     <nodeVersion>v0.10.18</nodeVersion>
     <npmVersion>1.3.8</npmVersion>
     <workingDirectory>src/main/frontend</workingDirectory>
 </configuration>
 <executions>
     <execution>
         <id>install node and npm</id>
         <goals>
             <goal>install-node-and-npm</goal>
         </goals>
         <phase>generate-resources</phase>
     </execution>
     <execution>
         <id>npm install</id>
         <goals>
             <goal>npm</goal>
         </goals>

         <configuration>
             <arguments>install</arguments>
         </configuration>
     </execution>
     <execution>
         <id>bower install</id>
         <goals>
             <goal>bower</goal>
         </goals>

         <configuration>
             <arguments>install</arguments>
         </configuration>
     </execution>
     <execution>
         <id>npm rebuild</id>
         <goals>
             <goal>npm</goal>
         </goals>

         <configuration>
             <arguments>rebuild node-sass</arguments>
         </configuration>
     </execution>
     <execution>
         <id>grunt build</id>
         <goals>
             <goal>grunt</goal>
         </goals>

         <configuration>
             <arguments>build</arguments>
         </configuration>
     </execution>
     <execution>
         <id>npm install before clean</id>
         <goals>
             <goal>npm</goal>
         </goals>

         <phase>clean</phase>

         <configuration>
             <arguments>install</arguments>
         </configuration>
     </execution>
     <execution>
         <id>grunt clean</id>
         <goals>
             <goal>grunt</goal>
         </goals>

         <phase>clean</phase>

         <configuration>
             <arguments>clean</arguments>
         </configuration>
     </execution>
 </executions>
</plugin>

我希望这能为我的方法提供一个宽泛的思路。这当然不是完美的,特别是因为它增加了整个项目的构建时间。

徐经武
2023-03-14

查看Spring Boot DevTools文档 http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-devtools.html

玛文。

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
</dependencies>

格拉德。

dependencies {
    compile("org.springframework.boot:spring-boot-devtools")
}

它包括一个内置的LiveReload服务器。你应该可以通过运行“Make Project”从IntelliJ更新你的应用程序

 类似资料:
  • 我正在考虑为我的公司获得JRebel许可证。 然而,我刚刚发现IntelliJ已经有了一个内置的功能来热部署类。 欢迎所有反馈/经验/建议。

  • 我对IntelliJ相当陌生,我正在使用它开发一个将spring-boot作为后端服务器的AngularJS应用程序。当我对HTML或JavaScript代码进行任何更改时,我总是必须重新启动应用程序服务器。是否有提供HTML/JS/CSS文件热交换的配置或插件? 我使用的是IntelliJ Community Edition 2017.2.17、Angular 1.4.4、Node 4.2.1和

  • 本文向大家介绍IntelliJ IDEA 中使用jRebel进行 Java 热部署教程图解,包括了IntelliJ IDEA 中使用jRebel进行 Java 热部署教程图解的使用技巧和注意事项,需要的朋友参考一下 jrebel JRebel是一套JavaEE开发工具。JRebel允许开发团队在有限的时间内完成更多的任务修正更多的问题,发布更高质量的软件产品。 JRebel是收费软件,用户可以在J

  • 本文向大家介绍SpringBoot项目在IntelliJ IDEA中如何实现热部署,包括了SpringBoot项目在IntelliJ IDEA中如何实现热部署的使用技巧和注意事项,需要的朋友参考一下 spring-boot-devtools是一个为开发者服务的一个模块,其中最重要的功能就是自动应用代码更改到最新的App上面去。 原理是在发现代码有更改之后,重新启动应用,但是速度比手动停止后再启动更

  • 我想把@AutoWired注释变成一个“方面”。我想在我的方面中注入一个存储库,但是当我试图调用autowired类的方法时,出现了NullPointException。 我已经尝试在aspect类上添加,但我出现了同样的错误。 如果我不使用aspect类,而是使用,我可以毫无问题地调用存储库。 一些文档谈到了spring的xml文件配置,但在spring boot,我没有这些文件。 这里是pom

  • wro4j 是一个 Web 资源优化工具。众所周知,到服务器加载一个大的文件比加载两个小的文件快,因为会增加 HTTP 交互的次数并且大部分浏览器在任何时候对于同一个服务器,只保持两个连接。开发 wro4j 项目的目的是减少加载一个页面的请求次数和传输的数据量。 点击下图查看大图。