简体   繁体   English

如何将maven托管依赖项复制到war \ web-inf \ lib中,以便在Eclipse中以调试模式运行我的GWT 2.0应用程序?

[英]How do I get maven managed dependencies copied into war\web-inf\lib so I can run my GWT 2.0 app in debug mode within Eclipse?

I am updating an existing project from GWT 1.5.2 to GWT 2.0.0. 我正在将现有项目从GWT 1.5.2更新为GWT 2.0.0。 We use maven 2 to manage our dependencies and do all of our development in Eclipse 3.5. 我们使用maven 2来管理我们的依赖项,并在Eclipse 3.5中完成所有开发。

Because we use maven to manage our dependencies, I do not have all of those jars in the war\\web-inf\\lib directory as GWT specifies. 因为我们使用maven来管理我们的依赖项,所以我没有像warT指定的那样在war \\ web-inf \\ lib目录中拥有所有这些jar。 Instead, they are in the maven repository, just where maven likes them. 相反,它们位于maven存储库中,就像maven喜欢它们一样。 I have the project set up so that maven can successfully build and launch in either dev or web mode and the application runs correctly. 我已经设置了项目,以便maven可以在开发或Web模式下成功构建和启动,并且应用程序可以正常运行。

The problem is that when I launch from Eclipse, I get a java.lang.NoClassDefFoundError. 问题是当我从Eclipse启动时,我得到一个java.lang.NoClassDefFoundError。 If I manually copy of my dependencies into war\\web-inf\\lib before launching, everything runs fine, but that doesn't lend itself to a long-term solution. 如果我在启动之前手动将我的依赖项复制到war \\ web-inf \\ lib中,一切运行正常,但这并不适合长期解决方案。 First, if I check all of those jars into our version control, that will subvert much of the value we get from maven. 首先,如果我将所有这些jar检查到我们的版本控制中,那将破坏我们从maven获得的大部分值。 As annoying as maven can be, ditching it is not the answer. 像maven一样恼人,抛弃它不是答案。 Second, having developers manually copy them over every time they want to debug something is ridiculous. 其次,让开发人员在每次调试时手动复制它们都是荒谬的。

So can I get Eclipse to copy the dependencies into war\\web-inf\\lib before launching? 那么我可以让Eclipse在启动之前将依赖项复制到war \\ web-inf \\ lib中吗? Is there an alternate solution that I'm missing? 有没有我想念的替代解决方案?

Thanks, 谢谢,

Tony 托尼

Running the gwt:eclipse goal will copy the maven dependencies into war/WEB-INF/lib . 运行gwt:eclipse目标会将maven依赖项复制到war/WEB-INF/lib See the Eclipse Configuration section of the Eclipse IDE Integration documentation of the Maven GWT plugin for more details. 有关更多详细信息,请参阅Maven GWT插件Eclipse IDE Integration文档的Eclipse Configuration部分。 Also have a look at this answer about Maven GWT 2.0 and Eclipse . 另请参阅有关Maven GWT 2.0和Eclipse的 答案

You should install the m2eclipse plugin and use that to build your project within eclipse. 您应该安装m2eclipse插件并使用它在eclipse中构建项目。 This will invoke maven as an external tool from within eclipse. 这将从eclipse中调用maven作为外部工具。

Your maven project artifact type should be set to war, which will let maven discover the dependencies and bundle them. 您的maven项目工件类型应该设置为war,这将让maven发现依赖项并将它们捆绑在一起。

See these links: 看到这些链接:

force Maven2 to copy dependencies into target/lib 强制Maven2将依赖项复制到target / lib中

http://maven.apache.org/plugins/maven-war-plugin/ http://maven.apache.org/plugins/maven-war-plugin/

http://maven.apache.org/plugins/maven-war-plugin/examples/rapid-testing-jetty6-plugin.html http://maven.apache.org/plugins/maven-war-plugin/examples/rapid-testing-jetty6-plugin.html

