Class to jar communication at run time

Hi,
I am developing a application using jdk 1.4 and have following query:
I have an application that displays some information in various languages (according to the language selected), i.e english, french, german etc. Say I select english, the application will display "Hello World" in English language and so on for other languages..
So my app is divided into three parts:
1) Core application : displaying information
2) XML file: Containing list of languages in XML format. This XML File can be updated for adding new languages. The format of XML file is somewhat as
<LANGUAGE_NAME>___</LANGUAGE_NAME>
<CLASS_LANG>____</CLASS_LANG>
3) A seprate JAR file :Having set of classes corresponding to each language. The JAR file should be such that we can add classes for new languages added.
The Workflow of app is as follows:
When ever we run the application, the application reads the list of languages from the XML file and populats the list in a drop-down list box. Now, upon clicking a "GO" button, the application checks the language selected and calls the JAR will. It sends the class name corresponding to the language selected. And the class should return the information back to the application.
Now, this process should be dynamic, i.e user can update XML with new language and update the JAR file with new class name.
And upon just re-running the application, the application should be able to use features of new language.
Consider that we have already shipped the application. All we have to do is to send updated JAR file to the user. and ask him to update the XML file for new language. i.e no changes to be done at application. And application should communicate with update JAR files at the end user.
Now I have following queries:
1) Is the above process possible? If yes, then
2) How to communicate my application with the new class files in JAR file. i.e how to communicate my class with the UPDATED class in JAR file. Any prototype code to achieve this functionality would be of great help. Remember all this need to happen at run time.
I hope my question is clear. Feel free to ask any queries.
Thanks,
rdh

Java has a mechanism to cope with this - though it is not XML-based:
java.util.ResourceBundle
I would store the required resource (a property file or the XML or a jar) separately.

