简体   繁体   English

在没有战争的情况下在tomcat上运行Java Web应用程序

[英]Running Java web application on tomcat without war

I have been assigned to work on a Java web application built on Spring/Hibernate using Wicket for the front-end, maven for dependency management, running on Tomcat server. 我被分配去在Spring / Hibernate上构建的Java Web应用程序上工作,该Web应用程序在Tomcat服务器上运行,使用Wicket进行前端,使用maven进行依赖项管理。

Using netbeans, whenever I make a change to the code, I hit run, and the IDE proceeds to rebuild the project, compiling the code to class files, and then packaging it into a .war file, which I understand is just a regular archive and nothing special. 使用netbeans,每当我对代码进行更改时,我都会运行run,IDE会重新生成项目,将代码编译为类文件,然后将其打包为.war文件,据我所知这只是一个常规存档没什么特别的

But it takes up to 10 minutes to build everything, even if it's just one small little change to one of the wicket stuff or hibernate stuff or whatever, and it's very unproductive. 但是,构建所有内容最多需要10分钟,即使这只是对检票口的东西或冬眠的东西之类的一小笔小改动,也是非常无用的。

Looking at the deploy process, the biggest bottlenecks are 从部署过程来看,最大的瓶颈是

  1. Copying files from a src folder to a target folder 将文件从src文件夹复制到目标文件夹
  2. Packaging everything into war archives 将所有内容打包到战争档案中
  3. Deploying it to tomcat 部署到tomcat

How can I speed up the development process? 如何加快开发过程? While 10 minutes per build may be relatively little compared to some other applications out there, time wasted is still time wasted to me. 虽然与其他一些应用程序相比,每次构建10分钟的时间可能相对较少,但是浪费的时间对我来说仍然是浪费的。

Here's a better suggestion: Use Spring Boot . 这是一个更好的建议:使用Spring Boot You can run your app as an executable JAR on a JVM without a servlet engine or Java EE app server. 您可以在没有servlet引擎或Java EE应用程序服务器的情况下将应用程序作为可执行JAR在JVM上运行。

I understand your frustration. 我了解您的无奈。 I have been through that. 我已经经历过了。 My cycle time was 20 minutes for a complete redeployment, by which I mean stopping Tomcat, recopying wars and jars and then restarting the server. 我的周期时间是20分钟,以进行完全重新部署,这是指停止Tomcat,重新复制war和jars,然后重新启动服务器。

Over time, we refactored our codebase to make every functionality (or web resource) a war and we went from one war that did everything to about 100 wars that had each a single concern. 随着时间的流逝,我们重构了代码库,以使每项功能(或网络资源)成为一场战争,我们从一场无所不能的战争变成了大约100场战争,每场战争只涉及一个方面。 If there were some shared modules between wars, we packaged the module as a jar and deployed it as a shared library. 如果两次大战之间存在一些共享模块,我们将模块打包为jar并将其部署为共享库。 As everybody is working with one web resource at a time, there is always just one war concerned at a time, so redeploying a single war is enough, which is like few seconds (with tomcat-maven-plugin automatically). 由于每个人一次都在使用一个Web资源,因此总是只涉及一次战争,因此重新部署一次战争就足够了,这就像几秒钟(自动使用tomcat-maven-plugin)。 However if a shared module is concerned, Tomcat had to be restarted completely. 但是,如果涉及共享模块,则必须完全重新启动Tomcat。

I would suggest you break your application into many deployables if that is possible. 如果可能的话,我建议您将应用程序分成许多可部署的部分。 For start, you can break your front and backend into two wars and divide further when possible. 首先,您可以将前端和后端分成两次战争,并在可能的情况下进一步分割。

You have at least 2 possibilities here: 您至少有两种可能性:

1) Use JRebel: https://zeroturnaround.com/software/jrebel/ 1)使用JRebel: https ://zeroturnaround.com/software/jrebel/

2) Go in the app folder of Tomcat: there you can find the folder with the unzipped content of the war file, just copy paste there (in the proper location) the JSP as it is, if you made a change into a jsp, or copy past the .class file of the classes you have changed... In most of the case no restart of Tomcat is needed. 2)进入Tomcat的app文件夹:您可以在其中找到包含war文件解压缩内容的文件夹,只需按原样复制粘贴到JSP(在适当的位置),如果您将其更改为jsp,或复制过去更改过的类的.class文件...在大多数情况下,无需重新启动Tomcat。

I use Eclipse for development. 我使用Eclipse进行开发。 But I believe options for both IDEs would be similar. 但是我相信这两种IDE的选择都是相似的。

As you are using maven so default maven goal for run would be 'mvn package' which cleans target directory, create class files, run unit tests and prepare war file and deploy in tomcat. 当您使用Maven时,运行的默认Maven目标将是“ mvn软件包”,该目标将清理目标目录,创建类文件,运行单元测试并准备war文件并在tomcat中进行部署。

Now, you should add a runtime server such as tomcat using New -> Server. 现在,您应该使用New-> Server添加一个运行时服务器,例如tomcat。 and use Run as -> Run on server on your project and provide tomcat server as runtime. 并在项目的服务器上使用“运行方式->运行”,并提供tomcat服务器作为运行时。 Next time when you change your code updated classes are hot deployed as long as tomcat is running. 下次更改代码时,只要tomcat正在运行,更新的类就会被热部署。 So you can test your code during development only. 因此,您只能在开发期间测试代码。 When you want to create war only then use mvn package to create war file. 当您只想创建war时,请使用mvn包创建war文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM