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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
memingCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
isoBoyCommented:
java -jar <jarname>
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.