Writing a class to provide Self ID capability in a JAR file.

Hello,
I need to write a class which reads and prints out the contents of the manifest file of the JAR file of which it is a part. I've got the code for reading the manifest file, which I've included below.
My question is this: how can I get this class to find out the name of the JAR file it's in so I don't have to hard code "myJar.jar" as I have below?
Thanks.
import java.util.*;
import java.util.jar.*;
import java.io.*;
public class SelfID {
public static void main(String[] args) throws IOException {
     System.out.println("The manifest for this jar file:");
     //Create JarFile reference
     JarFile jarFile = new JarFile("myJar.jar"); //I don't want Jar File name hard coded
     //Create Manifest reference
     Manifest manifest = jarFile.getManifest();
     System.out.println(manifest.toString());
     //Create Map of manifest key/value entries
     Map entryMap = null;
     entryMap = manifest.getMainAttributes();
     //Display contents of manifest file
     Iterator it = entryMap.keySet().iterator();
while( it.hasNext() ) {
Attributes.Name key = (Attributes.Name)it.next();
String value = (String)entryMap.get(key);
System.out.println(key.toString() + " = " + value);
}

In case anyone is wondering what self ID information in the manifest I am talking about--the custom ID information I am going to put there. I don't want to have to go back and modify the source code any time the name of the JAR file must change, which could one day become a requirement.

Similar Messages

  • Custom Security Provider impossible to remove the MBean Jar File

    Hi,
    I am currently developping a custom security provider for Weblogic. I
    have deploy my Mbean File Jar on a remote server weblogic running on
    solaris. NO authentication provider for this security provider has
    been defined in the console, it means there is no link with this
    security provider. Nevertheless, when I remove the MJF the server
    crashes when starting:
    <...>
    <May 21, 2003 3:37:08 PM CEST> <Critical> <WebLogicServer> <000364>
    <Server failed during initialization.
    Exception:weblogic.management.configuration.ConfigurationException: -
    with nested exception:
    [javax.management.MBeanException: Commo type:
    be.fgov.minfin.ccff.security.provider.CCFFSimpleSampleAuthenticator is
    not loaded. Checks MJFs.]
    javax.management.MBeanException: Commo type:
    be.fgov.minfin.ccff.security.provider.CCFFSimpleSampleAuthenticator is
    not loaded. Checks MJFs.
    at weblogic.management.commo.CommoModelMBean.load(CommoModelMBean.java:588)
    at weblogic.management.commo.Commo.initInstances(Commo.java:241)
    at weblogic.management.commo.Commo.init(Commo.java:125)
    at weblogic.management.AdminServerAdmin.initializeCommo(AdminServerAdmin.java:477)
    at weblogic.management.AdminServerAdmin.initialize(AdminServerAdmin.java:108)
    at weblogic.t3.srvr.T3Srvr.initialize1(T3Srvr.java:659)
    at weblogic.t3.srvr.T3Srvr.initialize(T3Srvr.java:589)
    at weblogic.t3.srvr.T3Srvr.run(T3Srvr.java:277)
    at weblogic.Server.main(Server.java:32)
    <...>
    I have been looking through all the config file where the MJF
    (removed) could be linked but I did not find anything.
    I am really confused because with my local weblogic running on
    win2000, there is no problem to remove this MJF.
    Thx in advance,
    tiggy

    Tiggy,
    Remove the userConfig directory under your domain directory. That should
    fix the problem.
    Thanks,
    ~satya
    Tiggy wrote:
    Hi,
    I am currently developping a custom security provider for Weblogic. I
    have deploy my Mbean File Jar on a remote server weblogic running on
    solaris. NO authentication provider for this security provider has
    been defined in the console, it means there is no link with this
    security provider. Nevertheless, when I remove the MJF the server
    crashes when starting:
    <...>
    <May 21, 2003 3:37:08 PM CEST> <Critical> <WebLogicServer> <000364>
    <Server failed during initialization.
    Exception:weblogic.management.configuration.ConfigurationException: -
    with nested exception:
    [javax.management.MBeanException: Commo type:
    be.fgov.minfin.ccff.security.provider.CCFFSimpleSampleAuthenticator is
    not loaded. Checks MJFs.]
    javax.management.MBeanException: Commo type:
    be.fgov.minfin.ccff.security.provider.CCFFSimpleSampleAuthenticator is
    not loaded. Checks MJFs.
    at weblogic.management.commo.CommoModelMBean.load(CommoModelMBean.java:588)
    at weblogic.management.commo.Commo.initInstances(Commo.java:241)
    at weblogic.management.commo.Commo.init(Commo.java:125)
    at weblogic.management.AdminServerAdmin.initializeCommo(AdminServerAdmin.java:477)
    at weblogic.management.AdminServerAdmin.initialize(AdminServerAdmin.java:108)
    at weblogic.t3.srvr.T3Srvr.initialize1(T3Srvr.java:659)
    at weblogic.t3.srvr.T3Srvr.initialize(T3Srvr.java:589)
    at weblogic.t3.srvr.T3Srvr.run(T3Srvr.java:277)
    at weblogic.Server.main(Server.java:32)
    <...>
    I have been looking through all the config file where the MJF
    (removed) could be linked but I did not find anything.
    I am really confused because with my local weblogic running on
    win2000, there is no problem to remove this MJF.
    Thx in advance,
    tiggy

  • Importing classes from Jar files..?

    I've run into a problem that I am having some difficulty solving. I currently trying to port a two part Java UI project from Solaris to Windows. The first is a package of core classes out of which I (successfully) create a jar file. The second is a product-specific package that imports the core classes from the package created in the first. The problem is that the second package fails to build because javac says the package from part one does not exist. Here's what I know:
    - This UI (built via a Makefile) builds successfully under Solaris
    - The jar file that I created in the first part exists in the appropriate directory.
    - When I view the contents of that jar it appears as though everything is there.
    - The jar file is appropriately included in the classpath of the second build.
    Any suggestions you could provide, or resources you could point me to would be greatly appreciated

    jh.jar is a static, 3rd party component. Doesn't seem to be giving me any grief, at least not yet.
    Correct on your second point.
    This is interesting. When I open my "CoreConsole.jar"
    file, I DO NOT see any reference to the
    com.emc.avalon.core.server package, only a list of
    class files that make up that package. You should see the .class files on the left and the relative path on the right.
    Also, all of the class file listings have absolute paths according
    to the location on my machine they were built, for example:
    m:/xpe/CoreConsole/classes/com/emc/avalon/core/server/MessageLogUtility.class
    Is this a problem..?Yes, that should be a relative path, with the first entry being the first name in the package statement. So you should see an entry MessageLogUtility.class, and the path should be com.emc.avalong.core.server.
    If you can't see the class that's missing, that would explain why the class loader can't find it, either.

  • Add jar files and use those classes at the runtime

    Hi All,
    I need to add some jar files at the runtime depends on which the user selects where the jar file is located and i need to import those classes in other class for some functionalities . I could add jar files by using the URLClassLoader and Class.forName("myjar.myclassname") is also succeeded and i have no clue how to use those classes with in the jar file as i couldn't import those classes also in the source because the jar files are being added at the runtime(This leads to class not found exception at the compile time).
    I had found a complicated way of using those classes after being added at the run time as below.
       Class clazz = Class.forName(myClass);
                final Method method = clazz.getDeclaredMethod(requiredMethod, new Class[]{URL.class});
                final Object returned = method.invoke(clazz.newInstance(), new Object[]{request}); but, its really pain to use in this way in all the places.
    Does any of you have simpler suggestions on how to achieve this?
    Thanks,
    Venky.

    Thanks jschell. Yes, you are right. I had found that using reflection API is the only way to load classes at the run time. But according to our application using reflection makes the application little complex, so while start of the application or during other modifications, i am overwriting my jar file to the latest one using FileChannel class as below
          FileChannel ic = new FileInputStream("new.jar").getChannel();
          FileChannel oc = new FileOutputStream("old.jar").getChannel();
          ic.transferTo(0, ic.size(), oc);
          ic.close();
          oc.close();After this code is executed, our application totally uses the new jar file.It is little fast than using reflection. Is this a good idea?

  • Performance issue if we use jar file instead of classes

    Hi,
    My application uses tomcat as web server.
    If i use calsses in webapps -> WEB-INF -> classes folder, i place classes in that ,
    In other case i use jar file and place that file in WEB-INF -> lib folder in the webapps directory.
    There is huge performance difference.
    While using classes performance is great while using jar file performance is very disappointed.
    I am using a file for encryption /decryption also.

    I can't really believe that classes vs jars makes a difference, but whatever.

  • Strip classes actually  used in a jar file to create a smaller jar file?

    I am creating a applet using java3d and the jar files add up to over 4meg ( j3dcore.jar j3dutils.jar vecmath.jar). Is there a way you can strip out only the classes your applet uses and create a smaller jar file so that the download isn't as big? Currently takes a long while for the applet to start because it downloads the Java 3D library in its entirety.

    Most likely those classes that you use also use other classes that you don't use ...

  • Application in JAR file cant find JDBC classes

    Hi,
    When I run an application from the JAR file the ClassNotFound exception is throw! When I run from the application classes in the directory the program works. The JDBC classes are in the CLASSPATH, the manifest of JAR file is:
    Manifest-Version: 1.0
    Created-By: xxxxx
    Main-Class: com.xxx.jhdesk.JHelpDesk
    Class-Path: classes111.jar JdbcDomino.jar
    I tried to put "class-path" parameter in the manifest but the problem continues.
    I need to send only my jar file, and the JDBC classes would be anywhere at the client machine.
    Any hint will be appreciated!
    Thanks in advance!
    Daniel Carvalho

    Those two jar files in the Class-Path entry in the manifest file, are they in the same directory as the jar file? (What you put there is supposed to be relative to the jar file, and you have no directory information.) And is there a line-ending character at the end of that line?

  • Encryption/decryption through jar file and classes

    Hi,
    My application uses tomcat as web server.
    I am doing encrytion and decyption.
    i fetch encypted data from database and then decrypt it
    If i use calsses in webapps -> WEB-INF -> classes folder, i place classes in that ,
    In other case i use jar file and place that file in WEB-INF -> lib folder in the webapps directory.
    There is huge performance difference.
    While using classes performance is great while using jar file performance is very disappointed.
    I am using a file for encryption /decryption also.

    Are you getting any error messages? Have you put debugging code in those classes to see what is happening?

  • Unsupported class version error trying to run jar file on windows machine

    Hi,
    i've written a program that connects to an access database to get its data. Created a jar file with the class files, the access database and other required files.
    works fine on my home windows computer but when i try to run it on another machine i get an error.
    here's what i write on the cmd: java -Xmx128m -jar myFile.jar
    heres the error i get:
    Exception in thread "main" java.lang.UnsupportedClassVersionError: StartUp(Unsupported major.minor version 49.0)
    at java.lang.ClassLoader.defineClass0(Native Method)
    and so on.
    It seems like it might be quite a basic error but i'm lost, can anyone please shed some light and tell me where i'm going wrong?
    cheers in advance

    hey there, in case anyone was going to reply, i've worked it out now. couldn't work out what was wrong at first so just pulled out all my classes and put them into a brand new jar file. now use javaw -jar instead of java and it worked fine! wierd...

  • Adding all dependent classes of an applet to make a jar file

    Hi everyone,
    I have this problem which I was not able to find a solution for, So I truly appreciate any feedback on this.
    I have a project on eclipse which is basically an applet.
    This applet is using some classes in some jars that I have imported as libraries for this project.
    Everything works on eclipse with no problem. However I need to make a jar file of the applet and required classes to use it in an html page.
    Now that's the part I have been facing difficulties, cuz I have to include all the classes that the applet is using from other jar
    files. And I can not come up with a way to find out all those classes.
    On the other side if I include the whole jars then my applet goes over 100 meg and would be useless.
    I am going to give an example of the problem I have in hope of making it a bit clear.
    I have a applet, which uses some classes from some jars. i.e., class A. but class A itself need class B and etc.
    Now how can I find all these dependencies since I have to include them along the applet in the jar file I am going to make.
    Once again I appreciate any feedback and sorry that is a long question.

    Fractalz wrote:
    . . . Now that's the part I have been facing difficulties, cuz I have to include all the classes that the applet is using from other jar
    files. And I can not come up with a way to find out all those classes.See the Class-Path: parameter (of a Manifest file) documentation here:
    http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html#Manifest-Overview

  • Does Time Machine provide the same capability as Windows Restore?

    Hi - I am exploring backup and restore options for the MAC.  I am most familiar with Windows and Windows Restore, where you can restore a Win machine back to the same state it was at a particular point in time ( including the OS and system files. Does Time Machine provide this same capability?  Thanks in advance for your time.

    Yes, it provides the ability to recover personal documents only or a complete snapshot of the operating system with applications, files and settings present during the time that snapshot was taken.
    More info:
    Mac Basics: Time Machine backs up your Mac

  • Java 5.0 does not recognize wrapped Class-Path in Manifest.MF of .jar file?

    Java: build 1.5.0_05-b05
    Ant: 1.6.2
    I use Ant <jar> task to create a standalone application in a .jar file. I have a very long "Class-Path" in the Manifest.MF file. The long Class-Path is wrapped at every 70th character by the <jar> task. I cannot run "java -jar <the jar file>", because Java runtime cannot find classes.
    I found the following Q&A from ANT's FAQ page,
    Q: Whenever I use the Ant jar or manifest related tasks, long lines in my manifest are wrapped at 70 characters and the resulting jar does not work in my application server. Why does Ant do this?
    A: Ant implements the Java Jar file specification. Please refer to the notes section where it discusses the maximum allowable length of a line and the concept of continuation characters.
    If a jar file produced by Ant does not work in your appserver, and that failure is due to the wrapped manifest, then you need to consult your appserver provider, as it is a bug in their appserver. Far more likely, however, is a problem in your specification of your classpath. It is not Ant's wrapping of your classpath that is the problem.
    Do not raise a bug about this issue until you have checked to ensure that the problem is not due to your classpath specification.
    Any idea?

    "will be searched ALSO."...
    From: http://java.sun.com/docs/books/tutorial/ext/basics/load.html
    Understanding Extension Class Loading
    The extension framework makes use of the new class-loading mechanism in the JavaTM 1.2 platform. When the runtime environment needs to load a new class for an application, it looks for the class in the following locations, in order:
    1. Bootstrap classes: the runtime classes in rt.jar and internationalization classes in i18n.jar.
    2. Installed extensions: classes in JAR files in the lib/ext directory of the JRE.
    3. The class path: classes, including classes in JAR files, on paths specified by the system property java.class.path. If a JAR file on the class path has a manifest with the Class-Path attribute, JAR files specified by the Class-Path attribute will be searched also.
    [snip]

  • Including helper classes in java proxy jar file

    I must not be using the right header search criteria because I'm sure this question
    has been asked before. In a Web Service File (.jws) I've imported a couple of
    helper classes that function as data transfer objects. I did this to maintain
    consistency with other portions of the application. The Java Proxy jar file generated
    by Workshop does not include these files. Is there a way of including these dependencies
    or do I need to distribute another jar file with my helper classes?

    Hi Naichen,
    I was able to successfully run both the autotype and clientgen Ant task, on the
    WSDL you provided. The code behind those Ant tasks are pretty much what the WebLogic
    Web Services test page run. Are you using WLS 8.1 SP2? If not, you might want
    to try with that version.
    Regards,
    Mike Wooten
    "Naichen Liu" <[email protected]> wrote:
    >
    >
    >
    Hi,
    I am having a warning message when trying to generate java proxy jar
    file on weblogic8.1
    webservice test web app, the message is as follows:
    "Warning Failed to generate client proxy from WSDL definition for this
    service.
    Prescription Please verify the <types> section of the WSDL."
    in the mean time, on weblogic starting terminal, I saw the following
    exceptions,
    C:\DOCUME~1\u252738\LOCALS~1\Temp\wlwproxy37508.jar1533409921\com\ual\www\rcc\cb
    t\schema\modifypnr\AlphaLength4Deserializer.java:36: cannot resolve symbol
    symbol : class FacetUtils
    location: package binding
    weblogic.xml.schema.binding.FacetUtils.checkLengthFacet(__typed_obj,4L);
    ^
    C:\DOCUME~1\u252738\LOCALS~1\Temp\wlwproxy37508.jar1533409921\com\ual\www\rcc\cb
    t\schema\modifypnr\OSIFieldAnonTypeDeserializer.java:36: cannot resolve
    symbol
    symbol : class FacetUtils
    location: package binding
    weblogic.xml.schema.binding.FacetUtils.checkMaxLengthFacet(__typed_obj,69L);
    ^
    C:\DOCUME~1\u252738\LOCALS~1\Temp\wlwproxy37508.jar1533409921\com\ual\www\rcc\cb
    t\schema\modifypnr\AlphaLength2Deserializer.java:36: cannot resolve symbol
    symbol : class FacetUtils
    location: package binding
    weblogic.xml.schema.binding.FacetUtils.checkLengthFacet(__typed_obj,2L);
    ^
    C:\DOCUME~1\u252738\LOCALS~1\Temp\wlwproxy37508.jar1533409921\com\ual\www\rcc\cb
    t\schema\modifypnr\FreeFormAnonTypeDeserializer.java:36: cannot resolve
    symbol
    symbol : class FacetUtils"
    Can anybody help me about this issue? I attached WSDL file, also United
    Airlines
    got an enterprise weblogic license deal with BEA, any help will be highly
    appreciated.
    Thanks!!!
    Naichen

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

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

Maybe you are looking for

  • Can't import video from Canon GL-2 into new Macbook Pro

    Can't import video from Canon GL-2 into new Macbook Pro Using 9-4 pin cable and then using firewire 800 to thunderbolt adapter.

  • How to pass params to another class which accepts keyboard input?

    How can I pass params to a stand-alone Java class that, when executed, gathers params using readLine()? In other words, MyClass, when executed from the command-line, uses readLine to gather params for program execution. I'd like to test this class by

  • Re: Transactions & DB

    Thomas Mercer Hursh, Ph.D. wrote: > If so, is this risk confined to failure during the end transaction processing? I.e., if I stick in something after the third insert which takes 10 minutes (because I like being stupid!) and the failure occurs durin

  • Competing for a resource

    I don't know if this is the correct forum for my question. I'm developing an application using servlets+jsp following a MVC architecture. In particular, my application has to assign an appointment with a doctor. But there are many users (patients) co

  • Objectsclasses and attribute documetation

    HI Does anyone know where I can find documentation on the objectsclasses and attributes in Oracle Internet Directory 3.0.1. I'm dealin' with password profiles and would like to know which functionality the attribute pwdhistory and pwdinhistory attrib