a maven aware IDE (idea, eclipse, netbeans) should do this packaging automatically. 一个maven感知的IDE(想法,eclipse,netbeans)应该自动进行这种打包。 maybe you: 可能是你:

  • forgot to enable maven import inside IDE? 忘了在IDE中启用maven导入?
  • did not add these dependencies to the pom.xml (so they aren't included in the 'mvn package' phase) 没有将这些依赖项添加到pom.xml(因此它们不包含在'mvn包'阶段)
  • added wrong scope to dependency declaration (eg scope 'provided' or 'tested'), so they are ignored for runtime 为依赖声明添加了错误的范围(例如,范围'提供'或'测试'),因此它们在运行时被忽略

If you have the packaging method in your pom.xml set to war it should copy runtime depdencies into target/war/WEB-INF/lib. 如果你的pom.xml中的打包方法设置为war,它应该将运行时depres复制到target / war / WEB-INF / lib中。

Or is your project to build something larger like an ear? 或者你的项目是建造像耳朵更大的东西? If so you should probably split your pom.xml into multi-project format. 如果是这样,您应该将pom.xml拆分为多项目格式。

As for Eclipse, I'm not terribly familiar with it so I can't really help you there. 至于Eclipse,我对它并不十分熟悉,所以我无法真正帮助你。 Are you (or can you) run a maven target (like "install") when you do a run or debug? 当你进行运行或调试时,你(或者你可以)运行maven目标(比如“安装”)吗?

This is not supposed to be a problem. 这不应该是一个问题。 If you are using Eclipse+WTP then WTP lets you declare jars listed under 'J2EE module dependency' in the project's properties. 如果您使用的是Eclipse + WTP,那么WTP允许您在项目的属性中声明“J2EE模块依赖项”下列出的jar。 Those jars are automatically published to tomcat (see note at the end of this comment) You need to declare an M2_REPO variable in your eclipse environment (search eclipse help for 'classpath variables'), it should point to your local maven repository, and just add external jars from there to your project and mark them as 'J2EE dependencies'. 这些jar会自动发布到tomcat(请参阅本评论末尾的注释)您需要在eclipse环境中声明一个M2_REPO变量(搜索eclipse帮助以获取'classpath变量'),它应该指向您的本地maven存储库,并且只是将外部jar从那里添加到项目中并将其标记为“J2EE依赖项”。 I did that with tons of projects, Maven and Eclipse live side-by-side :) (without m2eclipse) 我做了很多项目,Maven和Eclipse并排:)(没有m2eclipse)

A second option is to try to integrate Eclipse and Maven with m2eclipse plugin, as crowne mentioned, but I found this unnecessary. 第二种选择是尝试将Eclipse和Maven与m2eclipse插件集成,如提到的那样,但我发现这是不必要的。

There is a third option, if you don't use WTP (but you should). 如果您不使用WTP,则有第三种选择(但您应该)。 Assuming that you use tomcat, then you can copy those jars to $(tomcat.home)/common/lib. 假设您使用tomcat,那么您可以将这些jar复制到$(tomcat.home)/ common / lib。 If you can do it just for your private instance of tomcat (on each developer's machine) then you are good to go. 如果你只能为你的tomcat私有实例(在每个开发人员的机器上)做到这一点,那么你很高兴。 This is supposed to be a low-impact solution that will get those jars into the classpath at runtime, but it doesn't scale well. 这应该是一个影响较小的解决方案,它将在运行时将这些jar放入类路径中,但它不能很好地扩展。

note: unfortunately the classpath of Eclipse web projects can be confusing. 注意:遗憾的是,Eclipse Web项目的类路径可能会令人困惑。 When you add jars to the regular build path of the project, they are not deployed (copied over) to tomcat. 将jar添加到项目的常规构建路径时,它们不会部署(复制)到tomcat。 To solve this, WTP defines a special library called Webapp Library - this library contains all the jars in the project's WEB-INF/lib folder, as well as all the external jars that are marked as J2EE Module Dependencies. 为了解决这个问题,WTP定义了一个名为Webapp Library的特殊库 - 该库包含项目WEB-INF / lib文件夹中的所有jar,以及标记为J2EE Module Dependencies的所有外部jar。 All those jars find their way appropriately to WEB-INF/lib when published to tomcat. 当发布到tomcat时,所有这些jar都适当地找到了WEB-INF / lib的方式。

Quite simple: 1. Create a "lib" folder under your project like this: "\\src\\main\\webapp\\WEB-INF\\lib" 2. Copy needed "jars" etc that you want included inside your WAR bundle folder. 非常简单:1。在您的项目下创建一个“lib”文件夹,如下所示:“\\ src \\ main \\ webapp \\ WEB-INF \\ lib”2。复制您希望包含在WAR包文件夹中的所需“jars”等。 3. Invoke your maven build as you normally do. 3.像往常一样调用maven构建。 I use "mvn install", which creates builds the war file. 我使用“mvn install”,它创建了war文件。

If you examine the WAR file, your jars that you included in step-1 and step-2 will be there. 如果您检查WAR文件,那么您在步骤1和步骤2中包含的罐子就在那里。

Cheers. 干杯。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Maven依赖项不会复制到eclipse中的WEB-INF / lib - Maven dependencies are not copied to WEB-INF/lib in eclipse Maven,GWT,Google Eclipse插件,在依赖项项目处于战争状态时无法将jar复制到WEB-INF / lib - Maven, GWT, Google Eclipse plugin, can not copy jar to WEB-INF/lib when dependency project is war 如何在我的构建中将导入的jar文件添加到eclipse中的web-inf / lib? - How can I add imported jar files to web-inf/lib in eclipse for my build? GWT / GPE / App Engine:如何(智能地)找到丢失的.jar,并将其复制到/ WEB-INF / lib? - GWT/GPE/App Engine: How to (intelligently) find missing .jars and have them copied to /WEB-INF/lib? 如何让Eclipse自动将我放在WEB-INF / lib文件夹中的jar包含到我的项目中? - How do I make Eclipse automatically include jars I place in my WEB-INF/lib folder into my project? Maven 依赖项在 WEB-INF/lib 中不可见 - Maven dependencies not visible in WEB-INF/lib 如何将 JAR 文件添加到 Eclipse 中的 web-inf/lib 文件夹? - How can I add JAR files to the web-inf/lib folder in Eclipse? 如何让 Weblogic 10 更喜欢 myApp.war:/WEB-INF/lib/ 中的 jars 而不抛出 VerifyErrors? - How do I make Weblogic 10 prefer the jars in myApp.war:/WEB-INF/lib/ without throwing VerifyErrors? Maven:将 war/web-inf/classes 中的类作为 jar 添加到 war/web-inf/lib - Maven: Adding classes from war/web-inf/classes as a jar to war/web-inf/lib Maven War插件:指定正则表达式以排除web-inf / lib中的库 - Maven War Plugin : Specify Regular Expression to exclude libraries within web-inf/lib
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM