3

I installed JDK 1.6 on my Linux system, the $JAVA _HOME directory is /usr/java/jdk1.6.0_07. I built the path on Eclipse to $JAVA_HOME. It runs smoothly through Eclipse and loads all third party JAR files from /usr/java/jdk1.6.0_07/jre/lib/ext/, but when I export the JAR file and run it, it throws ClassNotFoundExecption.

Why?

MikkoP
  • 4,864
  • 16
  • 58
  • 106
Achyut
  • 377
  • 1
  • 3
  • 17
  • 1
    I wouldn't use such an old version of Java as it is four years old. I would include you jar in the class path. What are you doing when you say you "export the jar file"? – Peter Lawrey Sep 19 '12 at 11:28
  • *"loads all third party JAR files from `/usr/java/jdk1.6.0_07/jre/lib/ext/`"* That is odd, given they should not be there in the first place. – Andrew Thompson Sep 19 '12 at 12:12
  • @Peter Lawrey export the jar file means when export the jar file from eclipse – Achyut Sep 21 '12 at 10:33
  • So you are generating a JAR using eclipse. This is fine, but you have to make sure what you have generated will be used but setting the classpath and/or putting it in the right directory. – Peter Lawrey Sep 21 '12 at 10:35
  • Thanks @Peter Lawrey but if I force to do that ,why it is not working?? – Achyut Sep 21 '12 at 12:06

2 Answers2

1
  1. Did you install Java properly? Here are some instruction for installing Java 7 or Java 6
  2. Are you sure that the version of Java you are using is correct one since there can be several versions of java on linux? Try java -version on terminal where you run it to check.
  3. Do you use any third party library? If so, did you specify the class path when you run the jar file or bundle them inside your jar file?
gigadot
  • 8,879
  • 7
  • 35
  • 51
  • Hi @gigadot,thanks for commenting, java -version returns --java version "1.6.0_07" Java(TM) SE Runtime Environment (build 1.6.0_07-b06) Java HotSpot(TM) Server VM (build 10.0-b23, mixed mode) . Should I require to specify the path of jars that are placed in ext ? and how I bundle the jar file and specify class path inside my jar. – Achyut Sep 21 '12 at 10:26
  • Why did you put your external jar file in ext folder? Usually, they should be in your under your project path for ease of organising. You can specify class path using -cp argument when you start your application. – gigadot Sep 21 '12 at 11:32
  • http://stackoverflow.com/questions/219585/setting-multiple-jars-in-java-classpath – gigadot Sep 21 '12 at 11:32
  • Thanks, @gigadot , ok I removed the jars from ext, but if I require to have that jars into my jar and they automatically get build when I run it, how to do that? – Achyut Sep 21 '12 at 11:56
0

What does java -version return? Are you using the same JRE for execution?

Tobias Willig
  • 1,124
  • 7
  • 16
  • Thanks, java -version returns jdk1.6.0_07 and yes I build the path JRE System Library of eclipse to /usr/java/jdk1.6.0_07 – Achyut Sep 21 '12 at 10:24