This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why Class.forName does not work when calling from jar file  RSS feed

 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all
im trying to get class from jar file,the jar file is in the class path
and when im trying to call the class "a" im getting :

im working inside eclipse. and i did add the jar file into build path / and classpath
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works to find classes inside a jar file, if the class file truly is available. All I can tell you is to check carefully and make sure the jar file is really available at runtime. The CLASSPATH environment variable will be ignored when running a program from Eclipse, as I hope you're already aware.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16026
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you run a program as an executable JAR (by double-clicking the JAR or running it with "java -jar MyProgram.jar"), then Java does not look at the CLASSPATH variable or the -cp or -classpath options on the command line. In that case, the classpath is determined by the manifest file inside the JAR file.

If the class you're trying to load is not in the classpath in the manifest file (or in the JAR file itself), then it is not going to work.

For more info: Adding Classes to the JAR File's Classpath
 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok after i did simple test and added my custom jar it worked ok
the jar im trying to work is from third party application
and the manifest file looks like this can some one tell me what is
written here that prevent me from using this jar ?
-----------------------------------------------------
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.5
Created-By: 1.4.2_12-b03 (Sun Microsystems Inc.)
Fuego-Version: 5.5 ALPHA
Main-Class: fuegoblock.fdi.Id
Class-Path: fuegocore.jar fuegofdi.jar ftlib.jar ftmami.jar ftxoruntim
e.jar

Name: FuegoBlock FDI
Fuego-Block: FuegoBlock FDI
Implementation-Vendor: FuegoBlock
Implementation-Title: FuegoBlock FDI
 
Paul Clapham
Sheriff
Posts: 22471
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing should prevent you from using that jar with the manifest like that. Assuming of course that you do what it says and put those other five jars in the same directory as it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!