How to get .class files (and others) out of JAR in code?

Hi all,
I am packaging up several classes in a jar file. In my code I want to be able to "read" any number of jar files, and in each case pull out all the .class files to create instances of them. I don't want to unzip/unjar the files to the disk system. I basically want to create instances of the classes in the jar files in memory as if they had been loaded off the disk by themselves. Here is the sticky issue. I have a class in each jar that is "instantiated" by my plugin engine. There are other classes in the JAR file that "support" this class that is created. For instance, the class that is instantiated then has references and calls to new SomeClase() in it, and those classes are in the JAR file. So, is there some way to either "pull out" the class(es) of a JAR file without actually unjarring them to the local system and be able to create instances of them? Or, perhaps there is a way to make the classpath of the running app "see into" all the JAR files (and any sub-dirs/packages in that jar file) as if it was part of its class path? Again, these are always loaded via the Class.forName() call and newInstance(), and can not be programitcally added to the initial running application.
Thanks.

Not sure if this is what you are asking, but...
You have jars that reference each other (sounds pretty tightly coupled to me, maybe they shouldn't be in separate jars, but I digress) and each has a manifest file in META-INF, right?
To reference another jar's contents, simply add it to the Class-Path variable in your manifest. Then you can reference the classes as if they were all unjarred and slapped in the same directories.
More Info:
http://java.sun.com/docs/books/tutorial/jar/basics/manifest.html#special-purpose
Tarabyte :)

