java 如何在没有 mvn clean install 的情况下更改代码后构建项目?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12222348/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to build project after code changes without mvn clean install?
提问by Alejohuertas
I have a project in eclipse, a java app with appengine sdk and maven as my builder.
我在 eclipse 中有一个项目,一个使用 appengine sdk 和 maven 作为我的构建器的 java 应用程序。
The .class files are not refreshed until i launch clean install, so every change i do in code i have to run:
.class 文件在我启动全新安装之前不会刷新,所以我在代码中所做的每一个更改我都必须运行:
- mvn clean install
- mvn eclipse:clean
- mvn eclipse:eclipse
- mvn 全新安装
- mvn eclipse:clean
- mvn 日食:日食
and then try to launch my app.
然后尝试启动我的应用程序。
Help me please it's really annoying. Thanks
请帮帮我,这真的很烦人。谢谢
回答by Marek Dec
You are probably looking for a hot deployment feature. When working wit ha webapp, in most cases it is not enough just to compile a java class - usually you have to create a war package, and nearly always you have to redeploy the new code to the app server.
您可能正在寻找热部署功能。在使用 webapp 工作时,在大多数情况下,仅仅编译一个 java 类是不够的——通常你必须创建一个 war 包,而且几乎总是你必须将新代码重新部署到应用程序服务器。
mvn packageshould be enough to create the war. You don't need to run mvn cleanas long as you don't remove or rename any file. That would make things faster.
mvn 包应该足以引发War。只要不删除或重命名任何文件,就不需要运行mvn clean。那会让事情变得更快。
To achieve hot deployment (i.e. to get the new code instantaneously on the web-engine dev server) you need to do do some extra work, however. Make sure you use the Google Plugin for Eclipse- you can use it along with maven. The plugin at least should take care of static files hot deployment. Running the application in debug mode with Eclipse helps a bit as well as it is capable of replacing the methods' bodies on the fly.
但是,要实现热部署(即在 Web 引擎开发服务器上即时获取新代码),您需要做一些额外的工作。确保您使用Google Plugin for Eclipse- 您可以将它与 maven 一起使用。该插件至少应该处理静态文件热部署。使用 Eclipse 在调试模式下运行应用程序会有所帮助,因为它能够动态替换方法的主体。
Find further information answers to this question.
查找此问题的更多信息答案。
回答by Nick
It's unclear from the question exactly what is happening and why. To figure this out, we would need to see the pom.xml and the "tree" command output showing the relevant folders and files. Then we could compare that to what the relevant maven plugin should be doing, and work from there.
从问题中不清楚到底发生了什么以及为什么。要弄清楚这一点,我们需要查看 pom.xml 和“tree”命令输出,其中显示了相关的文件夹和文件。然后我们可以将其与相关的 maven 插件应该做的事情进行比较,并从那里开始工作。
As it stands, this is a quite old question in which it's unclear exactly what's happening, and OP has disappeared a long time ago. If this issue occurred today, the best thing to do would be to post to the App Engine Public Issue Tracker, although this could be inappropriate if the issue weren't in the App Engine SDK (or related maven plugins) but came from a third-party maven plugin not behaving properly (maven-compiler-plugin, for example). However, until a more in-depth analysis were performed, it would be difficult to know in advance.
就目前而言,这是一个相当古老的问题,目前还不清楚到底发生了什么,而且 OP 很久以前就消失了。如果这个问题今天发生,最好的办法是发布到App Engine Public Issue Tracker,尽管如果问题不在 App Engine SDK(或相关的 maven 插件)中,而是来自第三方,这可能是不合适的-party maven 插件行为不正常(例如maven-compiler-plugin)。但是,在进行更深入的分析之前,很难提前知道。
回答by Jason
I know this is a very old post but I recently came across this issue while working with STS and Websphere application server. Hope this helps anyone to come across this ancient relic of a post.
我知道这是一篇很老的帖子,但我最近在使用 STS 和 Websphere 应用程序服务器时遇到了这个问题。希望这可以帮助任何人遇到这个古老的帖子遗迹。
Have a look at the "FileSync" plugin in the Eclipse marketplace. It allows to sync your workspace files with external directories (think your application server). After you install "FileSync" you can configure it to "copy/paste" your workspace files directly to your application server's exploded .war directory. It might take a little playing around with to get your files copied in a j2ee compliant format but it worked like a charm for me. Once its configured you basically just update files, save them, and your application is ready to go!
查看 Eclipse 市场中的“FileSync”插件。它允许将您的工作区文件与外部目录(想想您的应用程序服务器)同步。安装“FileSync”后,您可以将其配置为将您的工作区文件直接“复制/粘贴”到应用程序服务器的展开的 .war 目录中。以兼容 j2ee 的格式复制文件可能需要花点时间,但它对我来说就像一个魅力。配置完成后,您基本上只需更新文件,保存它们,您的应用程序就可以使用了!
回答by Adam
Getting hot-reload of your App Engine application working is easy using only the Eclipse m2e plugin actually, and doesn't require the GPE plugin or any other special connectors:
实际上,仅使用 Eclipse m2e 插件就可以轻松地热重载 App Engine 应用程序,并且不需要 GPE 插件或任何其他特殊连接器:
1) Create your App Engine app as a Maven project in Eclipse as you would normally, using one of the provided Google archetypes or another custom archetype.
1) 像往常一样,使用提供的 Google 原型之一或其他自定义原型在 Eclipse 中将您的 App Engine 应用程序创建为 Maven 项目。
2) Configure your project, and do an initial build with mvn clean install
in the root of the project to create the initial target/<artifact>-<version>
WAR directory.
2) 配置您的项目,并mvn clean install
在项目的根目录中进行初始构建以创建初始target/<artifact>-<version>
WAR 目录。
3) Start the development server with mvn appengine:devserver
in the project root and ensure you can view your locally served app in a browser. Leave the development server running.
3)mvn appengine:devserver
在项目根目录中启动开发服务器,并确保您可以在浏览器中查看本地服务的应用程序。保持开发服务器运行。
4) In Eclipse, make sure that Project -> Build automatically
is checked.
4) 在 Eclipse 中,确保Project -> Build automatically
选中。
Now, whenever you save a .java
file Eclipse will automatically build the corresponding .class
file under target/<artifact>-<version>/WEB-INF/classes
. In a Maven project, this directory is set as the output directory for classes in your .classpath
. The development server will detect the file change and do a hot-reload of your application so that the changes will appear immediately when you refresh your app in the browser.
现在,每当您保存.java
文件时,Eclipse 都会自动.class
在target/<artifact>-<version>/WEB-INF/classes
. 在 Maven 项目中,此目录被设置为.classpath
. 开发服务器将检测文件更改并对您的应用程序进行热重新加载,以便在您在浏览器中刷新应用程序时立即显示更改。