Results 1 to 16 of 16
  1. #1
    lordhark is offline Member
    Join Date
    Feb 2012
    Posts
    8
    Rep Power
    0

    Default Open a jar file with button swing and load this file.jar in a desktop pane

    Hello, I want load the file.jar with pression on a button swing in my application and load this fiile.jar in a desktop Pane . I never created anything like; Could you help me? Thanks

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,271
    Rep Power
    25

    Default 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.

  3. #3
    lordhark is offline Member
    Join Date
    Feb 2012
    Posts
    8
    Rep Power
    0

    Default 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.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,271
    Rep Power
    25

    Default Re: Open a jar file with button swing and load this file.jar in a desktop pane

    I want to do is open an existing file.jar
    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.
    How does that connect to "within my JForm"?

  5. #5
    lordhark is offline Member
    Join Date
    Feb 2012
    Posts
    8
    Rep Power
    0

    Default 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.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,271
    Rep Power
    25

    Default Re: Open a jar file with button swing and load this file.jar in a desktop pane

    I would like the execution window of my jar file is opened within my project in the window of the caller
    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.

  7. #7
    lordhark is offline Member
    Join Date
    Feb 2012
    Posts
    8
    Rep Power
    0

    Default Re: Open a jar file with button swing and load this file.jar in a desktop pane

    Thanks for the help, I solved it :

    Java 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);
    But this code don't import the folder: MEFA-INF contained in a jar file. You have a solution for this problem? Thanks
    Last edited by lordhark; 02-16-2012 at 10:35 AM.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default 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).

  9. #9
    lordhark is offline Member
    Join Date
    Feb 2012
    Posts
    8
    Rep Power
    0

    Default 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?

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default 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.

  11. #11
    lordhark is offline Member
    Join Date
    Feb 2012
    Posts
    8
    Rep Power
    0

    Default 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.

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default 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.

  13. #13
    lordhark is offline Member
    Join Date
    Feb 2012
    Posts
    8
    Rep Power
    0

    Default 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.

  14. #14
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default 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.

  15. #15
    lordhark is offline Member
    Join Date
    Feb 2012
    Posts
    8
    Rep Power
    0

    Default 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.

  16. #16
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default 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

  1. How to open .ods file on button click event
    By Anagha in forum New To Java
    Replies: 15
    Last Post: 07-08-2012, 09:10 PM
  2. How to open pdf file in swing dialog?
    By asifzbaig in forum AWT / Swing
    Replies: 1
    Last Post: 10-06-2011, 03:47 PM
  3. Replies: 6
    Last Post: 03-19-2011, 03:24 AM
  4. Open an RDP file with Remote Desktop Connection
    By MisterAndy in forum New To Java
    Replies: 0
    Last Post: 12-04-2009, 08:24 PM
  5. How we can open a file with a click in button
    By kostinio in forum AWT / Swing
    Replies: 2
    Last Post: 11-01-2009, 04:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •