Solved

How to set up  classpath dynamically inside java class ??

Posted on 2002-06-14
8
431 Views
Last Modified: 2013-11-23
Hi
I want to set up classpath inside java class dynamically. I have tried to use System.setProperty("java.class.path", "my class path string ") to set classpath dynamically. But it is not working. How to set it dynamically from java class ?? Thanks , gary
0
Comment
Question by:garyshi
  • 4
  • 3
8 Comments
 
LVL 1

Expert Comment

by:nixj14
Comment Utility
You're in the same situation as I am in, so you may want to refer to the question that I will be asking.  To what I've researched and found from associates, you can not redefine a classpath once a VM has been instantiated.  You can however, define classes (or load classes) while the vm is loaded.  Look at the Classloader and System objects.


0
 
LVL 9

Expert Comment

by:Venci75
Comment Utility
have you tried:
String cp = System.getProperty("java.class.path");
cp += ";new_jar.jar";
System.setProperty("java.class.path", cp);
0
 

Author Comment

by:garyshi
Comment Utility
Hi nixj14,
Could you tell me main steps I should do for set classpath or load class ?? or If you have example code or few lines inportant codes for this problem, could you send them to me ?? Thanks so much.  I have to handle this problem as soon as possible. Otherwise I am worry ....

Venci75
I have tried the way you mention. It is not working.
Thanks all for you guy

Best Regards
Gary
gary2shi@yahoo.com
0
 
LVL 1

Expert Comment

by:nixj14
Comment Utility
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:garyshi
Comment Utility
Hi nixj14,
Thanks for giving me a link. But I can not open this link.  I guess it need a hotmail login first or it will check hotmail user, then go to some page. Could you copy them to me ?  Your hlep will be appreciated very much. Gary
0
 
LVL 1

Accepted Solution

by:
nixj14 earned 100 total points
Comment Utility
0
 

Author Comment

by:garyshi
Comment Utility
Hi nixj14,
Thanks for your help. I have run your example and it works fine.
Now I can load another class and run it from this classloader/example. But when I run one java class, it need some other java classes, like help.jar, util.jar. I have to put these jar files into classpath . There is no way to add these jar files into class path dynamically or use classloader to add these jar files into classpath ??  Again thanks for your help.
Gary
0
 
LVL 1

Expert Comment

by:nixj14
Comment Utility
Yeah, I'm running through a similar problem.  I was able to download some good source to add jars into your classpath.

Try this

http://gcc.gnu.org/ml/java/2000-10/msg00002.html
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
bunnyEars2 challenge 6 66
Updating Java 9 86
countHi2 challenge 7 43
json example 39 110
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now