Java,在开发过程中使用Groovy(Grails)只是为了能够测试代码而无需重新编译?

发布于 2024-10-29 14:31:15 字数 428 浏览 0 评论 0原文

我使用 Spring MVC 进行 Java Web 开发工作,基本上我被迫进行敏捷类型的开发,我必须进行很多小的更改,有时每次制作时我都会浪费大量时间进行编译改变(我在一家初创公司工作,没有足够的时间进行单元测试等,这并不理想,我不一定打算长期留在公司,但我只是在寻找方法以便更好地适应当前情况)。

我正在开发的应用程序需要速度快,并且需要进行大量大容量数据处理(它是一种搜索引擎,但不是网络搜索引擎),因此它必须为生产应用程序定期编译 Java,但我'我想知道我是否使用 Groovy 和 Grails 或类似的东西进行开发,是否可以将其编写为常规 Java,然后实时测试代码而无需重新编译。我想知道要做到这一点需要付出多少努力才能使其像编译后的 Java 一样工作。抱歉,如果这是一个新手问题,我只是不确定在哪里可以找到这方面的信息,因为有关 Grails 的大多数内容似乎更适合模拟脚本语言,而不是我想要使用它的目的。

I do Java web development work using Spring MVC and basically I'm forced to do an Agile type of development where I have to make a lot of small changes and I sometimes end up wasting a lot of time having to compile each time I make a change ( I work for a start-up company and I am not given enough time to make unit tests, etc, this isn't ideal and I don't necessarily plan to stay with the company long-term but am just looking for ways to be more adaptable for the moment).

The app I'm working on needs to be fast and it does a lot of high volume data processing (its sort of a search engine but not a web search engine) so it has to be regular compiled Java for the production app but I'm wondering if I used Groovy with Grails, or something similar, for development if I could just write it as regular Java but then test code in real-time without having to recompile. I'm wondering how much effort would be involved in doing this as far as making it work then as compiled Java. Sorry if this is a newbie question I just am not sure where to look for info on this as most things about Grails seem more geared towards emulating scripting languages not what I am trying to use it for.

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

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

发布评论

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

评论(2

勿忘初心 2024-11-05 14:31:15

敏捷是一种心态,它与编程语言或框架无关。我从来没有足够的时间不做单元测试。

如果您使用 Java 进行编码,请使用 Java 进行编码,而不是使用 Groovy。 Groovy 是(几乎)Java 的超集,因此理论上您可以在 Groovy 中编写类,然后将它们编译为 Java,但这种方法存在许多问题:

1)很容易在代码中插入一些不属于 Java 的内容 。正确的 Java,闭包非常有用:-)
2) Grails 不容易转换为 Spring MVC,因此您也必须重写这一点。

所以,我个人不会使用 Groovy/Grails。

当你说编译时,你真的是指构建战争并重新部署吗?大多数 IDE(Eclipse、Intellij 等)会在保存文件时重新编译类,因此不会有延迟。假设您使用这样的 IDE,您可以从 Eclipse 中运行您的 (Tomcat) 服务器,并且内容会自动重新部署,并且如果需要,Tomcat 会自动重新启动。

如果这仍然不够快,我推荐 JRebel,它非常好,我花了真正的钱许可证的钱。使用 JRebel 意味着您(通常)甚至不需要重新部署。您在 IDE 中更改 Java 文件,更改会发生在您的服务器中,而无需重新部署。我强烈推荐它。

我要做的另一件事是为您的代码编写单元测试。您不需要签入它们,但它们是一种可以帮助您提高工作效率的工具。

Agility is a state of mind, it doesn't have anything to do with a programming language or framework. I never have enough time NOT to do unit tests.

If you are coding in Java, code in Java, not in Groovy. Groovy is an (almost) superset of Java, so you could theoretically write your classes in Groovy and then compile them as Java, but this approach has a number of problems:

1) It's very easy to slip something in your code which isn't correct Java, closures are just SO useful :-)
2) Grails isn't easily translatable to Spring MVC, so you'd have to rewrite that bit as well.

So, I personally would not use Groovy/Grails.

When you say compile, do you really mean build the war and redeploy? Most IDEs (Eclipse, Intellij, etc) recompile a class as you save the file, so there is no delay. Assuming you're using such an IDE, you can run your (Tomcat) server from within Eclipse, and stuff gets automatically redeployed, and if necessary Tomcat restarts automatically.

If this still isn't fast enough, I recommend JRebel, which was so good that i forked out real money for a license. Using JRebel means that you (usually) don't even have to redeploy. You change a Java file in the IDE, and the change happens in your server without having to redeploy. I would highly recommend it.

One other thing I would do is to write unit tests for your code. You don't need to check them in, but they are a tool which will help your productivity.

[旋木] 2024-11-05 14:31:15

我在这里要做的是将 groovy 脚本嵌入到 java 代码中,如下所述:

http://groovy。 codehaus.org/Embedding+Groovy

通过这种方式,您可以更改 Groovy 代码,而无需重新编译。我们在上一个遗留应用程序中使用了这种技术,需要 10-15 分钟才能重新编译和安装。

Groovy 在 JVM 中运行并动态编译为字节码,因此无需担心它的“生产性”。

What I would do here would be to embed groovy scripts within the java code as described here:

http://groovy.codehaus.org/Embedding+Groovy

In this way you can change your groovy code without the need to recompile. We've used this technique in our last legacy app that took 10-15 mins to recompile and install.

Groovy runs within the JVM and is dynamically compiled to bytecode, so there's no need to worry about the "production-ness" of it.

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