Results 1 to 16 of 16
- 02-12-2012, 12:54 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 8
- Rep Power
- 0
- 02-12-2012, 02:56 PM #2
Re: Open a jar file with button swing and load this file.jar in a desktop pane
What do you mean by "load the file.jar"? How do you "load" a file? Read the file into a variable?
Are you trying to copy a file from a directory to the desktop?
What is a "desktop Pane"?
Are you trying to do something like this:
You have a jar file that contains some classes that you want to use in your program.
If that is the problem. put the jar file on the classpath when you execute your program and the classloader will be able to find the classes when your code tries to access them, like with a new statement.
- 02-12-2012, 03:59 PM #3
Member
- Join Date
- Feb 2012
- Posts
- 8
- Rep Power
- 0
Re: Open a jar file with button swing and load this file.jar in a desktop pane
Hello, thank you for your response.
So what I want to do is open an existing file.jar. Open the file.jar simply by acting on a button within my application.
I would almost make a sort of menu that invokes existing jar files and upload them to me within a predetermined area, hosted by the calling program. A portion of the Jform or more.
Also I would like the file.jar be opened within my JForm and to do this I thought JDesktopPane (Java 2 Platform SE v1.4.2), but if there is a better solution and you know her well being.
- 02-12-2012, 04:22 PM #4
Re: Open a jar file with button swing and load this file.jar in a desktop pane
Please explain what you mean by "open" a file? Do you want to start the execution of the class pointed to by the manifest file in the jar file? Like when you double click on the jar file.I want to do is open an existing file.jar
How does that connect to "within my JForm"?
- 02-12-2012, 10:08 PM #5
Member
- Join Date
- Feb 2012
- Posts
- 8
- Rep Power
- 0
Re: Open a jar file with button swing and load this file.jar in a desktop pane
I want to start the execution of the class pointed to by the manifest file in the jar file; Like when you double click on the jar file.
I would like the execution window of my jar file is opened within my project in the window of the caller to speak.
- 02-12-2012, 10:11 PM #6
Re: Open a jar file with button swing and load this file.jar in a desktop pane
I don't know how to do that. The class files in the jar will open a Window. That Window will expect to be an independent OS window, not something to be added to a container, like a button to a panel.I would like the execution window of my jar file is opened within my project in the window of the caller
- 02-16-2012, 10:32 AM #7
Member
- Join Date
- Feb 2012
- Posts
- 8
- Rep Power
- 0
Re: Open a jar file with button swing and load this file.jar in a desktop pane
Thanks for the help, I solved it :
But this code don't import the folder: MEFA-INF contained in a jar file. You have a solution for this problem? ThanksJava Code:File file = new File("//home//Scrivania//file//prova.jar"); URL[] urls = {file.toURI().toURL()}; ClassLoader cl = URLClassLoader.newInstance(urls); Class c = cl.loadClass("p.tabelle"); Object o = c.newInstance(); JInternalFrame pippopluto= (JInternalFrame) o; pippopluto.setVisible(true); pippopluto.setSize(300,300); desktop1.add(pippopluto);Last edited by lordhark; 02-16-2012 at 10:35 AM.
- 02-16-2012, 10:48 AM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Open a jar file with button swing and load this file.jar in a desktop pane
That code only works if the class p.tabelle is a JInternalFrame.
I suspect you haven't given us anywhere near enough information about what it is you are trying to achieve (and "stick a jar file in a window" is not the answer to that question).
- 02-16-2012, 11:22 AM #9
Member
- Join Date
- Feb 2012
- Posts
- 8
- Rep Power
- 0
Re: Open a jar file with button swing and load this file.jar in a desktop pane
Hello, my. Jar contains a program that works with all JInternalFrame to allow the opening of it within the JDesktopPane.
The problem is that the code imports the specified class from me, but it fails to refer to the information indicated inside the META-INF folder, such as non-standard libraries for database links.
In your opinion, how I should modify that code to make it even takes the information in the meta-inf folder?
- 02-16-2012, 11:40 AM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Open a jar file with button swing and load this file.jar in a desktop pane
You still haven't said what you're trying to achieve.
The overall picture.
For example, is this only supposed to open this one jar file?
If so, then simply add the file and the dependent jars to your apps classpath.
If it is supposed to open any jar file, then how do you control what gets selected? Not everything uses JInternalFrame.
If the jar file needs to contain a particular sort of application in it, then you need to define that.
All these things (and probably more) will affect the solution to this.
- 02-16-2012, 11:52 AM #11
Member
- Join Date
- Feb 2012
- Posts
- 8
- Rep Power
- 0
Re: Open a jar file with button swing and load this file.jar in a desktop pane
Then, I create a program that can "call" in a jar JDesktoPane one or more JAR of imprecise nature. I must make some sort of PLUGIN that are loaded dynamically depending on the login by the user.
For example:
It logs the user ANTONIO, the software will load the following jars: 1.jar, 2.jar
It logs the user MARIO, the software will load the following jars: 5.jar, 6.jar
The only thing common between the various jar is the name of the class that launches the program contained in the Jar.
For example, this class is called "PIPPO". Now when I go to use the above code, the class "PIPPO" is invoked and inside of me I see a jdesktoppane JInternalFrame, the point is that the GUI only appears but for example if the jar was connected to a database to add information to a database, I get an error classhpath, because the calling program did not import the data in the META-INF folder of jar files.
I hope I have been clear enough in explaining what I get. If you have other questions ask me. Thanks for your help and patience.
- 02-16-2012, 12:30 PM #12
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Open a jar file with button swing and load this file.jar in a desktop pane
OK.
The ClassLoader will only load the classes in the jars that it references.
In order to handle the other, dependent, jars referenced in the MANIFEST you will have to actuall read the MANIFEST yourself.
This shouldn't be too difficult, especially since there is a JarFile class.
Here's the API for it.
That will give you access to the Manifest.
From that you should be able to get at the dependencies and then load them as well.
- 02-16-2012, 02:12 PM #13
Member
- Join Date
- Feb 2012
- Posts
- 8
- Rep Power
- 0
Re: Open a jar file with button swing and load this file.jar in a desktop pane
Great, I've only seen in the class JarFile getManifest method (), now the problem is that I would need a setManifest ();
Basically I've seen these 2 classes, just that I'm not sure how to proceed. I loaded my interest class (with docide above) now I need to say that this class has a java classpath other than the calling application. Do not you have some small pieces of code that allows me to understand how to bind to a different classpath a jar because it is invoked at runtime?
Thanks for all the time you're devoting to my problem. And thanks for the solutions.
- 02-16-2012, 02:33 PM #14
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Open a jar file with button swing and load this file.jar in a desktop pane
Eh?
Why do you need to set the manifest?
I thought you were trying to load the jar file to run some class(es) within it?
You won't be able to change any classpaths, those are set at startup.
You'll have to get the ClassLoader to load up the jars referenced in the Manifest, prior to running any methods in the class you;re interested in.
- 02-16-2012, 03:24 PM #15
Member
- Join Date
- Feb 2012
- Posts
- 8
- Rep Power
- 0
Re: Open a jar file with button swing and load this file.jar in a desktop pane
So, if the amount of data in the meta-inf folder in the jar as I run the dependencies in my class? I must be able to load the jar in the manifest content of belief, correct? Maybe I'm getting out some steps.
Last edited by lordhark; 02-16-2012 at 03:33 PM.
- 02-16-2012, 03:43 PM #16
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Open a jar file with button swing and load this file.jar in a desktop pane
Assuming the manifest lists the jars needed by the classes inside it (which it will do if it is an executable jar) then you should have all the information you need to load them up in the same way as you loaded the jar file that contained the manifest.
Similar Threads
-
How to open .ods file on button click event
By Anagha in forum New To JavaReplies: 15Last Post: 07-08-2012, 09:10 PM -
How to open pdf file in swing dialog?
By asifzbaig in forum AWT / SwingReplies: 1Last Post: 10-06-2011, 03:47 PM -
Can we open .ods file on button click event..............
By Anagha in forum AWT / SwingReplies: 6Last Post: 03-19-2011, 03:24 AM -
Open an RDP file with Remote Desktop Connection
By MisterAndy in forum New To JavaReplies: 0Last Post: 12-04-2009, 08:24 PM -
How we can open a file with a click in button
By kostinio in forum AWT / SwingReplies: 2Last Post: 11-01-2009, 04:46 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks