1

I have a spring project, it runs well in eclipse. But when i package it as a executable jar file and run it with command java -jar jar-name, it reports the following exception.

Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/c
ontext/ApplicationContext
Caused by: java.lang.ClassNotFoundException: org.springframework.context.Applica
tionContext
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: cloud.ras.alert.RASAlertApp. Program will exit.

And even if i set the class-path value with springframework path, it still doesn't work. And can anyone give me a help? Many thanks.

6
  • It is failing to load Springs jar files, are you sure that you have all your external libraries included in the build path? Commented Jul 23, 2013 at 2:32
  • do you mean that i should config the build path in manifest file? Commented Jul 23, 2013 at 2:33
  • Yes, you need to set the classpath while compiling, and also while running. Commented Jul 23, 2013 at 2:35
  • Can you elaborate on what you mean by "springframework path"? Commented Jul 23, 2013 at 2:35
  • and i use maven, the dependency has existed in the pom.xml Commented Jul 23, 2013 at 2:35

2 Answers 2

1

Right click on project -> Export -> select Runnable Jar ->click Next in wizard -> Select "Copy Required Library into a sub folder next to the generated jar and click Finish.

Since the jar is not able to find your relevant jar as runnable jar, you are facing this issue.

IMP: Make sure you are using Eclipse JUNO.I am not sure with other versions of eclipse

I was using Eclipse Ganymede and it does not has the option to select "Library Handling" option in the wizard page.

Sign up to request clarification or add additional context in comments.

1 Comment

Works for Eclispe Mars! The goal is to select 'Runnable Jar File' and not the first option 'JAR file'.
0

Why don't double check your classpath? And you could try to add the jar path to you command as below: java -cp .;jar_path_spring -jar jar-name

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.