I am running a multi level maven project. It has webapps packaged as WAR, which depend on components packaged as JAR files
我正在运行一个多级maven项目。它将webapps打包为WAR,它依赖于打包为JAR文件的组件
Most of the code changes that i do belong to those JAR files.
我所做的大多数代码更改都属于那些JAR文件。
To test the changes, i need to repackage the JAR and the WAR and deploy externally in tomcat.
要测试更改,我需要重新打包JAR和WAR,并在tomcat中进行外部部署。
I tried using sysdeo-tomcat-maven-eclipse plugin, but it did not work as expected.
我尝试使用sysdeo-tomcat-maven-eclipse插件,但它没有按预期工作。
Please advise if anyone has a solution for this problem
请告知是否有人有解决此问题的方法
Thanks Gaurav
4 个解决方案
#1
Using the Maven Eclipse Integration plugin
使用Maven Eclipse Integration插件
I you are experiencing problems I've found it helpful to try the command line tool mvn for debugging. As a rule of thumb, if it builds without errors command line, then you can run it in Eclipse (but tomcat has problems also, so you might need to clean work directory and clear caches every once in a while).
我遇到问题我发现尝试使用命令行工具mvn进行调试很有帮助。根据经验,如果它构建没有错误命令行,那么你可以在Eclipse中运行它(但是tomcat也有问题,所以你可能需要每隔一段时间清理工作目录并清除缓存)。
Other than that I really recommend using the Maven Eclipse Integration plugin! I use the version from Sonatypes plugin repo http://m2eclipse.sonatype.org/sites/m2e. There is a newer integration on the eclipse repo, but it works differently and I have not yet had time to investigate it's uses yet.
除此之外,我真的建议使用Maven Eclipse Integration插件!我使用Sonatypes插件repo http://m2eclipse.sonatype.org/sites/m2e的版本。 eclipse repo上有一个更新的集成,但它的工作方式不同,我还没有时间调查它的用途。
If your project is modular, it may help to setup the root project as a simple project (no Java , no Java EE). Then import the sub-projects as simple Java projects (again no Java EE). You can still activate dependency management and run the build targets through the project.
如果您的项目是模块化的,那么将根项目设置为一个简单的项目(没有Java,没有Java EE)可能会有所帮助。然后将子项目导入为简单的Java项目(同样没有Java EE)。您仍然可以激活依赖关系管理并通过项目运行构建目标。
You only need to select the submodules required by your targeted project(s) by dependencies.
您只需按依赖项选择目标项目所需的子模块。
For any project that builds war files activate facets for java ee and configure context root under further configuration available (this can only be done once, why the option is missing in the screenshot, so do it right).
对于构建war文件的任何项目,激活java ee的facets并在可用的进一步配置下配置上下文根(这只能执行一次,为什么屏幕截图中缺少该选项,所以这样做)。
Then setup deployment assembly for your facated projects. All sibling projects (active in you workspace) should be added to deployment assembly and you also need to add the build path entry for maven dependencies to the deployment assembly. Once this is set up you can use the Run on server directive to boot your web apps.
然后为您的指定项目设置部署程序集。应将所有兄弟项目(在您的工作区中处于活动状态)添加到部署程序集中,还需要将maven依赖项的构建路径条目添加到部署程序集。设置完成后,您可以使用Run on server指令启动Web应用程序。
I find it useful to always stay in pure java mode when coding maven projects. Any smart views in Eclipse only obscures what happens behind the scene, you get access to the specific editors by activating facated projects anyway!
我发现在编写maven项目时始终保持纯Java模式很有用。 Eclipse中的任何智能视图只会模糊场景背后发生的事情,无论如何都可以通过激活指定的项目来访问特定的编辑器!
#2
I use the eclipse webtools plugin, and run my Tomcat from it. It has a republish method that publishes the jars as well (if not, you just clean the directory and republish).
我使用eclipse webtools插件,并从中运行我的Tomcat。它有一个重新发布方法,也可以发布jar(如果没有,你只需清理目录并重新发布)。
In the pom file, you should have the following lines so that the webtools will be supported automatically
在pom文件中,您应该具有以下行,以便自动支持Web工具栏
<build>
...
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<wtpversion>1.5</wtpversion>
...
</configuration>
</plugin>
...
</plugins>
...
</build>
#3
Using the Maven Eclipse Integration plugin and Web Runner
使用Maven Eclipse Integration插件和Web Runner
Setup a facated project (already described in another answer), use the latest Maven Eclipse Integration plugin. This should be located at the update site of your eclipse version under collaboration. In my case Indigo - http://download.eclipse.org/releases/indigo
(/Collaboration/Maven Integration for Eclipse).
设置一个指定项目(已在另一个答案中描述),使用最新的Maven Eclipse Integration插件。这应该位于您的eclipse版本的更新站点下进行协作。在我的案例Indigo - http://download.eclipse.org/releases/indigo(/ Collaboration / Maven Integration for Eclipse)。
As an alternative to the built in server which often fails on updating workspace dependencies in the deployment assembly (for tomcat) I would recommend using Sonatype Web Application Launcher Webby which is similar to the maven directive jetty:run of the maven jetty plugin. You can find the plugin at sonatypes update site for the plugin M2e Webby - http://m2eclipse.sonatype.org/sites/m2e-webby/
. Once this plugin is installed you can Run configuration and run the web-app from an auto build located in {project}/target/m2e-webby
.
作为内置服务器的替代品,它经常无法更新部署程序集中的工作区依赖项(对于tomcat),我建议使用类似于maven指令jetty的Sonatype Web Application Launcher Webby:运行maven jetty插件。您可以在sonatypes更新站点找到插件M2e Webby的插件 - http://m2eclipse.sonatype.org/sites/m2e-webby/。安装此插件后,您可以运行配置并从位于{project} / target / m2e-webby中的自动构建运行Web应用程序。
I recommend configuring one of the (default) embedded jetty-containers as provider for the servlet-api. If specific runtimes have to be tested, an external container can easily be configured by browsing to a server home directory and selecting the appropriate provider .
我建议将其中一个(默认)嵌入式jetty容器配置为servlet-api的提供者。如果必须测试特定的运行时,可以通过浏览到服务器主目录并选择适当的提供程序来轻松配置外部容器。
The disadvantages I've encountered are quite minor:
我遇到的缺点很小:
- Web applications must be manually shut down, there is no "restart".
- Each web application has to run on a separate port, they do not share container instance.
必须手动关闭Web应用程序,没有“重启”。
每个Web应用程序都必须在单独的端口上运行,它们不共享容器实例。
#4
You get 'Unable to read TLD "META-INF/c.tld" from JAR file "file:..g/workspace/.metadata/.plugins' error with the current version of m2eclipse plugin with the above configuration.
使用上述配置获取当前版本的m2eclipse插件时,从JAR文件“file:.. g / workspace / .metadata / .plugins”错误中“无法读取TLD”META-INF / c.tld“。
You need to delete servlet-api.jar and jsp-api.jar from the deployed projects lib/ folder to fix the above error, and setup custom build configuration so that the 2 files are not copied to the deployment directory.
您需要从已部署的项目lib /文件夹中删除servlet-api.jar和jsp-api.jar以修复上述错误,并设置自定义生成配置,以便不将2个文件复制到部署目录。
#1
Using the Maven Eclipse Integration plugin
使用Maven Eclipse Integration插件
I you are experiencing problems I've found it helpful to try the command line tool mvn for debugging. As a rule of thumb, if it builds without errors command line, then you can run it in Eclipse (but tomcat has problems also, so you might need to clean work directory and clear caches every once in a while).
我遇到问题我发现尝试使用命令行工具mvn进行调试很有帮助。根据经验,如果它构建没有错误命令行,那么你可以在Eclipse中运行它(但是tomcat也有问题,所以你可能需要每隔一段时间清理工作目录并清除缓存)。
Other than that I really recommend using the Maven Eclipse Integration plugin! I use the version from Sonatypes plugin repo http://m2eclipse.sonatype.org/sites/m2e. There is a newer integration on the eclipse repo, but it works differently and I have not yet had time to investigate it's uses yet.
除此之外,我真的建议使用Maven Eclipse Integration插件!我使用Sonatypes插件repo http://m2eclipse.sonatype.org/sites/m2e的版本。 eclipse repo上有一个更新的集成,但它的工作方式不同,我还没有时间调查它的用途。
If your project is modular, it may help to setup the root project as a simple project (no Java , no Java EE). Then import the sub-projects as simple Java projects (again no Java EE). You can still activate dependency management and run the build targets through the project.
如果您的项目是模块化的,那么将根项目设置为一个简单的项目(没有Java,没有Java EE)可能会有所帮助。然后将子项目导入为简单的Java项目(同样没有Java EE)。您仍然可以激活依赖关系管理并通过项目运行构建目标。
You only need to select the submodules required by your targeted project(s) by dependencies.
您只需按依赖项选择目标项目所需的子模块。
For any project that builds war files activate facets for java ee and configure context root under further configuration available (this can only be done once, why the option is missing in the screenshot, so do it right).
对于构建war文件的任何项目,激活java ee的facets并在可用的进一步配置下配置上下文根(这只能执行一次,为什么屏幕截图中缺少该选项,所以这样做)。
Then setup deployment assembly for your facated projects. All sibling projects (active in you workspace) should be added to deployment assembly and you also need to add the build path entry for maven dependencies to the deployment assembly. Once this is set up you can use the Run on server directive to boot your web apps.
然后为您的指定项目设置部署程序集。应将所有兄弟项目(在您的工作区中处于活动状态)添加到部署程序集中,还需要将maven依赖项的构建路径条目添加到部署程序集。设置完成后,您可以使用Run on server指令启动Web应用程序。
I find it useful to always stay in pure java mode when coding maven projects. Any smart views in Eclipse only obscures what happens behind the scene, you get access to the specific editors by activating facated projects anyway!
我发现在编写maven项目时始终保持纯Java模式很有用。 Eclipse中的任何智能视图只会模糊场景背后发生的事情,无论如何都可以通过激活指定的项目来访问特定的编辑器!
#2
I use the eclipse webtools plugin, and run my Tomcat from it. It has a republish method that publishes the jars as well (if not, you just clean the directory and republish).
我使用eclipse webtools插件,并从中运行我的Tomcat。它有一个重新发布方法,也可以发布jar(如果没有,你只需清理目录并重新发布)。
In the pom file, you should have the following lines so that the webtools will be supported automatically
在pom文件中,您应该具有以下行,以便自动支持Web工具栏
<build>
...
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<wtpversion>1.5</wtpversion>
...
</configuration>
</plugin>
...
</plugins>
...
</build>
#3
Using the Maven Eclipse Integration plugin and Web Runner
使用Maven Eclipse Integration插件和Web Runner
Setup a facated project (already described in another answer), use the latest Maven Eclipse Integration plugin. This should be located at the update site of your eclipse version under collaboration. In my case Indigo - http://download.eclipse.org/releases/indigo
(/Collaboration/Maven Integration for Eclipse).
设置一个指定项目(已在另一个答案中描述),使用最新的Maven Eclipse Integration插件。这应该位于您的eclipse版本的更新站点下进行协作。在我的案例Indigo - http://download.eclipse.org/releases/indigo(/ Collaboration / Maven Integration for Eclipse)。
As an alternative to the built in server which often fails on updating workspace dependencies in the deployment assembly (for tomcat) I would recommend using Sonatype Web Application Launcher Webby which is similar to the maven directive jetty:run of the maven jetty plugin. You can find the plugin at sonatypes update site for the plugin M2e Webby - http://m2eclipse.sonatype.org/sites/m2e-webby/
. Once this plugin is installed you can Run configuration and run the web-app from an auto build located in {project}/target/m2e-webby
.
作为内置服务器的替代品,它经常无法更新部署程序集中的工作区依赖项(对于tomcat),我建议使用类似于maven指令jetty的Sonatype Web Application Launcher Webby:运行maven jetty插件。您可以在sonatypes更新站点找到插件M2e Webby的插件 - http://m2eclipse.sonatype.org/sites/m2e-webby/。安装此插件后,您可以运行配置并从位于{project} / target / m2e-webby中的自动构建运行Web应用程序。
I recommend configuring one of the (default) embedded jetty-containers as provider for the servlet-api. If specific runtimes have to be tested, an external container can easily be configured by browsing to a server home directory and selecting the appropriate provider .
我建议将其中一个(默认)嵌入式jetty容器配置为servlet-api的提供者。如果必须测试特定的运行时,可以通过浏览到服务器主目录并选择适当的提供程序来轻松配置外部容器。
The disadvantages I've encountered are quite minor:
我遇到的缺点很小:
- Web applications must be manually shut down, there is no "restart".
- Each web application has to run on a separate port, they do not share container instance.
必须手动关闭Web应用程序,没有“重启”。
每个Web应用程序都必须在单独的端口上运行,它们不共享容器实例。
#4
You get 'Unable to read TLD "META-INF/c.tld" from JAR file "file:..g/workspace/.metadata/.plugins' error with the current version of m2eclipse plugin with the above configuration.
使用上述配置获取当前版本的m2eclipse插件时,从JAR文件“file:.. g / workspace / .metadata / .plugins”错误中“无法读取TLD”META-INF / c.tld“。
You need to delete servlet-api.jar and jsp-api.jar from the deployed projects lib/ folder to fix the above error, and setup custom build configuration so that the 2 files are not copied to the deployment directory.
您需要从已部署的项目lib /文件夹中删除servlet-api.jar和jsp-api.jar以修复上述错误,并设置自定义生成配置,以便不将2个文件复制到部署目录。