如何在不重启服务器的情况下编译单个/多个java文件?是否有相同的Eclipse插件?

时间:2023-01-14 11:08:41

I want to compile multiple java files in my Application without restarting Weblogic and Tomcat. Otherwise, this takes a lot of time. For this I got one Hotswap plugin in Eclipse, but this is not working in all the cases. It says it works for single file compile. Even if I use that it is not working in all the cases.

我想在我的应用程序中编译多个java文件,而无需重新启动Weblogic和Tomcat。否则,这需要很多时间。为此,我在Eclipse中获得了一个Hotswap插件,但在所有情况下都无法使用。它说它适用于单个文件编译。即使我使用它在所有情况下都不起作用。

Is there any other way that I can do this or is there any other plugin/script/software which can help me in this?

有没有其他方法可以做到这一点,还是有任何其他插件/脚本/软件可以帮助我吗?

If there are some open source ones, it will be very helpful.

如果有一些开源的,那将非常有帮助。

Thanks in Advance.

提前致谢。

6 个解决方案

#1


One thing is compiling the classes, but you also need the JAVA VM to reload the classes and use them, which is called hot-swapping. For the best available hot-swapping of classes you'll need something like javarebel. It allows you to hot-reload a lot more types of code-changes than the regular SUN JVM. If you run your deployment in exploded-mode you're home free, and can test any code change in a second or so. We're fairly test-driven, so I only use javarebel in that short phase when I assemble the whole application, but it works really well.

有一件事是编译类,但您还需要JAVA VM来重新加载类并使用它们,这称为热交换。对于最好的热交换课程,你需要像javarebel这样的东西。它允许您热插入比常规SUN JVM更多类型的代码更改。如果您在爆炸模式下运行部署,那么您可以在家中免费使用,并且可以在一秒左右的时间内测试任何代码更改。我们是相当测试驱动的,所以当我组装整个应用程序时,我只在短暂的阶段使用javarebel,但它工作得非常好。

#2


The Java HotSpot VM does this automatically, but not in all cases...

Java HotSpot VM会自动执行此操作,但并非在所有情况下都执行此操作...

First, you must be running a "debug" session, not a "run" session.

首先,您必须运行“调试”会话,而不是“运行”会话。

Next, some changes will force a restart. The basic idea is that if the interface to the class change (the method sigs, not an actual Java interface), the VM can't replace the class contents inline.

接下来,一些更改将强制重新启动。基本思想是,如果类的接口发生更改(方法sigs,而不是实际的Java接口),则VM无法内联替换类内容。

You shouldn't need a plugin for this, just a recent-ish VM.

你不应该需要一个插件,只需要一个最新的虚拟机。

This happens under several circumstances like

这种情况发生在几种情况下

  • adding methods
  • removing methods
  • changing method signatures
  • 改变方法签名

  • changing the class hierarchy (superclasses, implemented interfaces)
  • 更改类层次结构(超类,实现的接口)

It can also happen if you introduce an error into the class. (For errors like mismatched curly braces)

如果在类中引入错误,也会发生这种情况。 (对于不匹配的花括号等错误)

