Can we set classpath dynamically

Is it possible to set Classpath from java code .. Before executing a Java class we can set classpath manually using set classpath option in windows .. But here i want to do that from java code .. not thru this dos command.. is there any java API's to do this ??

Hey its possible ..
File afile = new File (MyJarName);
URL rl = new URL (afile.toURL().toString());
URL [] ury = new URL [] {rl};
URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Class sysclass = URLClassLoader.class;
Method method = sysclass.getDeclaredMethod("addURL", new Class[]{rl.getClass()});
method.setAccessible(true);
method.invoke(sysloader, new Object[] {rl});
String Classpath = System.getProperty("java.class.path");
System.out.println("Before->"+Classpath);
Classpath = Classpath + System.getProperty("path.separator") + rl.toString();
System.setProperty("java.class.path", Classpath);
Classpath = System.getProperty("java.class.path");
System.out.println("After->"+Classpath);

Similar Messages

  • Can we set the dynamic data source when using getReportParameters() ?

    Hello!
    I have a report where one of its parameters refers to a list of values (LOVs). This list of values is an SQL Query type. When the data source used in the report is defined in the BI Publisher server, I'm able to get the report parameters using the getReportParameters() function in my application. However, if the data source is not defined the function throws an exception, which is understandable.
    I decided to dynamically set the data source so that even if the data source used by the report is not defined in the BI Publisher server, it still will be able to get the LOVs for the parameter. I tried setting the JDBCDataSource of the dynamicDataSource for the ReportRequest object that I passed to the getReportParameters() function. Please see the sample code below:
    reportRequest.dynamicDataSource = new BIP10.BIPDataSource();
    reportRequest.dynamicDataSource.JDBCDataSource = new BIP10.JDBCDataSource();
    setReportDataSource(reportRequest.dynamicDataSource.JDBCDataSource, connectstr, jdbc, dc); //function to set the values for JDBCDataSource object
    reportParams = webrs.getReportParameters(reportRequest, uid, pwd); //call the getReportParameters
    I was expecting this to work as this is what I did to dynamically set the data source before calling the runReport function. So, my question is -- can we set the dynamic data source when using getReportParameters() ? I tried this both in versions 10g and 11g. It does not seem to work on both versions.
    Regards,
    Stephanie

    report_id column of apex_application_page_ir_rpt can help us uniquely identify each saved report.
    We can assign this report_id value to a page item and this page item can be put in the Report ID Item text box of the Advanced section of the Report Attributes page of the IR.
    This should load the saved report identified by report_id and you can get rid of javascript
    Regards,
    Vishal
    http://obiee-oracledb.blogspot.com
    http://www.packtpub.com/oracle-apex-4-2-reporting/book
    Kindly mark the reply as helpful/correct if it solves your problem

  • How can I set up dynamic parameters in a CMC schedule?

    Just need some help to set-up a month-end schedule in CMC (Central Management Console ).
    The schedule will contain a number on Crystal reports. These report should be run for the month just gone. eg If the schedule is run on 30.09.14, I'd like the FROM Date in my reports to be set to 01.09.14 and the TO Date set to 30.09.14.
    Can the CMC schedule update the report parameters (prompts) based on the run-date? Eg is there something like TO DATE = @TODAY ?
    If this is not provided within CMC, can you suggest how it could be handled?
    Thanks, Derek

    Hi Derek,
    This requirement is dependent to backend or universe.
    What is your backend database ?
    If it is SAP BW ,then in BEx we can create customer exits which makes report refresh for current month.
    If it is RDBMS  and you want to provide prompt in report ,then we need to create @Prompt in universe.
    Dave’s Adventures in Business Intelligence » Dynamic Dates Part III: Monthly Date Ranges
    if prompt is not required then create a condition in universe to run the report always for current month
    Ex: With SQL server , derive month from date
    upper(CONVERT(varchar(3),ADS_EVENT.Start_Time,7))
    condition
    @Select(Time\Month) = upper(convert(varchar(3),sysdatetime(),107))

  • Can I set classpath for OAS 10g?

    Hi,<br>
    <br>
    I have OAS on my workstation. Here are the details.<br>
    Server : Oracle Application Server 10g Release 3 <br>
    Version : 10.1.3.1.0 SOA4<br>
    Build : 061008.0900.00025<br>
    Platform : Windows XP - SP2<br>
    <br>
    I want to set an explicit classpath for complete OAS 10g as such and not to an individual oc4j application. Will I be able to do it?<br>
    I saw the System Properties after my server started.<br>
    It has a name-value pair as "java.class.path oc4j.jar".<br>
    So, I assume all my classpath settings (done thru Environment Variables from My Computer) are lost.?<br> I want to set it explicitly during the server startup itself. Can I do that?<br>
    I tried setting below in the opmn.xml <br>
    <process-set id="ASG" numprocs="1"><br>
         <module-data>          <br>                         <category id="start-parameters">     <br>               <data id="start-executable" value="C:\Oracle\product\10.1.3.1\OracleAS_1\jdk\bin\java"/>     <br>               <data id="start-args" value="-classpath C:\abc\properties\"/><br>
    I appended my properties folder after all the jar files present in that tag.<br>
    But its not loading any of my properties files.<br>
    <br>
    Can someone please help me out.<br>
    <br>
    Regards,<br>
    <br>
    Prashanth Babu.

    No, the iPad does not support multiple user accounts or preferences.

  • How can i set the dynamic text box to show variable value?

    In AS2, I can make a dynamic text box set a var name, when i
    use button set/change the var value, this textbox can show the
    value also.
    but In AS3, dynamic text box can't add var name. than how can
    i do it now?

    Set an instance name for the dynamic textfield. Then, to
    populate the textfield with the value of a variable, use:
    textFieldInstanceName.text = variableName

  • Can't set classpath or classloader for JavaCompiler!

    I have a class that I load using my own class loader. I know the class is loaded because I can instantiate it using reflection.
    Then, in my code I try to compile a source file which references (via import) the class I loaded, and I get a package does not exist error on the compile.
    I have tried everything I could think of. Currently, I'm doing this (read the comments):
            StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
            // trying to force the filemanager to use my class loader when resolving class paths... doesn't ever get called
            // except when loading annotation processors, though!!!
            ForwardingJavaFileManager<JavaFileManager> ffm = new ForwardingJavaFileManager<JavaFileManager>(fileManager)
                @Override
                public ClassLoader getClassLoader(Location location)
                    if (location == StandardLocation.CLASS_PATH)
                        return serviceClassLoader;
                    return super.getClassLoader(location);
                // This returns a list of File objects which were loaded in my class loader.
                // The File objects are created from the URL's I load in the class loader, and have the form:
                // "C:/Some/Path/To/File.jar"
                List<File> compileClassPath = serviceClassLoader.getClassPathFiles();
                // Adding the bin directory which contains the .class files of my app (in Eclipse)
                compileClassPath.add(new File("./bin"));
                // Attempt to add the bin dir with the .class files from another project - this is where the classes are that are failing to load
                compileClassPath.add(new File("C:/Documents%20and%20Settings/David/workspace/CoreServices/bin/"));
      fileManager.setLocation(StandardLocation.CLASS_PATH, compileClassPath);The output I'm seeing includes:
    CentralLoggingService_CentralLogService_Listener.java:5: package com.dave.service.logging does not exist
    import com.dave.service.logging.CentralLoggingService;
                                     ^
    CentralLoggingService_CentralLogService_Listener.java:7: cannot find symbol
    symbol: class CentralLogService
    public class CentralLoggingService_CentralLogService_Listener implements MessageListener<CentralLogService>So, basically, I need to know how to either:
    1) Set the class path for the JavaCompiler so that it will load classes that are required by the source being compiled, or...
    2) Set the classloader the JavaCompiler uses to resolve those classes.
    I've tried everything I could think of, even reading through the compiler source, and nothing has worked yet.
    Can anyone help?!?

    Hi,
    I am not sure but the argument to new File() looks dubious to me.
    You seem to be mixing URL and filename syntax.
    What does this do?
    class FileTest {
        public static void main(String[] args) {
            system.out.println(new File("C:/Documents%20and%20Settings/David/workspace/CoreServices/bin/").exists());
    }if its false then that directory doesn't exist.
    I would use backslashes (don't forget to escape them) and spaces, and no trailing path separator - like this
    class FileTest {
        public static void main(String[] args) {
            system.out.println(new File("C:\\Documents and Settings\\David\\workspace\\CoreServices\\bin").exists());
    }Play around with that till you can create a File object that exists and isDirectory().
    When I have done this in the past, I have used the existing classpath to set the classpath for invoking the compiler. For example this snippet from the hickory project at [https://hickory.dev.java.net/source/browse/hickory/trunk/code/src/net/java/dev/hickory/testing/Compilation.java?rev=11&view=markup|https://hickory.dev.java.net/source/browse/hickory/trunk/code/src/net/java/dev/hickory/testing/Compilation.java?rev=11&view=markup]
    List<String> optionList = new ArrayList<String>();
    optionList.addAll(Arrays.asList("-classpath",System.getProperty("java.class.path")));
    optionList.addAll(Arrays.asList(options));
    JavaCompiler.CompilationTask task = compiler.getTask(out,jfm,diagnostics,optionList,null,jfos);An advantage of that technique is that you don't have the path hard coded in the program. Useful if someone else wants to run it.
    In fact, you might find it useful to use the hickory testing package which provides an abstraction over the compiler API. See the javadoc starting here
    [https://hickory.dev.java.net/nonav/apidocs/index.html?net/java/dev/hickory/testing/Compilation.html|https://hickory.dev.java.net/nonav/apidocs/index.html?net/java/dev/hickory/testing/Compilation.html]
    Bruce

  • Please help - Can't set classpath on RedHat with jdk 1.3.1

    I'm trying to run an app and having lots of trouble with setting the classpath. I wouldn't even mind setting it on boot up. The only way I've gotten it to work was to manually type "export CLASSPATH=/usr/[the rest of it]" Can someone help?
    Here's what I've tried:
    edited rc.sysinit and added the following lines:
    # Set the classpath
    CLASSPATH=/usr/stoneware/config:/usr/stoneware/bin:/usr/stoneware/bin/gnujsp.jar:/usr/stoneware/bin/ProxyServlet.jar:/usr/stoneware/bin/jnet.jar:/usr/stoneware/bin/jcert.jar:/usr/stoneware/bin/jsse.jar:/usr/stoneware/bin/stoneware.jar:/usr/stoneware/bin/StonewareClient.jar:/usr/stoneware/bin/com.mortbay.jetty.jar:/usr/stoneware/bin/javax.servlet.jar:/usr/stoneware/bin/openxml-1.2.jar
    export CLASSPATH
    I've also tried setting from a .sh file using -classpath like this:
    /usr/java/jdk1.3.1_01/bin/java -ms16mb -classpath=/usr/stoneware/config:/usr/stoneware/bin:/usr/stoneware/bin/gnujsp.jar:/usr/stoneware/bin/ProxyServlet.jar:/usr/stoneware/bin/jnet.jar:/usr/stoneware/bin/jcert.jar:/usr/stoneware/bin/jsse.jar:/usr/stoneware/bin/stoneware.jar:/usr/stoneware/bin/StonewareClient.jar:/usr/stoneware/bin/com.mortbay.jetty.jar:/usr/stoneware/bin/javax.servlet.jar:/usr/stoneware/bin/openxml-1.2.jar -DStoneware.client.config=StonewareRelay.cfg com.stoneware.server.StonewareRelay
    And I've tried this:
    export CLASSPATH=/usr/stoneware/config:/usr/stoneware/bin:/usr/stoneware/bin/gnujsp.jar:/usr/stoneware/bin/ProxyServlet.jar:/usr/stoneware/bin/jnet.jar:/usr/stoneware/bin/jcert.jar:/usr/stoneware/bin/jsse.jar:/usr/stoneware/bin/stoneware.jar:/usr/stoneware/bin/StonewareClient.jar:/usr/stoneware/bin/com.mortbay.jetty.jar:/usr/stoneware/bin/javax.servlet.jar:/usr/stoneware/bin/openxml-1.2.jar
    /usr/java/jdk1.3.1_01/bin/java -ms16mb -DStoneware.client.config=StonewareRelay.cfg com.stoneware.server.StonewareRelay
    Please keep in mind the word wraps. The "-" you see is not really by itself, the text got wrapped.
    Thanks,
    James

    The way I usually set the CLASSPATH and PATH in Linux (RedHat specifically) is to edit the .bash_profile file in your home directory (/home/username/.bash_profile) and include them there. This will cause your CLASSPATH and PATH to be set everytime you run bash (if you want details on why, their is documentation on it). Your .bash_profile will usually have a PATH already so you can just add to it. Make sure when you add CLASSPATH to also add that to the EXPORT line at the bottom as it is easy to forget. That should work. The way you are saying to do it should work as well, I am not quite sure what you are having problems with but I have used the above method on over 20 machines and it has worked every time so far.
    Hope this helps.
    Will

  • Setting classpath dynamically

    Suppose an java application is already running. I want to take an instance of a class which is not within the classpath from the running application. Is there a way to do it.How to set the classpath to the started jvm.
    Thanx in advance
    S.Arun

    You need to load the class by your own, using a classloader. URLClassLoader is probably what you are looking for.
    Thomas

  • How to set classpath from java class ??

    I have tried to use System.setProperty("java.class.path", "my class path string ") to set classpath dynamically. But it is not working. How to set it dynamically from java class ?? Thanks , gary

    Look into the java.net.URLClassLoader. You can't set the classpath after the fact but you can specify URL's that will checked when you try to load a class with that loader.

  • C:set with dynamic variable name

    Hello,
    we have a litte market system.
    we iterate over the articles to display them on a page
    foreach article type we have to include a popup, but only once foreach article type.
    So if we have more than one article of the same type, the popup should be included only one time.
    <c:forEach var="article" items="#{MyArticleController.entities}">
        <c:if test="${requestScope[article.dtype] != true}">
            <!-- <ui:include src="/market/details/#{article.dtype}.xhtml"/>  -->          
            <c:set scope="request" var="${article.dtype}" value="1" />
        </c:if>
        <!-- <ui:include src="/market/preview/#{article.dtype}.xhtml"/>-->
    </c:forEach>I think the line with the c:set seems to be the problem.
    How can I solve this problem. How can I set a dynamic value and test against it later?
    Thanks
    Dirk

    You were close with your first example.
    However as noted, the <c:set> tag doesn't accept a dynamic expression for the "var" attribute.
    Suggested alternative: instead of using request attributes, have a seperate map
    <jsp:useBean id="articleTypeUsed" class="java.util.HashMap"/>
    <c:forEach var="article" items="#{MyArticleController.entities}">
        <c:if test="${not empty articleTypeUsed[article.dtype]}">
            <!-- <ui:include src="/market/details/#{article.dtype}.xhtml"/>  -->          
            <c:set target="${articleTypeUsed}" property="${article.dtype}" value="1" />
        </c:if>
        <!-- <ui:include src="/market/preview/#{article.dtype}.xhtml"/>-->
    </c:forEach>That should solve your issue with translating this java code into jstl.
    Whether the mix of JSTL and JSF/ui will work well together is a completely seperate issue, and one I can't really help with.

  • How to use jar files without setting classpath

    Hi,
    I have a situvation, I can not set classpath, but i have to use jar files, how can I do that.

    URL[] urls = new URL[]{pathToJar, pathToAnotherJar, ...};
    URLClassLoader urlc = new URLClassLoader(urls);
    Now load classes within the jars loaded by the urlc classloader as needed. This is a limited approach, you can mostly use interfaces to work with classes loaded by the custom loader instance above and your existing classes.

  • Set Classpath during runtime

    How can we set classpath to a .jar file during runtime. Is it possible to set classpath not other than editing a .bat file or by manually editing the global variables list????

    You need to implement you own Class Loader if you want to load a jar at runtime. Why would you like to do that in AS?

  • How can we set the column size and height dynamically

    Hi All,
    I have a requirement where i am designing rtf for excel output.Here i have a column where the height of that particular column must get reset dynamically according to the data that's getting populated.
    Thankq in advance.

    I had the same problem and I finally found that you can't set a form bean.
    There is no methods to do this.
    The only way is to make it a dynamic form bean, but i haven't investigated it.
    Now I use normal beans to move data between pages.
    Sorry if it's not what you want. If you have another solution let me know.

  • Can't compile Servlet program(error in setting classpath in XP)

    I encountered a similar problem as 'hereispaddy'.
    "I have recently written a servlet program. When I compile the program (let's say "HelloWorld.java"), I've got the following error message:
    package javax.servlet does not exist
    I've download the class files and set the classpath already. Have I missed anything? "
    i would like to ask, how to set the following in Windows XP:
    set CATALINE_HOME=C:\PROGRA~1\APACHE~1.0
    set CLASSPATH=.;%CATALINE_HOME%\COMMON\LIB\SERVLET.JAR;C:\JDK1.4\BIN;
    *ive tried in control panel->system->advanced->environment variables->
    variable name:CATALINE_HOME
    variable value:C:\Program Files\Apache Tomcat4.0 (and)
    variable name:CLASSPATH
    variable value:.;%CATALINE_HOME%\common\lib\servlet.jar;C:\jdk1.4\bin
    but failed!
    Could anyone kindly tell me what's wrong with my setting?
    Thx a lot!!!

    Does Tomcat work? Can run the examples on the home page?
    The only suggestion I have at this point is to get rid of the spaces in
    C:\Program Files\Apache Tomcat4.0
    But I am still in Win98 , so I am just guessing.

  • Can not set "Remove Panel" to "No" for dynamic VI

    In the VI Settings tab of the Application Builder, has no row for my dynamic VI. How to add this row for my dynamic VI.

    Are you sure that you added the dynamic VI on the Source File tab? I can't reproduce the problem where the dynamic VI doesn't show up in the VI Settings but it is possible that you can't set Remove Panel because of settings in VI Properties.

Maybe you are looking for