Hi, I use class files from a bunch of jar files and they are working ok. Then I put those jars into a big jar and put it into lib directory since this dirctory will be included into classpth. However this time all the classes cann't be found any more. May I ask what I need to do to retrieve the file in those small jar files all of which, again, in a big jar? Thanks in advance, LIly
Add all your jar files into one zip i.e jar file. This should work. Dont create any folder. Whatever name you give to the new jar file, I think you need to mention it in the classpath of your application. Because it is mandatory that irrespective of whether you specify the entire lib folder as your classpath. For jar I think you need to mention it in the classpath
it has to exist in the classpath just add it to the environment variables or your common folder
posted 17 years ago
I am sorry. I could not get it done as I said. Only one way it worked out. I extracted the contents of the jar files. I had arranged all the classes properly as per the package structure. My first attempt : FAILURE =========================== Let us assume JAR1=putil.jar( phone/util/PhoneNumber) JAR2=psubs.jar( phone/subscriber/CUser) When I tried to get a jar out of both of them, named ptotal.jar and put it into the lib folder and tried to refer the PhoneNumber class and CUser classes from a simple Java program. I am geting only NoClassDefFoundError. My second attempt : SUCCESS =========================== I extracted the contents and arranged as shown below. phone | -- subscriber | | | -- CUser | -- util | -- PhoneNumber Then zipped the contents together to get one single jar. Now it worked fine. Please educate me where I am going wrong. Thanks in advance
u may uesed to the follow method,try and try. place you .jar files java/j2sdk[version code]/jre/ext u don't set the classpath java/j2sdk[version code]/jre/ext Try to compile your .java files which clude the .jar file! sorry! my english is urgly [ June 02, 2003: Message edited by: zhang feng ]
posted 17 years ago
Hi Zhang, I am sorry to say that you cannot always put the jar files into jre/ext directory. Its better to know how to set the classpath. Because while building an application for a purpose and when we create a bat file to make it run, we need to clearly set the classpath that too relative classpath and make the application run. It should be something like when the user runs the batch file, he should see beautiful beautiful applets frames demon processes should run. And its easy to track what all jars your program requires. If you start putting the jar files in the jre/ext directory, then at one point of time, the performance will drastically become slow and hence it is better to avoid. I think Lily has raised this question because she needs to have only one jar as her whole set of deployment. That is the recommended way of deploying version in companies. Not to bore you. I will just give you one example of how it is useful in one of our application. We have one serialized file in addition to the jar that we give to the client. The client application is just a hand held device. iPAQ. That will support only one jar . In the ser file we write the initial version. Whenever he loads the application, it communicates with our server and tries to know whether the jar consists of the latest version . If not we recommend the user to download the latest. As he clicks the download button, the latest jar will be downloaded and next time he starts his application he gets the latest. So many such things to speak about. Sorry If I had diverted the original question of lily.
lily: I don't think that it is (easily) possible to do what you are wanting to do. Your classpath consists of either 1). A path to a directory or 2). a path to a .jar file. You cannot include .jars inside .jars. So, you have a couple of options: 1). Have multiple .jars. If your main jar is an executable .jar file, then you need to include in the manifest: "Class-Path: myjar1.jar myjar2.jar" Note the hyphen in "Class-Path". Then entires are separated by spaces (not ; or : ), and they are relative to the directory where the executable jar resides, not the directory you are running the program from. 2). Have one jar. Extract all the contents of you other .jars and combine them to make one big jar. This is generally not recommended, as updates can be made easier with several smaller .jars (the concept of the .DLL or .SO libraries). 3). Write your own class loader to load the classes from the jar files inside the other jar files. While a (remote) possibility, this probably would create more problems than it would solve, and as such you should probably avoid it.
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
posted 17 years ago
hai,Dhamodharan thank you tell me the something,i don`t know that the performanc will drastically will drastically become slow ,then putting the jar files in the jre/ext directory. i will set a correct path