When you save a Java file, eclipse compiles it. If there is an error, eclipse inserts an exception throw to indicate that there is an unresolved compilation error. (It does this so when you run you don't just see the last successful compilation, making it obvious you have a compiler error)

保存Java文件时,eclipse会编译它。如果有错误,eclipse会插入一个异常抛出,表明存在未解决的编译错误。 (它是这样做的,所以当你运行时不要只看到最后一次成功的编译,很明显你有一个编译器错误)

#3


I don't know Eclipse, but I do use Netbeans. Netbeans does this pretty well. The latest version even has an option to automatically recompile when you save a java file.

我不懂Eclipse,但我确实使用Netbeans。 Netbeans做得很好。最新版本甚至可以选择在保存java文件时自动重新编译。

I know this doesn't exactly answer your question. You can probably use both Netbeans and Eclipse depending on what part of the project you're working on.

我知道这并不能完全回答你的问题。您可以使用Netbeans和Eclipse,具体取决于您正在处理的项目的哪个部分。

EDIT: With Tomcat you can reload the web app. This is really only useful if Tomcat is looking at the new class. If your project is compiled to a build directory first and a WAR is then created from this you can go into Tomcat and install the web app and instead of pointing at a WAR point at the build directory.

编辑:使用Tomcat,您可以重新加载Web应用程序。这只有在Tomcat查看新类时才有用。如果首先将项目编译到构建目录,然后从中创建WAR,则可以进入Tomcat并安装Web应用程序,而不是指向构建目录中的WAR点。

In Tomcat you may have to put a site config file under tomcat/conf/Catalina/localhost. The contents of this file looks like this:

在Tomcat中,您可能必须在tomcat / conf / Catalina / localhost下放置一个站点配置文件。该文件的内容如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="C:/Projects/MyWebApp/build/web" path="/MyWebApp"/>

Instructions for reloading here: http://www.cs.ucl.ac.uk/teaching/java/tomcatfaq.html#changeservlet

这里重新加载的说明:http://www.cs.ucl.ac.uk/teaching/java/tomcatfaq.html#changeservlet

If you do this a few times though Tomcat will run out of memory. This is because of something called PermGenSpace. Read up about it if you want to know more. The solution is to increase the JVM memory, the PermGenSize (with -XX:MaxPermSize) and finally restarting Tomcat occasionally.

如果你这样做了几次虽然Tomcat将耗尽内存。这是因为PermGenSpace之类的东西。如果您想了解更多,请阅读相关内容。解决方案是增加JVM内存,PermGenSize(使用-XX:MaxPermSize),最后偶尔重启Tomcat。

EDIT2: If reloading the app causes you to be logged out you may be able to easily get the container to serialize your session data to disk by adding 'implements Serializable' to some of your classes. Then you should not need to login after reloading the app.

编辑2:如果重新加载应用程序导致您注销,您可以通过在某些类中添加“implements Serializable”,轻松地让容器将会话数据序列化到磁盘。然后你不需要在重新加载应用程序后登录。

#4


I agree that it is very tedious to redeploy all the time when developing.

我同意在开发时一直重新部署是非常繁琐的。

I would suggest you look into MyEclipse which has a very good hotdeploy mechanism which works well with Tomcat, and which is quite affordable and has a 30 day trial.

我建议你看一下MyEclipse,它有一个非常好的hotdeploy机制,可以很好地与Tomcat一起使用,而且价格实惠且有30天的试用期。

The stock Java EE mechanism in Eclipse for redeploying to servers is nowhere as fast.

Eclipse中用于重新部署到服务器的库存Java EE机制无处可寻。

#5


I guess I don't really see where the problem is. Here is what I do and the changes load almost instantaneously. I have an Ant script that compiles the .java and .jsp files for me, puts them in the appropriate directories under webapps and changes the web.xml file if necessary (or at least touches it to notify tomcat of the changes). If you need help on doing any of that with Ant, I'd be happy to help. Btw I do not use WAR files for deployment on my testing machine. That would be a lot slower I guess.

我想我真的不知道问题出在哪里。这就是我所做的,变化几乎瞬间加载。我有一个Ant脚本为我编译.java和.jsp文件,将它们放在webapps下的相应目录中,并在必要时更改web.xml文件(或者至少触摸它以通知tomcat更改)。如果你在使用Ant做任何帮助时需要帮助,我很乐意提供帮助。顺便说一下,我没有在我的测试机上使用WAR文件进行部署。我想这会慢得多。

#6


very easily done if you read this page: See http://blog.redfin.com/devblog/2009/09/how_to_set_up_hot_code_replacement_with_tomcat_and_eclipse.html Thank you Dan Fabulich

如果您阅读本页很容易做到:请参阅http://blog.redfin.com/devblog/2009/09/how_to_set_up_hot_code_replacement_with_tomcat_and_eclipse.html谢谢Dan Fabulich

#1


One thing is compiling the classes, but you also need the JAVA VM to reload the classes and use them, which is called hot-swapping. For the best available hot-swapping of classes you'll need something like javarebel. It allows you to hot-reload a lot more types of code-changes than the regular SUN JVM. If you run your deployment in exploded-mode you're home free, and can test any code change in a second or so. We're fairly test-driven, so I only use javarebel in that short phase when I assemble the whole application, but it works really well.

有一件事是编译类,但您还需要JAVA VM来重新加载类并使用它们,这称为热交换。对于最好的热交换课程,你需要像javarebel这样的东西。它允许您热插入比常规SUN JVM更多类型的代码更改。如果您在爆炸模式下运行部署,那么您可以在家中免费使用,并且可以在一秒左右的时间内测试任何代码更改。我们是相当测试驱动的,所以当我组装整个应用程序时,我只在短暂的阶段使用javarebel,但它工作得非常好。

#2


The Java HotSpot VM does this automatically, but not in all cases...

Java HotSpot VM会自动执行此操作,但并非在所有情况下都执行此操作...

First, you must be running a "debug" session, not a "run" session.

首先,您必须运行“调试”会话,而不是“运行”会话。

Next, some changes will force a restart. The basic idea is that if the interface to the class change (the method sigs, not an actual Java interface), the VM can't replace the class contents inline.

接下来,一些更改将强制重新启动。基本思想是,如果类的接口发生更改(方法sigs,而不是实际的Java接口),则VM无法内联替换类内容。

You shouldn't need a plugin for this, just a recent-ish VM.

你不应该需要一个插件,只需要一个最新的虚拟机。

This happens under several circumstances like

这种情况发生在几种情况下

  • adding methods
  • removing methods
  • changing method signatures
  • 改变方法签名

  • changing the class hierarchy (superclasses, implemented interfaces)
  • 更改类层次结构(超类,实现的接口)

It can also happen if you introduce an error into the class. (For errors like mismatched curly braces)

如果在类中引入错误,也会发生这种情况。 (对于不匹配的花括号等错误)

When you save a Java file, eclipse compiles it. If there is an error, eclipse inserts an exception throw to indicate that there is an unresolved compilation error. (It does this so when you run you don't just see the last successful compilation, making it obvious you have a compiler error)

保存Java文件时,eclipse会编译它。如果有错误,eclipse会插入一个异常抛出,表明存在未解决的编译错误。 (它是这样做的,所以当你运行时不要只看到最后一次成功的编译,很明显你有一个编译器错误)

#3


I don't know Eclipse, but I do use Netbeans. Netbeans does this pretty well. The latest version even has an option to automatically recompile when you save a java file.

我不懂Eclipse,但我确实使用Netbeans。 Netbeans做得很好。最新版本甚至可以选择在保存java文件时自动重新编译。

I know this doesn't exactly answer your question. You can probably use both Netbeans and Eclipse depending on what part of the project you're working on.

我知道这并不能完全回答你的问题。您可以使用Netbeans和Eclipse,具体取决于您正在处理的项目的哪个部分。

EDIT: With Tomcat you can reload the web app. This is really only useful if Tomcat is looking at the new class. If your project is compiled to a build directory first and a WAR is then created from this you can go into Tomcat and install the web app and instead of pointing at a WAR point at the build directory.

编辑:使用Tomcat,您可以重新加载Web应用程序。这只有在Tomcat查看新类时才有用。如果首先将项目编译到构建目录,然后从中创建WAR,则可以进入Tomcat并安装Web应用程序,而不是指向构建目录中的WAR点。

In Tomcat you may have to put a site config file under tomcat/conf/Catalina/localhost. The contents of this file looks like this:

在Tomcat中,您可能必须在tomcat / conf / Catalina / localhost下放置一个站点配置文件。该文件的内容如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="C:/Projects/MyWebApp/build/web" path="/MyWebApp"/>

Instructions for reloading here: http://www.cs.ucl.ac.uk/teaching/java/tomcatfaq.html#changeservlet

这里重新加载的说明:http://www.cs.ucl.ac.uk/teaching/java/tomcatfaq.html#changeservlet

If you do this a few times though Tomcat will run out of memory. This is because of something called PermGenSpace. Read up about it if you want to know more. The solution is to increase the JVM memory, the PermGenSize (with -XX:MaxPermSize) and finally restarting Tomcat occasionally.

如果你这样做了几次虽然Tomcat将耗尽内存。这是因为PermGenSpace之类的东西。如果您想了解更多,请阅读相关内容。解决方案是增加JVM内存,PermGenSize(使用-XX:MaxPermSize),最后偶尔重启Tomcat。

EDIT2: If reloading the app causes you to be logged out you may be able to easily get the container to serialize your session data to disk by adding 'implements Serializable' to some of your classes. Then you should not need to login after reloading the app.

编辑2:如果重新加载应用程序导致您注销,您可以通过在某些类中添加“implements Serializable”,轻松地让容器将会话数据序列化到磁盘。然后你不需要在重新加载应用程序后登录。

#4


I agree that it is very tedious to redeploy all the time when developing.

我同意在开发时一直重新部署是非常繁琐的。

I would suggest you look into MyEclipse which has a very good hotdeploy mechanism which works well with Tomcat, and which is quite affordable and has a 30 day trial.

我建议你看一下MyEclipse,它有一个非常好的hotdeploy机制,可以很好地与Tomcat一起使用,而且价格实惠且有30天的试用期。

The stock Java EE mechanism in Eclipse for redeploying to servers is nowhere as fast.

Eclipse中用于重新部署到服务器的库存Java EE机制无处可寻。

#5


I guess I don't really see where the problem is. Here is what I do and the changes load almost instantaneously. I have an Ant script that compiles the .java and .jsp files for me, puts them in the appropriate directories under webapps and changes the web.xml file if necessary (or at least touches it to notify tomcat of the changes). If you need help on doing any of that with Ant, I'd be happy to help. Btw I do not use WAR files for deployment on my testing machine. That would be a lot slower I guess.

我想我真的不知道问题出在哪里。这就是我所做的,变化几乎瞬间加载。我有一个Ant脚本为我编译.java和.jsp文件,将它们放在webapps下的相应目录中,并在必要时更改web.xml文件(或者至少触摸它以通知tomcat更改)。如果你在使用Ant做任何帮助时需要帮助,我很乐意提供帮助。顺便说一下,我没有在我的测试机上使用WAR文件进行部署。我想这会慢得多。

#6


very easily done if you read this page: See http://blog.redfin.com/devblog/2009/09/how_to_set_up_hot_code_replacement_with_tomcat_and_eclipse.html Thank you Dan Fabulich

如果您阅读本页很容易做到:请参阅http://blog.redfin.com/devblog/2009/09/how_to_set_up_hot_code_replacement_with_tomcat_and_eclipse.html谢谢Dan Fabulich