Similar Messages

  • Find out wich class have colled method at run time

    hello
    If I have one class with some public method, is there a way to find out wich class have called it, and do it at runtime?
    I can't modie classes that a using this method.

    well if make method to throw something, then I have to by able to handle it within the class that calls it?!
    but I cant allter that class.
    did I missunderstadn how you mean?
         public boolean isBlocked() throws Throwable{
              try {
                   throw new Throwable();                    
              } catch (Exception e) {
                   e.printStackTrace(); //And how do I here get the class calling to the method?
                   return (nextSeqNum-base >=  windowSize);
         }

  • How to tell if a Class object is instantiable at run time ?

    Hi
    Newbie here, I am making some modification to an existing code and need to tell if
    a Class object can be instantiated. My specific object is an abstract class.
    I found I can ask if a Class is an interface via
    Class class = ...;
    if (class.isInterface())
    but could not find anything for abstract classes. Any idea ? Thanks

    baftos wrote:
    Modifier.isAbstract(clazz.getModifiers())Edited by: baftos on May 30, 2009 9:38 AMThis only covers the case of an abstract class. Below is a more robust solution. However even this solution has gaps - For instance, it is definitely possible to instantiate a URL object, but you've kind of got to know how to do it if you want to avoid a malformedURLException. If we are just talking about being able to instantiate the default constructor, this will suffice
    package tjacobs.test;
    import java.lang.reflect.Constructor;
    public class Test {
         public static class Bar {
              public static void install() {
              public Bar() {}
         public static abstract class Foo {
              public static void install() {
              public Foo() {}
         public static class FooBar {
              public static void install() {
              private FooBar() {}
         public static void abstractTest() {
    //          Foo.install();
    //          Bar.install();
    //          FooBar.install();
              abstractTest("tjacobs.test.Test");
              abstractTest("tjacobs.test.Test$Foo");
              abstractTest("tjacobs.test.Test$Bar");
              abstractTest("tjacobs.test.Test$FooBar");
         public static void abstractTest(String str) {
              Class c = null;
              try {
                   c = Class.forName(str);
              catch (Exception ex) {
                   ex.printStackTrace();
              try {
                   Constructor con = c.getConstructor(new Class[] {});
                   Object obj = con.newInstance(new Object[] {});
                   System.out.println("Can instatiate");
              catch (Exception ex) {
                   System.out.println("Cannot instantiate!");
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              abstractTest();
    }

  • Load Jar and access a class in jar at run time

    I need help from you.
    How to load a Jar and access a class in the jar at run time?
    When i try the following code it works fine while running in Java (Jdk1.5).If iam running the same code in servlet,ClassCastException occurs.
    Error Message : ClassCastExcption : jartest1 cannot be cast to Thing
    test.jar contains jartest.class and Thing.class
    jartest1.java
    try{
    File file =new File("test.jar");
    String lcStr ="jartest";
    URL jfile = new URL("jar", "", "file:" + file.getAbsolutePath() +"!/");
    URLClassLoader cl = URLClassLoader.newInstance(new URL[] { jfile });
    Class loadedClass = cl.loadClass(lcStr);
    Thing t=(Thing)loadedClass.newInstance();
    t.execute();
    catch(Exception e)
    System.err.println(e);
    Thing.java
    public interface Thing
    void execute();
    jartest.java
    public class jartest implements Thing
    public void exceute()
    System.out.println("Welcome");
    Thanks and Regards
    V.Senthil Kumar
    Edited by: senthilv_sun on Dec 16, 2008 8:30 PM

    senthilv_sun wrote:
    I need help from you.
    How to load a Jar and access a class in the jar at run time?
    When i try the following code it works fine while running in Java (Jdk1.5).If iam running the same code in servlet,ClassCastException occurs.
    Error Message : ClassCastExcption : jartest1 cannot be cast to ThingPresumably we can only hope that that is a transciption error. It always helps to use copy and past actual errors and code rather than manually typing them.
    test.jar contains jartest.class and Thing.classWrong.
    The interface class and plugable class must not be in the same jar.
    A plugable interface requires two components
    - Interface (generic sense)
    - Functional components.
    The Interface must be independant (own jar) so that it is available to the framework (user of plugin) and to the functional components. And the plugable component must not be on the java class path.
    This also means that we know for certain that the plugable component is also on the system class path. That is a bad idea as well.
    Given that it is pretty pointless to even speculate as to why this error is showing up. Create the correct jar layout. Test using the command line. Then test using servlets. Insure that the plugable jar is NOT on the java classpath for both tests.

  • Dynamic jar file inclusion at run time

    Hello,
    I have a java application which should accept the three parameters.
    1) The jar file location
    2) Particular Class file insdie that jar(we specified the location in step number 1)
    3) And method name in that class.
    My question is how to include specified jar location with jar name to CLASSPATH at run time. So that i can execute a particular method name in step number (3).
    I would appreciate for the quick reponse or any input.
    Thanks,
    Raghu

    And if you want to change the system classpathduring
    runtime, don't forget that you can always use
    reflection to call the System classloader'sprotected
    addUrl method :)Really?
    Seems reasonable although this is the first time I
    have seen that referred to.you can indeed. I've done this, as a quick avoid-writing-a-classloader hack. wouldn't really recommend it, though. if you're using reflection to modify access, chances are you're doing a massive fudge
    and of course, since it's not part of a public API, there's absolutely no reason to the method won't simply disappear in a future release....

  • Imported Jar file not loaded at run time ORA-105100

    Oracle 9iDS forms Version 9.0.2.9.0
    Oracle 9iAS Release 2
    I have imported java classes from a jar file into my form. I have it working in client server. Added the entries to the classpath in the default.env and system environment variable for development of the form and for execution.
    Moved the jar file, form and testing html to the application server. Modified the classpath in the default.env file. Tested the form. Got the ORA-105100 error. MetaLink note 261650.1 states that error frm-40735 When-Button-Pressed triger raised exception ORA-105100 if calling a java function from a jar file. Cause: Jar file not loaded at run time. Solution: add in your default.env CLASSPATH parameter your jar file including the whole directory of the jar file location. That has been done and the OC4J has been restarted. Still get error.
    Oracle support has not been able to give me much help as of yet. Does anyone have any further ideas, or documentation that I can read to help get this working?
    Thanks in advance for any assistance that is offered.

    Hey people any clues?

  • Jar run time problem

    Hi,
    I have an application in SWING where thumbnail images are being created at runtime and displayed in a ListCellRenderer. This is mainly used as a history feature where the user can click on that image and retrieve back the information.
    The problem is: when I run my code without an IDE it works fine as I am giving relative path names at all the places for storing the images. However, when I make a jar file, it is not able to read those images generated at run time.
    Is there a way to read runtime created files outside the jar file?
    Can someone help?
    Thanks in advance........

    sir,
    thanks for your reply.
    Again I give correct class path in Manifest.txt's
    Main-Class.
    ie., I am creating my mainclass as mainEMS.java and
    its .class file is lacated in D:/ram/classes/sdff
    folder. So I am giving the Manifest.txt ,the main
    class as " Main-Class: ram.classes.sdff.mainEMS
    fter that i give enter.
    then create the jar file.
    but, after creating jar file, it will again show,
    "Failed to load Main-Class manifest attribute from
    D:/kbs.jar "
    what's my problem.Does the file META-INF/Manifest.mf containt the Main-Class entry or do you have it only in Manifest.txt... there is a huge difference.

  • The Apache axis2 jar files are not taking at run time

    While running the application I was getting the following errors. The error is getting at run time only. It has compiled successfully.
    It ran under eclipse without any issues. But with Apache axis we are getting following error trace while uploading to server. The Apache axis2 jar files are not taking at run time.But compiling successfully.
    The application is running under Oracle R12 server.I didn't find any option to set class path for run time in R12 server.
    Using Java version is 1.6 and Apache axis2.1.6.2
    Error trace:
    Exception :java.lang.NoClassDefFoundError: Could not initialize class org.apache.axis2.description.AxisService
    Error : java.lang.NoClassDefFoundError: Could not initialize class org.apache.axis2.description.AxisService
    com.rightnow.ws.wsdl.RightNowSyncServiceStub.populateAxisService(RightNowSyncServiceStub.java:41)
    com.rightnow.ws.wsdl.RightNowSyncServiceStub.(RightNowSyncServiceStub.java:636)
    com.rightnow.ws.wsdl.RightNowSyncServiceStub.(RightNowSyncServiceStub.java:625)
    com.rightnow.ws.wsdl.RightNowSyncServiceStub.(RightNowSyncServiceStub.java:673)
    com.rightnow.ws.wsdl.RightNowSyncServiceStub.(RightNowSyncServiceStub.java:665)
    com.rightnow.ws.util.ContactUtils.initializeService(ContactUtils.java:57)
    somejsp.jspService(_somejsp.java:189)
    com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)
    oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:473)
    oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:594)
    oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:518)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:64)
    oracle.apps.jtf.base.session.ReleaseResFilter.doFilter(ReleaseResFilter.java:26)
    com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:15)
    oracle.apps.fnd.security.AppsServletFilter.doFilter(AppsServletFilter.java:318)
    com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:642)
    com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:391)
    com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:908)
    com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:458)
    com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:313)
    com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:199)
    oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
    com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
    java.lang.Thread.run(Thread.java:619)

    Hello,
    I too am trying to use Axis2 application in R12. But getting the following error:
    java.lang.classCastException: com.sun.xml.messaging.saaj.soap.ver1_1.SoapMessageFactory1_1Impl cannot be cast to oracle.webservices.soap.VersionedMessageFactory
    If I run the application standalone from java command line it works fine. I think the error could be because of some oracle app jars getting picked up inatead of my application jars. How to make sure that my application jars get picked up instead of oracle jars
    I tried loading my jar file and then setting it as contextClassLoader using "Thread.currentThread().setContextClassLoader", but this did not help.
    Can you please let me know what can be tried to fix this
    Thanks
    Srikanth

  • How to Load Classes in run time - Urgent

    Hi All,
    How to Load a class file from a .jar file in JDK1.1 with out using URLClassLoader. I have tried to extract the .jar file by file input stream and zipEntry classes and defineClass using the bytes i got from the stream , but the class loader fails to take the classes that are already loaded in the system.
    The customClassLoader that i created was not able to assign an object to the another reference variable that already in the JVM.Please i want to know how to assign or communicate between the objects of CustomclassLoader and SystemClassLoader?
    Please help me in this regard.
    Thanks in advance,

    Hi,
    The above code works in the straight way if the class is available in the classpath.
    I need to load a class by using custom class loader that i extends from classloader base class .
    I have to read a class file from a .jar file (in server) and load it in run time.Here i am able to read the bytes from the .jar file of the specified class file, but the class that i read extends some other class that is already loaded when i tried to create newInstance of the class i get Exceptions. Here the custom classLoader cannot find the loaded existing class in the JVM.can i get a solution for this situation

  • LoadClass    (error loading a class which extends other class  at run-time)

    Hey!
    I'm using the Reflection API
    I load a class called 'SubClass' which exists in a directory called 'subdir' at run-time from my program
    CustomClassLoader loader = new CustomClassLoader();
    Class classRef = loader.loadClass("SubClass");
    class CustomClassLoader extends ClassLoader. I have defined 'findClass(String className)' method in CustomClassLoader.
    This is what 'findClass(String className)' returns:
    defineClass (className,byteArray,0,byteArray.length);
    'byteArray' is of type byte[] and has the contents of subdir/SubClass.
    the problem:
    The program runs fine if SubClass does not extend any class.
    If however, SubClass extends another class, the program throws a NoClassDefFoundError. How is it conceptually different?
    Help appreciated in Advance..
    Thanks!

    Because i'm a newbie to the Reflection thing, i'm notI don't see reflection anywhere. All I see is class loading.
    sure what role does the superclass play when i'm
    trying to load the derived class and how to get away
    with the errorWell... hint: all the superclass's stuff is not copied into the subclass.
    I am quite sure it fails to load the superclass because of classpath issues.

  • Run time error while using Class gcl_error

    Hi All,
    I am getting run time error while using class gcl_error
                                          type REF to zsreport_error_handling:
    '' Attempt to access a component using 'NULL' object reference (points to nothing).
    An object reference must point to an object ( an instance of a class) before you can use it to access components ( variable : ''GCL_ERROR'').
    Either the reference point has not yet been set or it has been reset to 'NULL' by a clear statement."
    Can you please suggest any solution for this ?
    Thanks in advance.

    Dear All
    Its Resolved Thanks For your Valuable time Support
    INCLUDE LV03VFB4 inside below code trigger error.
    PERFORM VVBBD_AUFBAUEN USING WA_AVBBD
                                        WA_AVBBD-APOMOBILE
                                        DA_SUBRC
                                        DA_UPDKZ
                                        DA_VVBBD_TABIX
                                        0.
    This Was the Error some how 0 was there we are removed the 0 now it is working fine
    Rgds
    Thomson

  • How to get class name of a object in run time, from its accessible context.

    Hi,
    I need to get the class name of a java object in run-time, given the AccessibleContext of that object.
    I gone through the AccessibleContext api documentation. but there is not way to get the class name for a java object using its AccessibleContext object.
    Do any one have any idea how to get the class name of an java object, given its accessible object Accessible.
    Thanks
    Timberlake

    816311 wrote:
    Please try to provide a solution for my requirement and avoid evaluating a requirement.
    I am a curious guyit's great to be curious. however, in this situation, the requirement makes no sense in the given context. so, in an effort to be helpful, the people on this forum are asking you the reason behind the requirement. the reason we do this is because we have experience answering questions on this forum and, more often than not, requirements which don't make sense are the result of misunderstandings or confusion on the part of the person making the requirement. if we can figure out why you want to do what you want to do, we may be able to point you in a direction which makes more sense.

  • How to get info from a .class file at run time? thanks for help

    I need to get methods and properties (variables) from a .class file at run time.
    as u know, javap.exe can do that in an independent way. but i need to get info at run time once the .class or packeges have been changed, javap is not suitable in the case.
    i try to read data directly from .class file but it's hard to know the file format.
    e.g. a class looks like (java file):
    class MyClass extends Frame
    int i0;
    String s0;
    public String getName()
    if the file is compiled to .class file, how to get properties (variables: i0,s0) and methods String getName() from the .class file by an applicaton at run time?
    Doclet is not suitable for speed reason, it is too slow to get right info in right format.
    Thanks for any help, please write a little bit more in detail if you know.

    Use the Java Reflection API. Have a look at the Reflection section of the Java Tutorial located at http://java.sun.com/docs/books/tutorial/reflect/index.html

  • How to instantiate classes at run time with constructors having arguments?

    I have to instantiate some classes in the run-time because they are plugins. The name of the plugin (pluginClassName) comes from a configuration file.
    Currently I am doing this to achieve it:-
    UIPlugin plugin = (UIPlugin)Class.forName(pluginClassName).newInstance();However, there is a disadvantage. I can not pass arguments to the constructor of the plugin.
    public class RainyTheme extends UIPlugin {
      public RainyTheme() {
       // bla bla
      public RainyTheme(int x, int y , int width, int height) {
       // set co-ordinates
       // bla bla
      // bla bla bla bla
    }Now if I want to instantiate this plugin at runtime and at the same time I want to pass the 4 arguments as shown in the second constructor, how can I achieve this?

    I have no experience with JME and the limitations of its API, but looking at the API docs ( http://java.sun.com/javame/reference/apis.jsp ) it seems that there are two main versions, CLDC and CDC, of which CLDC is more limited in its API.
    The Class class does not contain the methods getConstructor(Object[]) or getConstructors() in this version ( http://java.sun.com/javame/reference/apis/jsr139/java/lang/Class.html ), so it seems that if you are using CLDC then there is no way to reflectively call a constructor with parameters. You'd have to find another way to do what you want, such as use the noarg constructor then initialise the instance after construction.

  • No such class at run--time?

    Hi there.
    I'm trying locate the following constructor at run=time:
    package cliquespace.core.agentdevice.cliquespace.agent.device.spine;
    final public class AgentDeviceActiveAffiliation extends DeviceActiveAffiliation<AgentDeviceActiveAffiliationPrecis,AgentDeviceMediaProfile,
    AgentDeviceConnection,AgentDeviceActiveAffiliation>{
        public AgentDeviceActiveAffiliation(SourceCliqueSpace sourceCliqueSpace,LimitingConstraint[]limitingConstraints,
            AgentDeviceActiveAffiliationPrecis precis)throws CliqueSpaceException{
            super(sourceCliqueSpace,limitingConstraints,precis);
        }Note that DeviceActiveAffiliation extends SourceActiveAffiliation.
    I use the following code to do this:
    214    public SourceCliqueSpaceElement createElementFromPrecis(SourceCliqueSpace cliqueSpace,SourceCliqueSpaceElementPrecis precis)
    215     throws CliqueSpaceException{
    216        /**
    217         * Get the Element's class.
    218         */
    219        Class cl=null;
    220        try{
    221            cl=Class.forName(precis.getElementCanonicaName());
    222        }catch(ClassNotFoundException cnfe){
    223            ReceiveElementGivenCanonicalTypeHasNoSourceCliqueSpaceElement x=
    224             new ReceiveElementGivenCanonicalTypeHasNoSourceCliqueSpaceElement(precis.getIdentifier(),precis.getElementCanonicaName());
    225            x.initCause(cnfe);
    226            throw x;
    227        }
    228
    229        /**
    230         * Get the class's precis constructor.
    231         */
    232        Class[]paa=new Class[3];
    233        if(precis.getCliqueSpaceType().equals(AgentCollaborationCliqueSpace.class.getSimpleName())){
    234            paa[0]=AgentCollaborationCliqueSpace.class;
    235        }else if(precis.getCliqueSpaceType().equals(AgentDeviceCliqueSpace.class.getSimpleName())){
    236            paa[0]=AgentDeviceCliqueSpace.class;
    237        }else{
    238            throw new CreateElementFromPrecisCliqueSpaceTypeIsUnknown(this.getName(),precis.getCliqueSpaceName(),precis.getCliqueSpaceType());
    239        }
    240        paa[1]=LimitingConstraint[].class;
    241        paa[2]=precis.getClass();
    242        Constructor co=null;
    243        try{
    244            co=cl.getConstructor(paa);
    245        }catch(NoSuchMethodException nsme){
    246            ReceiveElementNoPrecisConstructorExistsForSourceCliqueSpaceElement x=
    247             new ReceiveElementNoPrecisConstructorExistsForSourceCliqueSpaceElement(precis.getIdentifier(),precis.getElementCanonicaName());
    248            x.initCause(nsme);
    249            throw x;
    250        }
    276    }[/code.
    However, when the code runs, I get the following exception:cliquespace.core.exception.agentdevice.agentdevice.ReceiveElementNoPrecisConstructorExistsForSourceCliqueSpaceElement: An Element identified by [9DNCEJ0AVQVJLJEHP00EKTKKJWMXB77U2C9XCZAQ] of type [cliquespace.core.agentdevice.cliquespace.agent.device.spine.AgentDeviceActiveAffiliation] cannot be constructed from a received precis because the given class has no precis constructor.
    Caused by: java.lang.NoSuchMethodException: cliquespace.core.agentdevice.cliquespace.agent.device.spine.AgentDeviceActiveAffiliation.<init>(cliquespace.core.agentdevice.cliquespace.AgentCollaborationCliqueSpace, [Lcliquespace.core.cliquespace.constraint.LimitingConstraint;, cliquespace.core.agentdevice.cliquespace.agent.device.spine.activeaffiliation.AgentDeviceActiveAffiliationPrecis)
            at java.lang.Class.getConstructor0(Class.java:2723)
            at java.lang.Class.getConstructor(Class.java:1674)
            at cliquespace.core.agentdevice.AgentDevice.createElementFromPrecis(AgentDevice.java:244)
            at cliquespace.core.agentdevice.AgentDevice.receiveElement(AgentDevice.java:346)
            at cliquespace.core.agentdevice.AgentDevice.receiveElement(AgentDevice.java:64)
    ...[/code]
    Note, AgentCollaborationCliqueSpace also extends SourceCliqueSpace. So, specifying either AgentCollaborationCliqueSpace or AgentDeviceCliqueSpace should yield the given constructor.
    As far as I can determine, the other parameters line up.
    It's got me stumped. Your advice, suggestions and/or, help would be appreciated.
    Thanks,
    Owen.

    One needs to use the class declared in the parameter, even, as SourceCiqueSpace is in this case, if the class is abstract.

Maybe you are looking for