立即重新部署 Java EE 应用程序

发布于 2024-12-09 17:24:49 字数 1104 浏览 0 评论 0原文

我对 Java EE 很陌生,一直在为部署过程的缓慢而苦苦挣扎,并想知道我是否做错了什么。我对 Django 有经验,其中代码的更改会立即发生,而且似乎热部署 Java EE 应用程序有点令人困惑——有多种东西声称可以热部署(Glassfish、Eclipse manic hotdeploy、Jetty hotdeploy、JRebel 等)。 )。

我的项目是一个 Maven 项目,我使用 Netbeans 进行部署。该站点使用 Spring、JSF 和 Hibernate 框架。

在Netbeans中,保存时部署,根据下面的屏幕截图似乎已启用,但单击/取消单击是不可能的,因为它声称从我的pom.xml中获取信息(尽管我的pom.xml中没有这样的字段(仅依赖项))。 在此处输入图像描述

现在,对某些文件的更改似乎立即生效。这些包括: - JSF 文件 - 静态文件

更改为以下需要部署: - 任何 XML 文件 - 任何属性文件,甚至本地化属性文件 - 任何 java 文件的

更改都需要我手动部署,并且重新部署需要半分钟,即使我目前只有 2-3 个类,基本上是一个用户类和一个授权类。该项目目前只允许登录,尽管如此,编译大约需要几秒钟;并且容器(Glassfish)似乎消耗了大约 600 MB 的 RAM,甚至在几次部署后出现 PermGen 错误,我需要使用任务管理器终止 java 进程。 (我读到这与每次重新部署后垃圾收集器泄漏有关,我什至使用 jhat 生成配置文件,但出现了数千个类的列表,我的类,Spring,Hibernate 类等)

我有也听说过 jrebel,并尝试运行它,但它似乎与我的 Netbeans 版本(7.0)不兼容,即使它似乎可以运行,对任何 java 文件的任何修改仍然需要重新部署。

我可以采取什么措施来解决这些问题,或者在 Java EE 中,每次更改任何 Java 文件后等待大约 1 分钟是正常现象吗?这个问题极大地降低了生产力。

这是部署应用程序时我的 Glassfish 输出: http://pastebin.com/7FhZ6AVh

I am quite new to Java EE and have been struggling with the slowness of the deployment process, and wonder if I'm doing something wrong. I am experienced with Django where the changes to code immediately occur, and it seems that hot deploying Java EE applications are a bit confusing -- there are multiple things which claim to hot deploy (Glassfish, Eclipse manic hotdeploy, Jetty hotdeploy, JRebel etc.).

My project is a Maven project and I'm using Netbeans to deploy. The site uses Spring, JSF and Hibernate frameworks.

In Netbeans, Deploy on Save, according to the following screenshot seems to be enabled, but clicking/unclicking is not possible since it claims to get the info from my pom.xml (though there is no such field in my pom.xml (only dependencies)).
enter image description here

Now, changes to some files seem to be effective immediately. These include:
- JSF files
- Static files

Changes to following require deployment:
- Any XML file
- Any properties file, even localization properties files
- Any java file

Changes to those require me to deploy manually and redeploying takes half a minute even though I currently have only 2-3 classes, basically a single user class and an authorization class. The project allows just logins at the moment, and despite this, the compilation takes around a few seconds; and the container (Glassfish) seems to consume around 600 MB of RAM and even gives PermGen errors after a few deployments and I need to kill the java process using Task Manager. (I have read that this is related to garbage collector leaking after each redeploy, and I have even used jhat to generate a profile, but was presented with a list of thousands of classes, my classes, Spring, Hibernate classes etc.)

I have heard about jrebel as well, and tried running it, but it seems that it is not compatible with my Netbeans version (7.0) and even though it seems to run, any modification to any java file still requires a redeploy.

Is there anything I can do to remedy these issues, or is it just normal in Java EE to wait for around 1 minute after each change to any Java file? This issue kills productivity significantly.

Here is my Glassfish output when deploying the application: http://pastebin.com/7FhZ6AVh

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

剪不断理还乱 2024-12-16 17:24:49

我既没有找到可靠的消息来源,也没有找到官方消息来源,但既然你没有答案,我想指出我发现的两件事。

第一个是 NetBeans 站点上的此常见问题解答,描述如何为 Maven 打开保存时编译项目。看来此设置默认情况下处于关闭状态,并且仅在测试时默认处于打开状态。为了方便起见:

转到项目属性对话框的编译面板,将其也打开以执行主源代码。

