How to use JAR file in Application?

Hi,

I am new to Java. I am using Visual cafe Version 3.
I have downloaded an application which is
available as .jar file.

Now, I have to write a small swing based GUI where I
have lo create a button (apart from many other things)
by clicking on this button I should be able to invoke the
application I have downloaded.

Is this possible.
Please guide me in doing this.
Thanks in advace.

Regards.
LVL 2
kgreddyAsked:
Who is Participating?
 
memingConnect With a Mentor Commented:
If the jar-ed application that you have got has instructions on which class is the main class and what the command line parameters are, you should first test it on the command line.

ex: java -classpath ... MainClass argv1 argv2 ...

If everything appears to be working, try invoking the following lines in your own code:

....
String [] argvs = new String[n]
argvs[0] = argv1;
argvs[1] = argv2;
MainClass.main(argvs);
....

Never tested it. But always thought it would work.

Other options are:
1) Use some kind of classloader, i.e. the default classloader
2) Invoke a system exec call to start the application as a seperate process. This will start a new VM, and won't allow you to share variables in the memory (at least not easily).
0
 
vladi21Commented:
Java Tip 49: How to extract Java resources from JAR and zip archives
http://www.javaworld.com/javaworld/javatips/jw-javatip49.html

Java Tip 70: Create objects from jar files!
http://www.javaworld.com/javaworld/javatips/jw-javatip70.html
0
 
isoBoyCommented:
java -jar <jarname>
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
kgreddyAuthor Commented:
meming:

Yeah, I could get the information about the main class.
But not the arguments I have to pass.

I tries doing this :
Say I have my .jar file in c:\jCVSFiles\jCVS-5.1.1\application\jcvsii.jar

I have set my CLASS path in autoexec.bat and rebooted my system
to get this information.

Now, I tried java -classpath c:\jCVSFiles\jCVS-5.1.1\application\jcvsii.jar <Main Class>

I am getting the following error.
Failed reading value of registry key.




0
 
kgreddyAuthor Commented:
meming:

Yeah, I could get the information about the main class.
But not the arguments I have to pass.

I tries doing this :
Say I have my .jar file in c:\jCVSFiles\jCVS-5.1.1\application\jcvsii.jar

I have set my CLASS path in autoexec.bat and rebooted my system
to get this information.

Now, I tried java -classpath c:\jCVSFiles\jCVS-5.1.1\application\jcvsii.jar <Main Class>

I am getting the following error.
Failed reading value of registry key.




0
 
memingCommented:
In case you don't have a complete jCVS package, download it from http://www.ice.com/java/jcvs/.

First, check the requirements document of your copy of the jCVS. Install all the required software packages on you machine, including JDK/JRE 1.1 or 1.2, Swing 1.1, JAF, and JavaHelp (see c:\jCVSFiles\jCVS-5.1.1\doc\manual\misc\require.html). JDK/JRE can be found at www.javasoft.com.  You only need JRE if you won't program in Java.

The error message you have sounds like an improper Java installation to me (just the java.exe program alone can't do the trick).

Next, read through the documents carefully to find an example of how to start the program.

You don't have to modify the autoexec.bat file and reboot to have the correct classpath setup. The "-classpath" option of the java.exe program is all you need to have a very controlled environment for your program:

java -classpath c:\jCVSFiles\jCVS-5.1.1\application\jcvsii.jar;%jar_file1%;%jar_file2%;%the_rest% com.ice.jcvsii.JCVS <try no args first>
(the classpath takes jar file name, ie ..\a.jar, and class file path, ie ..\jcvsClasses)

As I understand, jCVS is a GUI application. It may not require any command line arguments.
0
All Courses

From novice to tech pro — start learning today.