Similar Messages

  • How to run .class file and .jar file in jdev9i

    I want to run .class file and .jar file in jdev9i,what should I do?
    Also,I want to generate .class file and .jar file in jdev9i,what should i do?

    Add the .class file containing the public static void main(...) method to the project by clicking on the + toolbar button in the navigator, open the project properties and properly set the additional classpath then right click on the .class in the navigator and say run. It should work, I've just tried it.
    Doesn't work for a .jar yet, in JDeveloper 9.0.3 it works both for .class and .jar
    Michel

  • How to get .class files from a JAR at runtime

    Hi. I wrote a program that load the classes it find in the "prog/components" directory. It enables me to add new components without messing with the code of the main program. Everything worked fine when wrote a batch file - but I want to create a JAR file. In the Batch file I gave the path to those files for the class loader in a loop, and it was "prog.components/" + filename[i] (I get the file names by using a FileFilter).
    My question is - how can I obtain the files in the prog/component directory inside the JAR? WHen I left it as it was in the BATCH it didn't work because there wa no prog/component dir outsiede the JAR. What should I do?

    Thanks man, that was really helpful! I wrote some piece of code that inserts the file names I want to an ArrayList. However, I wonder how you would make the program list all the files in the "prog.jar/prog/components/" directory? I think your code would be better tahn mine since you've coped with it before. Could you write the code snippet?

  • How to put picture files and other things on my BB 8703e

    Hello! I know I got a bit of a throwback bb, but I am using it until I can upgrade to a new phone on sprint.
    So, I am barely learning about this bb, so any help or cool uploads and apps I need to add... Please let me know.
    Now I got this app, that will supposedly let me play music files. However, i cannot seem to figure out how to put any files on here when I connect my bb to my computer. When I initially connect the usb it will be like BB connection detected, but it doesn't show a folder or anything...
    Where should i be looking....
    What should I do?

    With the 8707, I believe you will need to visit a website and download the image from there, or from an email you send with the image attached.
    Music or ringtones will need to come from visiting a site with music or ringtones, from the BlackBerry browser.
    1. If any post helps you please click the below the post(s) that helped you.
    2. Please resolve your thread by marking the post "Solution?" which solved it for you!
    3. Install free BlackBerry Protect today for backups of contacts and data.
    4. Guide to Unlocking your BlackBerry & Unlock Codes
    Join our BBM Channels (Beta)
    BlackBerry Support Forums Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • How to get video file and iTunes Extra to show as one file in iTunes?

    When I purchase a movie in iTunes with iTunes Extras, after the download is finished in the "Movies" and "Genres" view they appear as one file. You click on the cover, it opens, shows the "Play iTunes Extra" button as well as a small Play arrow button next to the title to play the movie directly. Only in "List" view do they appear as separate files.
    How can I achieve that for my own iTunes extra? I tried giving the .ite the same XID as the movie file but that didn't work, they continue to appear as separate files in iTunes and the little play button when expanding the iTunes Extra doesn't work obviously. Anyone can tell me how this is done?

    Ok, I finally figured it out... there is 2 files that play a critical role in this
    first is manifest.xml
    in this file ensure that the library_item type string references the xid for your video file, and it has to be a proper xid. The iAd Producer manual explains how to create one if it does
    example:
    <library_item type="video" local_id="feature" xid="TEST:uuid:C7AE7CED-3F60-4C08-AA01-E3F9647B95CC" name="Your Movie"/>
    second file and even more critical is iTunesMetadata.plist. There is a couple of strings in there that lace the iTunes Extra to the film and vice versa
    <key>itemId</key>
    <integer>987654321</integer>
    <key>itemName</key>
    <string>Your Movie - iTunes Extras</string>
    The first is a unique 9 digit number that identifies your iTunes Extra file, the second is the name of the file that should follow the convention "Your Movie Title - iTunes Extras"
    <key>playlistId</key>
    <integer>123456789</integer>
    <key>playlistName</key>
    <string>Your Movie</string>
    This is what ties it back to the movie file, we will come back to it later where in the movie MetaData you need to place this 9 digit string
    <key>xid</key>
    <string>TEST:uuid:C7AE7CED-3F60-4C08-AA01-E3F9647B95CC_ITUNES_EXTRAS</string>
    This is the convention in how to properly xid your iTunes Extra, it is your movie's XID with "_ITUNES_EXTRAS" added to the end of it
    <key>Name File</key>
    <string>Your Movie - iTunes Extras.ite</string>
    <key>associated-adam-ids</key>
    <array>
    <integer>123456789</integer>
    The first is self explanatory but the second is again this 9 digit number that you will need to place into the meta data of your movie. It is what will make iTunes lace the two files together
    <key>xid-asset-mapping</key>
    <dict>
    <key>TEST:uuid:C7AE7CED-3F60-4C08-AA01-E3F9647B95CC</key>
    <array>
    <integer>123456789</integer>
    </array>
    <key>TEST:uuid:C7AE7CED-3F60-4C08-AA01-E3F9647B95CC_ITUNES_EXTRAS</key>
    <array>
    <integer>987654321</integer>
    </array>
    </dict>
    This is the last critical piece, it laces the two files tigthly together. Now the 9 digit number counting down from 9 is part of the unique ID of the iTunes Extra, the 9 digit number counting up from 1 needs to be put into the metadata of your movie. The annotation type for this is "contentID".
    That's pretty much it. If you did it right your files will now appear as one file in cover view just like a movie bought in the store.
    The easiest to do this right is to grab the manifest.xml and iTunesMetadata.plist from an iTunes store movie and copy paste and edit it for your purposes, which is what I did.
    Cheers everyone!

  • How to get "ShareWithMe" files with "check out" status?

    Hello All,
    I was working on try to get "ShareWithMe" documents via SharePoint 2103 Query APIS with CSOM and REST service.
    Practically it works good using the "SharedWithUsersOWSUSER"
    manage property from this way: 
    https://domain-my.sharepoint.com/_api/search/query?querytext='*'&querytemplate='SharedWithUsersOWSUser:"someone"
    But, this search query is not working for files that has been set up to "check out",  I
    mean this scenary :
    e.g
    I upload a new file to my documents. 
                    Check out the file.
                    Share this file with someone.  
    I could verify that  "SharedWithUsersOWSUser" property has a empty value  for check out files that has been shared with someone, and this it will be the reason for what the query displayed above is not working in this case. 
    an extra test that I did it was : change the file shared from "check out" to "check in" and then the query it worked as expected.  
    Is there some way to get also these files(with "check out" status) ? I can see that it works very well on OneDrive for business - "ShareWithMe" page, I mean all files that it were shared with the current user are listed there, without to
    take into account if these files it were set up to check out or not. Please, some suggestion ?

    When the file is checked out and metadata is changed while it is checked out the search crawler will not pick up the change until it is checked in. When you make changes to a file while it is checked out they are considered temporary changes until they
    are checked in.
    Blog | SharePoint Field Notes Dev Tools |
    SPFastDeploy | SPRemoteAPIExplorer

  • How to get *.class file path....

    how could find the executable file path at execution time..
    if there is one *.class file, then i will paste it to another location . next i will execute that .class file. how to find that path from execution program ....

    Try the following
    URL path = getClass().getProtectionDomain().getCodeSource().getLocation();

  • How to get class name and method name within a class method?

    Hi,
    In a java class, is it possible to get its class name and the class method?
    Please advise.
    Thank you.

    I mean whether there's any built-in command that will
    return the class name instead of code it ourself, for
    easier maintenance.
    Possible?
    this.getClass().getName();

  • HT3775 Does anyone know how to get .mts files and mpg files to work in final cut express?

    I am trying to import footage from a cannon xa10 but it wont come up in final cut express. The only files I have managed to get off the sd card are either .mts or .mpg files and these won't import into final cut. Any suggestions?

    Barney & cjnz11, are you importing AVCHD lite?
    FCE doesnt play nice with AVCHD lite with the Standard plugins, imovie on the other hand does (go figure) there is a fix for this.
    1. Open the Final Cut Express.app by right clicking the icon and choose 'show content'. At Contents/Plugins you find a folder called: "AVCHD.RADPlug". compress this and keep it safe (Just incase)
    2. Now Open the iMovie.app by right clicking the icon and choose 'show content'  At Contents/RADPlugins there is a folder called "AVCHD.RADPlug". Copy that folder to where you found the folder with the same name inside the Final Cut Express.app
    After that you will be able to Log & Transfer AVCHD Lite with in FCE instead of the imovie import and XML export method.  

  • How to get Mobile number and other information from SIM card

    Hi,
    I like to get mobile number,mobile user name and other information from SIM card using j2me program.Is there is any API for this one.
    Any one give guidelines to me how to get this.
    with regards,
    latchiya

    Please use the search! this topic has come up lots of times already.

  • How to import ofice files and others on iphone

    please help

    In what context are you having problems? In any text box, such as this, you tap the .?123 button to get to the number page, then tap it again to go back to letters. If you need more symbols, from the number page tap the #+= tab.

  • How to Zip a file and find it size using ABAP code

    Hi All,
    My requirement is to extract a file from Al11 ZIP it and find it size. 
    Please let me know whether there are any Function modules or Classes for Zipping and finding the size of it.
    Note : Used Class "cl_abap_zip" but the output at in chinese language.
    Thanks in advancve for your support.
    Regards
    Jithu

    Check https://wiki.sdn.sap.com/wiki/display/profile/GZIP
    and how to zip and unzip a file in abap
    May it useful
    Kanagaraja L

  • When I "save page as" I also get a folder with gif images, jscript script files and other similar items. how can I stop this.

    When I "save page as" via the file button at the top edge of the page, I also get a folder containing gif images, jscript script files and other similar items. I am not is allowed to delete it unless I also delete the page I need. How can I stop this from happening. is it the way I've configured firefox perhaps.
    == since I installed firefox

    Make sure that you have selected "Web Page, complete" to save the page.

  • HT1454 HELP! ITook loads of photos on my ipod touch, and when i went to look at them they were just black images , and then out of 50 bout 7 of them came out?anyone know how to get the black pictures turn out ?

    HELP! ITook loads of photos on my ipod touch, and when i went to look at them they were just black images , and then out of 50 bout 7 of them came out?anyone know how to get the black pictures turn out ?

    Try the following:
    - A reset. Nothing is lost
    Reset iPod touch: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Restore from backup

  • HT4910 Problem, I reseted my iPhone 4S and now I don't know how to get back files.

    Problem, I reseted my iPhone 4S and now I don't know how to get back files. I bought WhatsApp and some other games with money. Can I get them back? I have iCloud account.

    Not sure what it is you are asking, but you can redownload apps from the purchased section of the app store.

Maybe you are looking for