简体   繁体   English

无法从Eclipse运行带有Maven的Java应用程序,但它可以在命令行中运行

[英]Can't run Java Application with Maven from Eclipse but it works in Command line

I'm trying to run a sample from Google. 我正在尝试从Google运行一个示例。 To be precise the Google Calendar cmdline sample (http://samples.google-api-java-client.googlecode.com/hg/calendar-cmdline-sample/instructions.html) 准确地说是Google Calendar cmdline示例(http://samples.google-api-java-client.googlecode.com/hg/calendar-cmdline-sample/instructions.html)

I cloned the code, I've build and comiled the code in command line and it ran succesfully. 我克隆了代码,我在命令行中构建并编译代码,并且它成功运行。

But now I imported the project into eclipse and it won't run. 但现在我将项目导入eclipse,它将无法运行。 I always get the error: 我总是得到错误:

    Error: Could not find or load main class Libs\Google

I tried googleing the error but did not find a simular situation. 我试着谷歌错误但没有找到类似的情况。 Anyone that can help me on the way to a solution, because I can't make heads or tails out of it. 任何可以帮助我找到解决方案的人,因为我无法做出正面或反面。

I assume it's not a fault in the code, it's code from google and it worked when I compiled in command line. 我认为它不是代码中的错,它是来自谷歌的代码,当我在命令行编译时它起作用。 So it must be something from eclipse. 所以它必须是来自日食的东西。 I did an import of existing maven project. 我做了一个现有的maven项目的导入。 It didn't gave errors or anything and then I tried to run with the above error as result. 它没有给出错误或任何东西然后我试图运行上面的错误作为结果。

Thx! 谢谢! (if more info is needed please ask in comments and I will provide) (如果需要更多信息,请在评论中提问,我会提供)

UPDATE: 更新:

I have installed 我安装了

Eclipse Juno version Version: 4.2.1 Eclipse Juno版本版本:4.2.1

M2e plugin 1.2 (Maven integration for eclipse) M2e插件1.2(用于eclipse的Maven集成)

Apache Maven version 3.0.4. Apache Maven 3.0.4版。

UPDATE 2: 更新2:

Also I noticed when I try to open pom.xml in eclipse I get an error. 另外我注意到当我尝试在eclipse中打开pom.xml时出现错误。

An error has occurred. See error log for more details.
java.lang.NullPointerException

No further details 没有进一步细节

You will have to check your classpath configuration. 您必须检查类路径配置。 Mere importing your source tree into eclipse does not work ( eclipse is shitty when it comes to understand maven files ). 仅仅将源代码树导入eclipse不起作用(当理解maven文件时,eclipse很糟糕)。 You should try to recreate classpath / project with maven: 您应该尝试使用maven重新创建类路径/项目:

mvn eclipse:eclipse

will create .classpath / .project for you 将为您创建.classpath / .project

Also keep in mind, that eclipse is constrained to only one classpath scope where maven uses 4 different ( so your test classes wil leakinto your project ) 还要记住,eclipse仅限于一个类路径范围,其中maven使用4个不同的(因此您的测试类将泄漏到您的项目中)

PS: if you can afford - get you license of IDEA and forget about such issues PS:如果你能负担得起 - 获得IDEA许可并忘记这些问题

I imported the application in Netbeans and it worked. 我在Netbeans中导入了应用程序,但它确实有效。 I still don't know what went wrong with Eclipse and didn't find a solution. 我仍然不知道Eclipse出了什么问题,但没有找到解决方案。 For now I'm using Netbeans. 现在我正在使用Netbeans。

If I find a solution I will post it here for future reference. 如果我找到解决方案,我会在此发布以供将来参考。

If you are running from Eclipse like Run configuration check on the botton view (Maven build in tree) what maven do you use in your build: it can be embedded or external . 如果您从Eclipse运行,如运行配置,请检查botton视图(Maven build in tree)您在构建中使用的maven:它可以是嵌入式的还是外部的 If there are embedded change it to external, if you are already add it to eclipse. 如果已将嵌入式更改为外部,如果已将其添加到eclipse中。

If you haven't already added to eclipse external maven follow this steps: 如果您还没有添加到eclipse外部maven,请按照以下步骤操作:

Window -> Preferences -> Maven -> Installations -> Add 窗口 - >首选项 - > Maven - >安装 - >添加

And add path to your external maven. 并添加外部maven的路径。 Then try again :) I hope it will help you. 然后再试一次:)我希望它能帮到你。

Try removing the default VM arguments that come pre-configured with the project. 尝试删除预先配置项目的默认VM参数。

Assuming you're running Eclipse in Windows, you can remove the arguments by going to: 假设您在Windows中运行Eclipse,可以通过以下方式删除参数:

Run > Run Configurations... > Java Application > CalendarSample

Then click on the "Arguments" tab and remove the VM arguments. 然后单击“Arguments”选项卡并删除VM参数。

Hit "Apply", then "Run" and you should see the sample program run (assuming you've followed ALL of the steps @ http://samples.google-api-java-client.googlecode.com/hg/calendar-cmdline-sample/instructions.html ). 点击“Apply”,然后点击“Run”,您应该看到示例程序运行(假设您已经按照所有步骤进行了操作@sttp: //samples.google-api-java-client.googlecode.com/hg/calendar- cmdline-sample / instructions.html )。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM