Solved

classpath problems?

Posted on 2006-06-13
5
608 Views
Last Modified: 2010-08-05
OK, i have 2 jars, call them A.jar and B.jar

A.jar's purpose is to synchronize B.jar with some version of B.jar on the network in a specified location. If A.jar discovers that B.jar is out of synch with this other version, it replaces B.jar with the one on the network. Also, if B.jar is not present in the current directory it replaces it with B.jar from the network spot.  Both A.jar and B.jar live in the same directory.

Now, i exectute like this: java -classpath A.jar;B.jar someClass someparameter

However, I've found that when I do it this way, if B.jar is NOT originally in that directory when I launch Java it cannot find any classes in B.jar even if I copy it to the directory before I try to execute them.

Does that makes sense? let me clarify:

I start with A.jar ONLY in the directory. A.jar's job is to check for B.jar and when it does not find B.jar, it copies B.jar from a place on the network. It then needs to launch a class from B.jar in a thread and exit.

However, when either B.jar is not originally in the directory OR if B.jar is replaced by A.jar, the JVM throws a ClassDefNotFoundException for the class I'm trying to execute. If B.jar is not touched (its there AND its up to date), the launch works fine.

Any ideas? Thanks!
0
Comment
Question by:pedron
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16896875
>>Does that makes sense?

Dependent jars need to be named in a jar's Class-Path entry in its manifest. If you use WebStart the process you're trying to achieve should happen transparently:

http://java.sun.com/j2se/1.5.0/docs/guide/javaws/developersguide/faq.html#204
0
 

Author Comment

by:pedron
ID: 16896958
Ok, I added the B.jar to A.jar's Class-Path entry in its Manifest file, but i got the same error. NoClassDefFoundException whenever I start out with NO B.jar in the directory.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 125 total points
ID: 16896989
It need to be there or you need to load it dynamically. See

http://javaalmanac.com/egs/java.lang/LoadClass.html
0
 

Author Comment

by:pedron
ID: 16897086
THANKS! i have been sweating this hardcore lately. It works like a charm!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16897089
:-)
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question