System Properties Class Loader, how to?

Hi,
I am trying to configure the WLS startup class to load some property class into system, i.e example.properties
What does is it take?

Hi,
Step1). Create a Startup class like following:
package startup;
import java.util.*;
import java.io.*;
public class MyStartUp
    public static void main(String ar[]) throws Exception
           MyStartUp start=new MyStartUp();
              Properties p=new Properties();
           InputStream stream=start.getClass().getClassLoader().getResourceAsStream("a.properties");
                 p.load(stream);
           System.out.println("\n\n\t Your City is : "+p.getProperty("city"));
} Step2). Compile the above class like following
javac  -d . MyStartUp.javaStep3). Now make a Jar which will include your properties file and the above Class
jar -cvf  MyStartup.jar   startup  MyStartUp.java  a.propertiesStep4). Now put the MyStartUp.jar inside "$DOMAIN_HOME\lib" directory
Step5). Configure the startup class from AdminConsole then restart your Server.
Thanks
Ravish Mody

Similar Messages

  • Custom applet class loader, how?

    Fellow Java programmers;
    I would like to load 'secure' class files (ie encrypted) into an applet at startup time.
    I have code that does this for a normal java program.
    How do you go about using a custom class loader in an applet?
    Would something like this work? (using say *.Xclass local encrypted class files)
    ..somewhere in theapplet: init().. runClass()
    .public void runClass(name)
    { aCL = new AppletClassLoader(); // extends ClassLoader
    Class c = aCL.loadClass(name);
    Method m= c.getMethod("main"..)
    m.invoke(...);
    Your comments or pehaps a code snippet would be appreciated.
    Thanks, John

    John,
    this does not work without modifying the runtime client environment.
    Security constraints will prevent you from setting up a new class loader, so you will have to at least grant this permission in a policy file deployed to your clients as you will have to deplay the encryption keys.
    As bringing in a new class loader from an applet is highly security critical, this should be backed by a rather strict policy and by signing the applet.
    Though the example you provided might work, the class loader implementation itself is not so easy-
    If you would like to imitate the findClass() and loadClass() methods from SUN you will see that those are complex and not suitable for "hooking" in an encrypted stream.
    You might try an easier way:
    Load the class data as an encrypted byte array, decrypt it and use SUNs class loader methods to define a JAVA class out of this byte array:
    ClassLoader.defineClass(String�name, byte[]�b, int off, int�len)
    This seems to be easier than implmenting your own loader.
    Oliver

  • Implementation of Class Loader

    i use resource bundle to load values in the properties object instead i have to use class loader ,how can i use the same

    The JVM source code are available but i do no where "sun.boot.class.path" is defined. I mean in which part of the source code. There are many folders in hotspot source code. As this is a part of bootstrap classloader code, i want to know where is this bootstrap source code.

  • Tomcat Class Loader

    I have setup tomcat 4.1.12 on WinXP. Tomcat is integrated with IIS.
    I am able to work with my web applications. My problem is :
    I cant use my own classes in my application. Tomcat is not able to locate my .class file, i think. I have tried this:
    1) created c:\tomcat4\webapps\myapp\WEB-INF\classes and placing my .class file in it.
    2) created c:\tomcat4\work\Standalone\localhost\myapp\WEB-INF\classes and placing my .class file in it.
    3) placed my .class file under D:\tomcat4\shared\classes
    4) placed my .class file under D:\tomcat4\common\classes
    After each step, I restarted the Tomcat service and the IIS service.
    I checked my Tomcat Application Manager, my application is there but the WEB-INF folder is not visible. But if I rename it and refresh the page, the renamed folders appears. I'm not sure why this is happening. I would be grateful if anyone could clarify this for me.
    I have referred to the documentation - Class Loader - HOW TO ... but cant solve this problem. Did I miss anything?
    Please help.

    Try this create somename\WEB-INF\classes\ fold and add all classes and then create a war file. And put the war file in webapps of tomcat. There is no problem in running tomcat and IIS totgether.

  • How to load a class dynamically in the current/system class loader

    I need to dynamically load a new jdbc driver jar to the current/system class loader... Please note that creating a new classloader will not help since the DriverManager refers to the systemclassloader itself.
    Restarting the application by appending the jar to its classpath will solve the problem but I want to avoid doing this.

    Did you then create a ClassLoader to load the JDBC
    driver and then install it into the system as
    directed by the JDBC specification (ie
    Class.forName(someClassName))?
    And then try to use it from a class loaded fromsome
    other ClassLoader (i.e. the system class loader)?
    If you did not try this please explain why not.O.K. I just looked at the source to
    java.sql.DriverManager. I did not know what I was
    talking about, as what I suggested above will not
    work.
    This is my new Idea:
    Create a URLClassLoader to load the JDBC driver also
    in this ClassLoader you need to place a helper class
    that does the following:
    public class Helper {
    public Driver getJDBCDriver(String driverClassName,
    String url) {
    try {
    Class.forName(driverClassName);
    Driver d = DriverManager.getDriver(url);
    return d;
    catch(Exception ex) {
    ex.printStackTrace();
    return null;
    }Now create an instance of the Helper class in the new
    ClassLoader, and call its getJDBCDriver method to get
    an instance of the driver (you will probably have to
    create an interface in the root class loader that the
    Helper implements so that you can easily call it).
    Now from the root classloader you can make calls
    directly to the returned Driver and bypass the
    DriverManager and its restrictions on cross
    ClassLoader access.
    The only catch here is that you would have to call to
    the returned Driver directly and not use the Driver
    Manager.This sounds like will work but I did not want to load DriverManager in a new classloader.. I did a hack
    I unzip the jar dynamically in a previously known location (which I included in my classpath when launching the app). The classLoader finds the class now though it did not exist when the app was launched !
    A hack of-course but works eh ..

  • How are the java system properties loaded into the Oracle 8.1.7

    I have listed the java system properties both standalone and in the Oracle database. The standard list of system properties is quite extensive and informative. But the list of system properties from the Oracle database is severely truncated.
    I expect these properties are initialized on database startup.
    If that is the case, I expect there to be a file and initialization parameters that define where the information is kept and there values.
    Can anyone give me some guidance?

    System*.properties file should be located in the $ORACLE_HOME/javavm/jahome directory
    I have listed the java system properties both standalone and in the Oracle database. The standard list of system properties is quite extensive and informative. But the list of system properties from the Oracle database is severely truncated.
    I expect these properties are initialized on database startup.
    If that is the case, I expect there to be a file and initialization parameters that define where the information is kept and there values.
    Can anyone give me some guidance?

  • System class loader vs application class loader

    Hello
    I have a class that uses a third partyjar which I have put in /jre/lit/ext. The class compiles but fails at runtime being unable to read the property files called in the class' constructor. I believe that is b/c the third party jars are loading w/ the system class loader and cannot "see" the property files "floating" at the same level as the class that is calling them.
    So I created a jar, of the property files, with the same directory/package structure as the location of the property files and put that in the /jre/lib/ext and STILL the same problem; cannot read the property files, the constructor fails, fugly. There is an overloaded constructor that includes a parameter for the property files, but I need to get this to work as is first. What am I missing? Please edify me. tia.

    If the 3rd party jar needs a certain properties file to initialize correctly, I doubt it would be looking for it in the class hierarchy. I mean I doubt it does:
    Properties p = new Properties();
    p.load( getClass().getResourceAsStream() );It's more likely to do:
    Properties p = new Properties();
    p.load( new FileInputStream(...) );The reason is that the property file should be easily edited by the user and users know how to move around in the file system, not in the Java jars and classpaths.
    Just a guess...

  • Using system resource to redirect class loading

    It seems to be an open secret that the JVM can be manipulated to load classes (or packages?) from alternate locations.
    Take, for example, this excerpt from a SAX user guide:
         In case your Java environment did not arrange for a compiled-in default (or to use
         the META-INF/services/org.xl.sax.driver system resource), you'll probably need to
         set the org.xml.sax.driver Java system property to the full classname of the SAX
         driver, as in
              java -Dorg.xml.sax.driver=com.example.xml.SAXDriver MySAXApp sample.xml
    So what is the "META-INF/services/org.xml.sax.driver" system resource? Clearly this resource is tied (historically) to the Manifest file in the jar archive format. Is the META-INF/services prefix special for remapping class names? What other services are there? What other resources can be placed in the META-INF directory? Does this work only for Manifest files in jar archives, or does it also work for conventional file systems?
    Does the -D option set class locations or package locations? How is the replacement class located (using the same class path)? Is the actual package/class name available for every (potentially) loaded package/class?
    How does this work? Where is this documented? What is this called?

    Thanks for the reply, but this doesn't really answer
    the questions that I intented. Let me try again.
    The original posting shows two ways that the JVM can
    be coerced to load a implementation from an alternate
    location. This coeretion process seems to be an
    undocumented, ad hoc extension to the JVM. For the
    purposes of these question, I call this process "class
    substitution".No, you are misinterpreting what you are seeing there.
    The example command that you gave does nothing but define a property which is available via System.getProperty().
    That is all it does in terms of java (actually Sun's implementation of java.)
    >
    A) Where in the Java documentation is this type of
    class substitution discussed? I have searched the
    Java language definition, Sun's Java site, and "Java
    In a Nutshell" for references to "system resources",
    "services", and various alternatives to no avail. The
    documentation has some reference to Properties, but
    the connection to class substitution is opaque to me.
    There is no class substitution.
    There is however, class loading. And that can be done in several ways.
    1. For one you can write your own class loader - see java.lang.ClassLoader.
    2. Or you can also load your own classes, which is likely to be what the command line you see is doing (when you run other code associated with that in your own application.) That is called reflection. You could start with the java.lang.Class - and practically any java book will cover it.
    3. And it is possible to to load your own class instead of a core class. For example you could replace java.lang.String. Your command line does not do that. But if you look that the documentation for java (Sun) you will find references to the Xbootclasspath option.
    For 1 and 2 above the Sun JVM will do nothing with the command example you gave unless you write some code or use some code (outside the sun jvm) that uses it. For 3 it doesn't have anything to do with example you gave.
    B) Can I achieve this result (class substitution) If I
    put a META_INF directory in a normal file system class
    directory, or does this only work for JAR files. I'm
    sure a simple experiment would suffice, but I'd like
    to know WHY?

  • How do I set System properties within WL6.0?

    I am setting WL6.0 up to have a startup class, but this class needs to
    read system properties which have not yet been set. How do I set these
    up within weblogic? I was able to get the startup class set up, but it
    needs these system properties to continue.
    gmo

    Correct on all points. The one advantage of doing this in java is that you can more easily do more
    complex things like accessing configuration information from a remote data store (like a database).
    Dimitri Rakitine wrote:
    These are not needed if you simply replace java ...lots of options... weblogic.Server with
    java ...lots of options... startmyWLS in the script which starts WebLogic, but, on the other
    hand, this solution is no different from simply adding -DmyProperty=myValue to the startup script
    (I think that the ultimate goal is the ability to deploy(and redeploy!) components,
    without any mods to the particular vendor's startup scripts of anything of that nature).
    Kumar Allamraju <[email protected]> wrote:
    Thanks to robert for a quick workaround..
    I tried to start the WLS with the following piece of code and actually i need to set
    some additional properties
    for successful server startup.
    Here it is
    import java.util.Properties;
    public class startmyWLS
    public static void main(String[] args)
    Properties props = System.getProperties();
    props.put("myProperty", "myValue");
    props.put("bea.home", "E:\\bea");
    props.put("weblogic.Domain", "mydomain");
    props.put("weblogic.Name", "myserver");
    props.put("java.security.policy",
    "E:\\bea\\wlserver6.0\\lib\\weblogic.policy");
    System.setProperties(props);
    weblogic.Server.main(args);
    Make sure you run this from E:\bea\wlserver6.0., as it tries to read config.xml
    config\[your-domain-name] from this
    directory.
    Kumar
    Robert Patrick wrote:
    import java.util.Properties;
    public class StartMyWebLogicServer
    public static void main(String[] args)
    Properties props = System.getProperties();
    props.put("myProperty", "myValue")
    System.setProperties(props);
    weblogic.Server.main(args);
    gmo wrote:
    That won't work since it has to be 'outside' of the code. It's a service, and
    services are started when weblogic is started up, not when I call a bean.
    And it has to be dynamic, since the properties will vary on evry installation.
    Robert Patrick wrote:
    You can also use System.setProperty() or a combination of
    System.getProperties() followed by a System.setProperties()...
    gmo wrote:
    They are not normal system properties. I'm using some open source code, and
    it requires settings to be system properties, but they are specific to the
    application, which means that they are not already in the system
    properties. I know how to get them, and after some more research, you can
    set them on the command line when starting up weblogic. However, is this
    the best way to set system properties?
    Robert Patrick wrote:
    What "system properties" are you trying to find?
    gmo wrote:
    I am setting WL6.0 up to have a startup class, but this class needs to
    read system properties which have not yet been set. How do I set these
    up within weblogic? I was able to get the startup class set up, but it
    needs these system properties to continue.
    gmo
    Dimitri

  • How to dynamically refresh system properties when changed

    Hi All,
    Through weblogic startup class I'm loading the properties from a properties file
    into system properties, Now my requirement is to refresh those system properties
    when ever I make changes to the properties.
    Is there any way to achieve this functionality through MBeans.

    Hello Lucky,
    I believe you cannot refresh properties file dynamically using MBeans. What
    you can do is write an MBean which necessrily mirror your property file and
    register with MBeanServer. You can set values on the MBean dynamically but
    in order to persist your changes you need to write your own persistance
    mechanism.
    Cheers
    Ali
    "Lucky" <[email protected]> wrote in message
    news:3f84d68f$[email protected]..
    >
    Hi All,
    Through weblogic startup class I'm loading the properties from aproperties file
    into system properties, Now my requirement is to refresh those systemproperties
    when ever I make changes to the properties.
    Is there any way to achieve this functionality through MBeans.

  • Properties Class, How does it work

    Hi
    I was struggling to find how to use Properties Object, to read properties file, then I saw the following solution:
    fis = <classname>.getClass().getResourceAsStream("<prop file>"); (1)
    prop = new Properties();(2)
    prop.load(fis);(3)
    fis.close();(4)
    This works fine, but I am not able to understand, how does it work?
    <classname>.getClass() should return a class object, and this class must be havaing getResourceAsStream() method, which is used by the properties object. But what is the need of first getting a "class" object. Our aim is to open the Properties file, then why do we need any reference to the current class.
    Can anybody explain the jargon of the line -(1)
    Gaurav

    the Class class is defined in the lava.lang package. The java virtual machine (JVM) uses a class loader to load class definitions from wherever <g> into memory, ok? The Class class represents the JVM's internal holding of a class definition (as opposed to instances of the class itself).
    To get the Class for any class, you can use the getClass() method on any object, or you can use the <classname>.class syntax. Either way, you get an instance of Class.
    The Class class contains some utility methods about class definitions prresent in the JVM. Importantly, the Class object for a class contains a reference to the class loader that loaded the class. You get it with the getClassLoader() method. The class loader is a thing that knows how to get a class definition from a local drive, or of a jar file, or off the web (if you are using an applet), or whatever. If one class needs another class to work, the class loader knows how to get the definition for that other class.
    Say I have a class
    class Foo {
       int bar(Baz baz);
    }and another one
    class Baz {
    }And both of these are in a jar file at http://z.com/applet1.jar
    An instance of URLClassLoader will be used to fetch class Foo. When Foo needs the definition of Baz, that same loader will be used to get Baz.
    A jar file (or a directory on your local drive) can contain anything at all, not just .class files. It might contain .prioperties files. These are called "resources". If you bundle them up with your class files, then the class loader that loaded the class files can also get them. So if your widget has gif files that it uses for icons, you just bundle them all up together.
    Of course, Class.getResource() is just a convenience method for Class.getClassLoader().getResource().

  • Why won't -Djava.system.class.loader make it use my ClassLoader?

    I created a class MyAppLoader and installed it in the bootclasspath and used the system property -Djava.system.class.loader. Yet, the JVM won't use my classloader! It's never instantiated (I have a static bit that prints code if it's loaded at all).
    How do I make the JVM use my class as the system classloader?

    send to me some Duke, please Any particular one? I hear the Duke of Northumberland is quite a laugh - would he do?

  • Replacing system class loader

    Hi!
    I'm trying to replace the system class loader for plugin management reasons. I've written a simple test app for testing, but it doesn't work. The first code is a ClassLoader, the second is the main code.
    I try to run the code like this: java -Xbootclasspath/a:. -Djava.system.class.loader=A -cp . B
    It uses my classloader every time, except for when I call Class.forName(). What could be the problem?
    Thanks, Bal�zs
    public class A extends java.lang.ClassLoader {
    public A(ClassLoader parent) {
    super(parent);
    System.out.println("A loaded, parent is " + parent);
    public Class loadClass(String name) throws java.lang.ClassNotFoundException {
    try {
    Class c = getParent().loadClass(name);
    System.out.println("A was asked for " + name + " and delegated it to " + getParent());
    return c;
    } catch (ClassNotFoundException e) {
    System.out.println("A was asked for " + name + " but didn't find it");
    throw new ClassNotFoundException(name + " not found :[");
    }; // ENDOF CLASS A
    public class B {
    public static void main(String[] args) {
    (new B()).proc();
    private void proc() {
    System.out.println("Hello World!");
    System.out.println("Class loader: " + getClass().getClassLoader());
    try {
    Class.forName("C");
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    }; // ENDOF CLASS B

    Thanks for the reply. I think I've got a much better idea of how this stuff works now. I think what I need to do is register my deserializer with SOAP as a class that will really load the deserializer using Class.forName() with my class loader as a parameter. Then when the bootstrap class loader can't find a class, findClass() in my classloader will be called and I can load it from a URL.
    Should work.
    Thanks very much!

  • How to configure Class Loading-Import Shared Library using admin_client

    i am deploying ear using below command through command prompt.its deployed successfully.
    java -jar ../admin_client.jar deployer:oc4j:localhost:23792 oc4jadmin oc4jadmin -deploy -file C:/ex.ear -deploymentName ex -bindAllWebApps
    i have one requirement if i deploy thorugh command prompt. while deploying ear through admin console in Deploy: Deployment Settings-Configure Class Loading-Import Shared Libraries-i checked JAXB then the ear will be deployed successafully.
    i need to incorporate same thing in above command also.i have created shared library and jars are placed in this path.
    C:\Oc4J\j2ee\node1\shared-lib\JAXB\2.0
    but while deploying ear using admin_client.jar command script i need to configure classs loading and import above shared library.how to modify the script?

    Ours is not a Desktop Application, but we want to handle Authentication(Which authenticates the userid and password by making a Tuxedo call) and add the Principal to Subject in session, so that ADF Authorization and securityContext can be used as is,
    but doing this with Custom Authentication Provider in weblogic needs me to have a lot of Tuxedo Service related jars in weblogic/system classpath which i feel is not right thing to do, as the same jars are required in application also, which means i will have the jars in class path twice and i need to deploy the jars to both places everytime there is any change.
    Is there any way by which i can set Authenticated principal to Subject in the created session from within Application?

  • Via APIs. how can I get weblogic specific system properties

    I am looking to find out the API for enumerating over weblogic's system
    properties. I would like to be able to find out things like the service
    pack #, the class path it's using, etc. I've tried the
    System.getProperties() but that only gets me java properties.
    Thanks.

    try getServletContext().getResourceAsStream("/index.html") where the filename should be givven relative to the web app root
    try{
    InputStream is = new BufferedInputStream(getServletContext().getResourceAsStream("/index.html"));
    defaultProps.load(new FileInputStream("Intranet_Properties.props"));
    finally {
         if( is != null ){
              is.close();
    }

Maybe you are looking for

  • How to use a servlet adapter ?

    Hi all, I try to use the servlet adapter, but documentation is not very usefull on this point (like on many other point). The first step in documentation is : Create a directory in the classpath oracle.panama.adapter.servlet for the .class file. The

  • Unable to set default mail account in iOS

    I'm unable to choose my default mail account. I have two IMAP mail accounts configured. One of the two accounts was imported using a configuration profile supplied by the mail service provider. This worked well, except that iOS doesn't seem to recogn

  • X200 under Windows 7, fingerprint login pass through stalls

    (sorry, new to the forum --- I think this way of expressing the subject will be  less likely to be ignored) This is a new machine for us as well as a new operating system. We aren't using the fingerprint login and don't intend to. Usually when the ma

  • The problem of notebook gx710

    Does not start after power-up. The lamp power light, hard drive spin up, the fan runs, and the monitor is constantly dark. Times with the 15th running Windows, but after restarting everything the old way. Help me, please!!! 

  • When using Facetime or texting...

    When using Facetime or texting, do you have to have internet?