简体   繁体   中英

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

I'm trying to run a sample from Google. To be precise the Google Calendar cmdline sample (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. 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. 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

M2e plugin 1.2 (Maven integration for eclipse)

Apache Maven version 3.0.4.

UPDATE 2:

Also I noticed when I try to open pom.xml in eclipse I get an error.

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 ). You should try to recreate classpath / project with maven:

mvn eclipse:eclipse

will create .classpath / .project for you

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 )

PS: if you can afford - get you license of IDEA and forget about such issues

I imported the application in Netbeans and it worked. I still don't know what went wrong with Eclipse and didn't find a solution. For now I'm using 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 . If there are embedded change it to external, if you are already add it to eclipse.

If you haven't already added to eclipse external maven follow this steps:

Window -> Preferences -> Maven -> Installations -> Add

And add path to your external maven. Then try again :) I hope it will help you.

Try removing the default VM arguments that come pre-configured with the project.

Assuming you're running Eclipse in Windows, you can remove the arguments by going to:

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

Then click on the "Arguments" tab and remove the VM arguments.

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 ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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