第二个是,我必须强调,我不太完全理解这一点,NetBeans 部署 Web 应用程序似乎有两种不同的方式。第一种方法是就地部署,它与手动将 .war 文件部署到服务器相同。第二种是增量部署,如果它类似于增量编译,则意味着当您的应用程序热部署时,您仅部署更改的文件。

当您从项目的上下文菜单中单击“运行”或“部署”时,就地部署似乎是默认的部署方法。当您的项目已经部署并再次单击“运行”(或使用“运行”工具栏按钮)时,就会发生增量部署。

我想指出,NetBeans 常见问题解答虽然位于 netbeans.org 网站上,但并不是官方出版物。任何人都可以创建常见问题解答,并且该信息可以而且将会在不进行修改的情况下过时。

编辑:经过一番思考,我决定所谓的增量部署并不是一种不同的部署方式,只是当您第二次运行应用程序时,它会执行以下操作:增量部署。

编辑:请注意,上面的说明将您指向编译面板,而不是您在屏幕截图中选择的运行面板。这是我的屏幕截图,显示您需要在编译面板下拉列表中选择用于应用程序和测试执行,默认值是仅用于测试执行代码>

编译面板下拉菜单

I've found neither credible nor official sources but since you have no answers I'd like to point out two things I've discovered.

The first is this FAQ on the NetBeans site describing how to turn on compile on save for a Maven project. It appears that this setting is off by default and only on by default for tests. For convenience:

Go to the project properties dialog, Compile panel, to turn it on for main source execution as well.

The second is, and I must stress that I don't quite understand this completely, there seems to be two different ways that NetBeans deploys a Web Application. The first way is an in-place deployment that appears to be the same as deploying a .war file to the server manually. The second is an incremental deployment, which if it's anything like incremental compilation it means that when your app is hot-deployed you are only deploying the changed files.

The in-place deployment seems to be the default method of deployment when you either click Run or Deploy from the projects' context menu. The incremental deployment happens when your project is already deployed and you click Run again (or use the Run toolbar button).

I'd like to point out that the NetBeans FAQ, although on the netbeans.org website is not an official publication. Anyone can create a FAQ and the information can and will become obsolete without revision.

Edit: After a little reflection I've decided that the so called incremental deployment is not a different way of deployment it's just that the second time you Run your application it does an incremental deployment.

Edit: Notice that the instruction above is pointing you to the Compile panel as opposed to the Run panel that you have selected in your screenshot. Here's my screen shot showing that you need to choose for both application and test execution in the Compile panel drop down and that the default is for test execution only

Compile panel drop down

不知在何时 2024-12-16 17:24:49

JRebel 与 NetBeans 7.0 (http://plugins.netbeans.org/plugin/22254/jrebel-netbeans-plugin) 兼容,事实上它与任何 IDE 兼容。

JRebel is compatible with NetBeans 7.0 (http://plugins.netbeans.org/plugin/22254/jrebel-netbeans-plugin) and in fact it is compatible with any IDE out there.

眸中客 2024-12-16 17:24:49

这是由 NetBeans 团队的 Geertjan Wielenga 制作的精彩视频,介绍了如何在 NetBeans 7.2.1 和 GlassFish 3.1.2 上设置 JRebel:

如何在 NetBeans IDE 中开始使用 JRebel: youtube.com/watch?v=kveXKv2q4Ec" rel="nofollow">http://www.youtube.com/watch?v=kveXKv2q4Ec

This is a great video by Geertjan Wielenga from the NetBeans team that walks through setting up JRebel on NetBeans 7.2.1 and GlassFish 3.1.2:

How to Get Started with JRebel in NetBeans IDE: http://www.youtube.com/watch?v=kveXKv2q4Ec

樱娆 2024-12-16 17:24:49

“保存时编译”对我来说速度减慢了很多,但后来我发现的另一件事是 Netbeans 中的“应用代码更改”按钮,该按钮仅在调试模式下可见。 (图中右侧的绿色按钮)

这对于应用Java代码更改很有用;它并不是每次都有效,但我认为如果更改不是方法添加并且 bean 是请求范围的,那么它在大多数情况下都有效。我认为这相当于手动保存时编译,但比重新部署更好。

应用代码更改

"Compile on Save" slowed things a lot for me, but another thing I have found out afterwards is the "Apply Code Changes" button in Netbeans, that is only visible in Debug mode. (The green button at the right in the picture)

This is useful to apply Java code changes; it doesn't work each time, but I think it works most of the time if the change is not a method addition and the bean is request scoped. I think this does what Compile on Save manually, but it's better than redeploying.

Apply Code Changes

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文