• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 620
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
ben josh
Ranch Hand
Posts: 620
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
"Don't believe every tiny ad you see on the internet. But this one is rock solid." - George Washington
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic