How do I list all classes in a Jar file?

How do I list all classes in a Jar file?

Its no problem if the jar file contains classes, but I have an EAR file, which contains a jar-file, and I want to list all classes in that jar-file.
I would like to do something like this:
java.util.jar.JarFile jarfile = new java.util.jar.JarFile( new File("/meYear.ear"), true );
java.util.jar.JarEntry jar = jarfile.getJarEntry( "myJar.jar" );
// Cast it to a new JarFile:
java.util.jar.JarFile newJar = (java.util.jar.JarFile)jar;
But the method getEntry returns something like jarFile$JarEntry, if I try to class cast it I get an classCastException.

Similar Messages

  • How  to include the inner classes in a jar file in netbeans ide

    Dear java friends
    how to say to netbeans ide that it has to include the
    inner classes in the jar file.
    (i have one single applet class
    with two inner classes that show up
    in the build/classes file but not in the jar).
    The applet works in the viewer but not
    in the browser (I believe because the
    xxx$yyy etc should be in the jar)
    willemjav

    First, please stop posting the same question multiple times:
    Duplicate of http://forum.java.sun.com/thread.jspa?threadID=5269782&messageID=10127496#10127496
    with an answer.
    Second, If your problem is that you can't do this in NetBeans, you need to post to somewhere that provides NetBeans support - like the NetBeans website's mailing list. These forums do not support NetBeans (or any other IDE) - they are Java language forums.

  • How to list all filename in excuteable jar file?

    Hi there,
    i've been googling around for hours, but found no good answer :(
    i want listing all file name in my excuteable jar file
    Firstly, i use
    File f = new File("/sounds");
    String[] filenames = f.list();
    and use these filenames to load some resouces from url
    //ex
    URL url = getClass().getResource("/sounds/"+filenames);
    No problem occurs when i run it normally
    but when I put it in excuteable jar file, NullPointerException appears
    i think it's because : "File f = new File("/sounds");" doesn't work in jar file (somehow, i don't know why too)
    is there any alternative way to listing all filename in this situation?
    thanks in advance

    There are jar handling classes in the standard library under java.util.jar. I think JarFile is the one you want.
    Hower it's not good practice to list jar contents in order to read resources. It's better to have some kind of resource file in the jar which lists your sounds or whatever. A simple text file with one file name per line suffices.

  • How to Invoke a main class in a jar file from my project

    Hi
    I am a new user of the Sun Java Studio enterprise. I would like to know how i can invoke a main method in a jar file associated to the project.
    regards
    Nisanth

    Could you please clarify: do you want to run your project or a project from an independent jar?
    In the first case just select Run Project from the project context menu or select a class with main method and click Run File in the class context menu.
    Regarding the second case:
    - I don't think there is such a feature in the IDE (running third party jars is not an IDE function). Could you explain why you need this?

  • Don't know how to make my main class import a jar file

    OK, the title doesn't make much sense but here are my create-jar.bat and manifest files:
    create-jar.bat:
    jar cvmf manifest.txt dassimul-admin.jar player/ admin/ com/ connector/ common/ *.class
    manifest.txt:
    Main-Class: admin.DASAdmin
    the problem is that in connector/ folder there is the jdbc mysql connector driver (.jar file).
    in Eclipse I can add this jar to the Java Build Path, so the program runs.
    When I double-click the dassimul-admin.jar file, I get a Class Not Found Exception
    C:\MYWORK\dassimul>java -jar dassimul-admin.jar
    FATAL ERROR WHILE LOADING SQL DRIVER: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    I think that the problem lies in the fact that admin.DASAdmin can't see and import the jar file in connector/ folder... am I right?

    It looks like you are putting the mysql jar file inside the dassimul jar. That won't work unless you write custom code. You should use the Class-Path attribute of the manifest to define a relative path(s) to the other jar(s) that you need to use.
    [http://java.sun.com/docs/books/tutorial/deployment/jar/index.html]

  • How to tell if a class within a jar file is being accessed?

    Hello,
    I have written a web app using NetBeans 5.5 and some external libraries.
    Rome 0.9 and a Rome module georss-rome.jar.
    Everything works fine with the integrated Netbeans tomcat 5.5...
    When I try to deploy this as a war using Tomcat 5.5 standalone It will not work properly. To make things worse, I get no error.
    In my code, I instantiate a class in the georss module by doing the following:
                    GeoRSSModule geoRssModule = GeoRSSUtils.getGeoRSS(entry);
                    if(geoRssModule != null)
    ...do something;
    }I then check for null and if not null I do stuff with methods within that jar.
    Basically I pass a rss feed or a georss feed. If its a georss feed then geoRssModule would not be null.
    As I said, this works fine within integrated tomcat but does nothing (no expected action) with standalone which leads me to believe that this is a deployment/jar/classpath issue.
    To me it seems that the class GeoRSSModule is never actually instantiated, but I never get any errors or expected output.
    I set tomcat logging.properties to FINEST for all types of logging.
    Is there a way to determine if the jar is even being accessed for that class file?
    TIA!
    BTW, I dont have the module source.
    I also verified that the jars (rome.jar and georss-rome.jar) are being deployed to webapps/myapp/WEB-INF/lib
    Message was edited by:
    gforty

    GeoRSSModule geoRssModule = GeoRSSUtils.getGeoRSS(entry);Try placing logging statements before and after this statement so that you can track execution. Make sure that your code at least gets to this particular line where you instantiate the GeoRSSModule object. Then place a logging statement afterwards to see if an object was indeed created.
    What helps me in situations like this is that I also use the NetBeans attached debugger listening on your standalone Tomcat installation. This allows you to trace your execution on the server side, one line at a time, giving you a clearer understanding of program flow.

  • How can I list all files in a subdirectory in a jar

    Hello.
    I have wrote a program which lists all class files in given directory.
    I used Class.getResource(""), and File.list().
    Now I turned the program into single jar file.
    It never works.
    I know the reason but do not know how to fix the problem.
    What can I do?
    Thank you in advance.

    If you are trying to list the files of jar file from java code you can use this code.
    Try with the below code
    =============================================
    try {
    // Open the JAR file
    JarFile jarfile = new JarFile("filename.jar");
    // Get the manifest
    Manifest manifest = jarfile.getManifest();
    // Get the manifest entries
    Map map = manifest.getEntries();
    // Enumerate each entry
    for (Iterator it=map.keySet().iterator(); it.hasNext(); ) {
    // Get entry name
    String entryName = (String)it.next();
    // Get all attributes for the entry
    Attributes attrs = (Attributes)map.get(entryName);
    // Enumerate each attribute
    for (Iterator it2=attrs.keySet().iterator(); it2.hasNext(); ) {
    // Get attribute name
    Attributes.Name attrName = (Attributes.Name)it2.next();
    // Get attribute value
    String attrValue = attrs.getValue(attrName);
    } catch (IOException e) {
    =================================================
    use import java.util.*;
    and import java.io.*;

  • How to print/list all the groups/users present in Weblogic using Java code

    Hi,
    Weblogic version : 11.1.1.5
    How to print/list all the groups/users present in Weblogic using Java code
    I want to make a remote connection to Weblogic server and print all the users/groups present in it.
    I have gone through the below mentioned site, but I cannot use the same approach since most of the API' are deprecated for example "weblogic.management.MBeanHome;"
    http://weblogic-wonders.com/weblogic/2010/11/10/list-users-and-groups-in-weblogic-using-jmx/
    Thanks in advance,
    Edited by: 984107 on 05-Feb-2013 05:26
    Edited by: 984107 on 05-Feb-2013 22:59

    see this http://www.techpaste.com/2012/06/managing-user-groups-wlst-scripts-weblogic/
    Hope this helps.

  • How can I list all the domains configured for Weblogic Servers?

    How can I list all the domains configured for Weblogic Servers?
    I saw a note, which says the following:
    "WebLogic Server does not support multi-domain interaction using either the Administration Console, the weblogic.Admin utility, or WebLogic Ant tasks. This restriction does not, however, explicitly preclude a user written Java application from accessing multiple domains simultaneously."
    In my case, I just want to list all the domains, is that possible by using any scripts?
    Thanks
    AJ

    If you use WLS Node Manager and the Config Wizard was used to create the domains, then the list of domains should be in a location like this:
    <MIDDLEWARE_HOME>\wlserver_10.3\common\nodemanager\nodemanager.domains
    Enterprise Manager Grid Control also has support for multi-domain management of WLS in a console.

  • How can I list all users who have access to a particular TABLE or VIEW

    Hi,
    Can someone tell me how I can list all users who have access to a particular TABLE or VIEW.
    Abhishek

    Hi,
    Take a look on this link: http://www.petefinnigan.com/tools.htm
    Cheers

  • How can I list all users and their DEFAULT tablespace?

    How can I list all users and their DEFAULT tablespace?
    Peter

    Peter, the following short article that lists the most heavily used Oracle rdbms dictionay views might be of interest based on your question:
    How do I find information about a database object: table, index, constraint, view, etc… in Oracle ? http://www.jlcomp.demon.co.uk/faq/object_info.html
    HTH -- Mark D Powell --

  • Java class uses another class in a Jar file (How do I make Java see it)?

    I am trying to figure out how do I make Javac see the thinlet.class in the thinlet.jar.
    I have developed an XUL xml interface and a java program that calls the interface shown below:
    //package thinlet.demo;
    import thinlet.*;
    public class UI extends Thinlet
    { public UI () throws Exception {add(parse("UI.xml"));}
    public static void main(String[] args) throws Exception
    { new FrameLauncher("UI", new UI(), 600, 600); }}
    when I do the normal compile, I get an error:
    UI.java:4: cannot find symbol
    symbol: class Thinlet
    public class UI extends Thinlet {
    ^
    UI.java:7: cannot find symbol
    symbol : method parse(java.lang.String)
    location: class thinlet.demo.UI
    add(parse("UI.xml"));
    ^
    UI.java:12: cannot find symbol
    symbol : class FrameLauncher
    location: class thinlet.demo.UI
    new FrameLauncher("UI", new UI(), 600, 600);
    ^
    3 errors
    This thinlet class should be in the thinlet.jar that I have added the directory to the path, the directory and jarfile name to the System CLASSPATH and it couldn't see it. So finally I tried putting the thinlet.jar in the same directory to no avail. I've searched the web for some time an cannot find anything that specifically speaks to compiling a program that has parent classes in a Jar.
    Any help is definitely appreciated.

    This thinlet class should be in the thinlet.jar that I have added the directory to the path, the directory and jarfile name to the System CLASSPATH and it couldn't see it. So finally I tried putting the thinlet.jar in the same directory to no avail. I've searched the web for some time an cannot find anything that specifically speaks to compiling a program that has parent classes in a Jar.
    Any help is definitely appreciated.You just still haven't provided the jar in the classpath, or you're not using the right class name. Is the class really named thinlet.Thinlet? Or are you thinking "import thinlet.*" means to import all classes in a jar named thinlet.jar? Because the latter is not true. You need to import classes, not jar file names.

  • How to get list of drives present in local file system?

    Hi all,
    I want to show all drives and their contents using JTree.
    Does anybody know how to get list of drives present in local file system?

    Thank you!
    I have new question.
    I want to disply size and file type. Can you give ur suggestion in order to do that?
    I want to provide following using JTree
    + root <Dir> 50KB
    - file1 <txt> 10KB
    - file2 <bmp> 20KB
    + root2 <Dir> 200KB
    -file1 <jpeg> 50KB
    Is this possible?
    Plz reply..........
    bye

  • How to combine the classes from 2 jar files into 1?

    Hi there
    I have got 2 jar files with the same name but the classes that they contain are different. So, I want to combine those 2 files into 1. Could anyone please tell me how to add the classes in a jar file to another jar file?
    Thanks for your help!
    From
    Edmund

    The jar utility allows you to extract files as well as put them into a jar. This is in the java docs.
    You might have to hand modify the manifest file if it was hand modified in the first place. All you should have to do is copy the text from one file to another. The manifest will have the same name so you will have to extract to different dirs so it isn't overwritten.
    Steps:
    -Create dir1 and dir2
    -Extract jar1 into dir1, Extract jar2 into dir2.
    -Manually examine manifests and combine if needed.
    -Copy files from one dir to another.
    -Use jar tool to create new jar.

  • How do you know the version of a JAR file ?

    how do you know the version of a JAR file ?
    is it what is written on MANIFEST.MF ?
    for example i have a JAR file
    whose MANIFEST.MF has this
    Manifest-Version: 1.0
    Created-By: Ant 1.4.1so, whats the version of this JAR ? 1.0 ?

    anyway, that was JSTL..jar.
    Now, come to another JAR file....
    whose MANIFEST.MF has......
    Manifest-Version: 1.0
    Created-By: Apache Ant 1.5.1
    Extension-Name: Struts Framework
    Specification-Title: Struts Framework
    Specification-Vendor: Apache Software Foundation
    Specification-Version: 1.1
    Implementation-Title: Struts Framework
    Implementation-Vendor: Apache Software Foundation
    Implementation-Vendor-Id: org.apache
    Implementation-Version: 1.1
    Class-Path:  commons-beanutils.jar commons-collections.jar commons-dig
    ester.jar commons-logging.jar commons-validator.jar jakarta-oro.jar s
    truts-legacy.jarso, How do you believe whats the version now ? do u go with the comment "Manifest-Version: 1.0" or "Specification-Version: 1.1" ?
    definitely, you would go with the "Specification-Version: 1.1" and declare this JAR as STRUTS 1.1
    hmmm, so, if nothing is mentioned like above should we follow the MANIFEST version as the JSTL version ? in my earlier example i did not find any comment on ""Specification-Version" ......so , if anybody gives me that JAR , how do i decide whether its 1.0 specification or 1.1 specifucation compliant ?
    can you tell whats the JSTL version of my earler example JAR file ?

Maybe you are looking for

  • Unable to add a special character in the rskc

    Hi I want to add the degree symbol like how it will come when we will write : 36degree [that small circle]. Please suggest how to add i am trying by coping that from a word file but failed. Regards Vismark

  • Why is the Image in Canvas Square?

    I have about a dozen video clips in my Sequence - they are all DV/DVCPRO - NTSC, 720x480. The sequence settings are 720x480 NTSC DV (3:2), Pixel Aspect Ratio NTSC - CCIR 601 - DV 720/480 and the Compressor DV/DVCPRO - NTSC. Question: Why is the image

  • Left outer join on linked server

    Hi, I am migrating large amounts of data from Oracle database to SQL Server database, through a linked server. When I use LEFT JOIN, the SQL server execution plan shows that the query that merges tables is not executed remotely (i.e. the data from bo

  • (10.8) Finder.app does not update file lists and Dropbox stops syncing, could they be related?

    The Finder on three identical, brand new, iMacs does not refresh when new files are added or removed from a folder. They were all purchased about a month before the release of Mountain Lion and were upgraded upon release. The problem is intermittent,

  • Aperture + OSX 10.5.8 not opening

    had some problems generally with my G5 Quad recently (kernel crashes etc.) but been stable for last day Every time i click on Aperture its crashing before getting anywhere - fixed permissions but no luck Any views? Process: Aperture [459] Path: /Appl