Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help understanding jar file construction to utilize custom class 1

Status
Not open for further replies.

motoslide

MIS
Oct 30, 2002
764
US
Newbie alert:
I have a vendor-supplied integration utility written in Java. They supplied a couple of jar files and a sample class which uses those custom methods. I now need to create my own jar file of a modified version of their example, and use that in a "java aware" application.
How do I create my custom jar file? Specifically, is the name of the jar file important, and the directory structure therein?
Should my jar file incorporate the vendor-supplied jar files, or do I need to move all 3 of them together as needed.
To help illustrate:
The sample code is called "SigCaptureDemo.class". I created a jar file called "BarSign.jar", which contains that class file and a MANIFEST.MF file. If I add "BarSign.jar" to my classpath, what would my corresponding "import" statement be?

I'd like to see an example of creating a custom "Hello World" class which can be used by another application and pass it a variable for the second word. In other words, allow it to print "Hello Earth", or "Hello AnyVariable". I think that would provide me with the understanding to address my specific needs.

Thanks for any pointers. Sorry that was such a long question.

"Proof that there is intelligent life in Oregon. Well, Life anyway.
 
I'm not sure about how to start to answer your question. About jar files, you can pack them as you want, I don't think there's a fixed rule. A jar is like a container, a zip file intended to ease the burden of deliver a bunch of .class files, so you can do a single jar file with vendor and your classes.

Not sure if I'm helping, maybe this tutorial helps.

Cheers,
Dian
 
Thanks for the link to that tutorial. I've scanned quite a bit of it, but I still need a "push".

In one of their examples, I've created 3 small classes called Server, Client, and Utility. I've create a jar file which includes a "Main-Class:" label in the manifest file which allows the "Server" to be launched directly from a command line.

Now, I want to "include" those classes for another test project. I've added the jar file to my classpath. I've added "package myclass" at the beginning of each source file (then re-compiled and re-created the myclass.jar file). On my new project, I have this as my first line:
import myclass.*;
I get a compile-time error:
package myclass does not exit

Where am I going astray?

"Proof that there is intelligent life in Oregon. Well, Life anyway.
 
Packages and imports have nothing to do with jars.

I'd take a look at the use of packages here before going on further.

Cheers,
Dian
 
Thanks once again.
I've been beating my head and have made some progress. I have a custom class now which does what I need and I'm able to launch it from within my "java aware" application. The utility runs as a frame with just a few buttons to capture a graphic and save it to a disk file. The only part which is still failing is my inability to close down the process. The demo I downloaded had a "System.exit(0)" line, which isn't allowed because my calling application is also running in the JVM. I changed that to a "dispose()". That appears to work, but my CPU pegs at 100% and stays there until I kill the JVM. Is there a better way to discard the frame once it has accomplished my needs?



"Proof that there is intelligent life in Oregon. Well, Life anyway.
 
A call to setVisible(false) is also adviceable, and be sure there are no references to the JFrame so the garbage collection can get rid of it.

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top