How can I load my java class dynamically ???

Hi guyz !
Please look on my problem:
1. I write code under Windows.
2. I have file testcls1.java with class by name 'TestCls1'. /package 'hs0'/
3. I try to use method Class.forName.
4. File on disk is "c:/shttpsrv0/SrvFiles/java/testcls1.java".
5. I get exception ClassNotFound.
Question: what is right way to write first parameter for method ???
Thanx in advance !

Hi guyz !
Please look on my problem:
1. I write code under Windows.
2. I have file testcls1.java with class by name
'TestCls1'. /package 'hs0'/
3. I try to use method Class.forName.
4. File on disk is
"c:/shttpsrv0/SrvFiles/java/testcls1.java".
5. I get exception ClassNotFound.
Question: what is right way to write first parameter
for method ???Class.forName can use *.class files only. If you have *.java file, you have to compile it first. Moreover, Class.forName uses CLASSPATH. If you want to provide the exact location of *.class file, try to use URLClassLoader.

Similar Messages

  • How can i run a java class file from shell?

    Hi all,
    I've a .class file named "File" that contains Main method, it is in the package "File2".
    How can I run it by shell command?
    PS: "java -cp . file" doesn't work it launch->
    Exception in thread "main" java.lang.NoClassDefFoundError: File2/File (wrong name: File2/File)
    Thanks in advance.

    Just to understand: is File2 ar jar archive or not? If it is a jar archive, have you tried open File2.jar? If File2 is a directory within the current directory, have you tried java -cp . File2/File? I just tested with a set of classes and it works... Let me be precise:
    * Let us imagine you are working in a directory whole path is PathToDir/
    * in this directory you have the classes put in a directory called File2
    * in order to launch File.class then you would have to invoke :
    cd PathToDir/ (just to be sure)
    java -cp . File2/File
    *if you were to do the following then you would have the problem you describe
    cd PathToDir/File2/
    java -cp . File

  • How can I call a java class from within my program?

    I was wondering if there's a platform independent way to call a java class from my program.

    Here's my scenario. I'm working on a platform independent, feature rich, object-oriented command prompt program. The way I'm designing it is that users can drop classes they write into my bin directory and gain access to the class through my program. For example, they drop a class named Network.class in the bin directory. They would type Network network at my command prompt and gain access to all the methods available in that class. They can then type system.echo network.ipaddress() at my prompt and get the system's ip address. I have it designed that there's a server running in the background and the clients connect to my port. Once connected the end-user can enter their user name and password and gain access to the system. When they type a command they actually call another java program which connects to my server using a seperate thread. They can then communicate back and forth. I have it set that everything has a process id and it's used to keep track of who called what program. Once the program is done it disconnects and closes. Rather than getting into the nitty gritty (I didn't want to get into heavy detail, I know how everything will work) I'm really interested in finding out how I can call a java program from my program. I don't want it to be part of the app in any way.

  • How can I execute a java class with arguments from an air application built from mxml?

    I have an mxml application. It has a button, and when that button select event occurs, I want my mxml air app to pass arguments to a java class I have built, which resides in a package path on my system. I need to be able to pass several arguments to my java method from my mxml call. How do I do this, and what config files are necessary? For the simple task I want to engineer, can you show me an example of a properly configured config file? My java class has been executed at the command line in the past as follows:
    java -cp %CP% com.abc.prism.queue.EmitMessage XYZ "my message text" 192.12.13.14 5672
    where %CP% is an env variable that tells my class the classpath it runs with, and XYZ, "my message text", the IP address, and the port are the arguments I must pass from mxml to my java class. How do I accomplish this?
    How do I make known to the java class I call from mxml the %CP% class path? It tells my java class where to find various rabbitMQ jars.

    Hi,
    You need to use Integration technology like BlazeDS or LCDS.

  • How can i mention a java class in the form's action=" ...."  in jsp

    if i am not using struts frame work, how can i call?
    i am not using any of the frame work.
    for example.
    i am searching for a customer name from a database
    i have coded the form fields in jsp
    as
    <%@page session="true"%>
    <%@page errorPage="ErrorPage.jsp"%>
    <%@page import="com.krysl.model.*"%>
    <jsp:useBean id="model" scope="session" class="com.krysl.model.webmodel"/>
    <html>
    <head>
    <title>Customer Seach</title>
    <jsp:include page="SetBaseURL.jsp" flush="false"/>
    <link rel="stylesheet" href="http://forums.sureshkumar.net/style.css">
    </head>
    <body>
    <jsp:include page="Banner.jsp" flush="false"/>
    <h1>Customer Search</h1
    <form method="POST" action=".......................">
    <b>Customer Name</b>
    <input type="TEXT" name="customerSearchArgument" size="20">
    <input type="submit" value="search">
    </form>
    </body>
    </html>
    this "customerSearchArgument" will receive a class method
    package com.krysl.controller;
    import java.io.*;
    import java.sql.SQLException;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import com.krysl.model.*;
    * @author dsdc
    public class customersearchaction extends Action
    public void run() throws ServletException, IOException
    String arg = request.getParameter("customerSearchArgument");
    if(arg != null)
    arg = arg.trim();
    if(!arg.equals(""))
    try
    model.customerSearch(arg);
    catch(SQLException e)
    throw new ServletException(e.getMessage());
    final String next = "/CustomersList.jsp";
    RequestDispatcher rd = application.getRequestDispatcher(next);
    if(rd == null)
    throw new ServletException("Could not find" + next);
    rd.forward(request, response);
    All other database connections and related things i coded in
    some other classes webmodel, model, controller servlets etc....
    in the above class the model.customerseach(arg);
    will do all the searching.
    my doubt is how to call this method in that action="" of jsp
    i tried as action="com.krysl.model.customersearch"
    action="com/krysl/model/customersearch"
    its not working
    please letme kno
    urget
    thank you

    Hi.
    go to otn.oracle.com/products/forms and get infromation about PJC and JavaBeans in Forms. The keyfilter example is available as sample as well. However, the link temporarily doesn't work
    All Forms demos and code sources: http://download.oracle.com/otndocs/demos/Forms_Demos_10gr2.zip
    Frank

  • How can i get all java class names from a package using reflection?

    hi,
    can i get all classes name from a package using reflection or any other way?
    If possible plz give the code with example.

    You can't, because the package doesn't have to be on the local machine. It could be ANYWHERE.
    For example, via a URLClassLoader (ie from the internet) I could load a class called:
    com.paperstack.NobodyExpectsTheSpanishInquisitionI haven't written it yet. But I might tomorrow. How are you going to determine if that class is in the package?
    This subject comes up a lot. If you want to do something a bit like what you're asking for (but not quite) there are plenty of threads on the subject. Use google and/or the forum search facility to find them.
    But the answer to your question, as you asked it, is "you can't do that".

  • How can we call one java class in another java class?

    Hi all,
    My problem is ,
    one java code creates a file i have to send that file through email as an attachment here i wrote a java code to send a mail with attachment
    can any one help me how i can implement this. my idea is to write a send mail function in 1st java code which creates the file
    Is this a better idea ???plz suggest me.

    Hi all,
    My problem is ,
    one java code creates a file i have to send that file
    through email as an attachment here i wrote a java
    code to send a mail with attachment
    can any one help me how i can implement this. my idea
    is to write a send mail function in 1st java code
    which creates the file
    Is this a better idea ???plz suggest me.may samaaj nahi atay

  • How can  I access my java class file in a .jar file ...PLz Help anyone!!

    Hi Folks,
    I am new in Java programming, have a .jar file that contains .java files that I want no access and use from another .java file. These files in the .jar file basically form a library thus have no main-method. However I can not declare an instance of the library (in the .jar file) and use it within my program.
    Plz help ...I have tried all I know in vain.
    Thanks.

    temba wrote:
    Hi Folks,
    I am new in Java programming, have a .jar file that contains .java files that I want no access and use from another .java file. These files in the .jar file basically form a library thus have no main-method. However I can not declare an instance of the library (in the .jar file) and use it within my program. You are making little sense. You can't instantiate .java files.
    Plz help ...I have tried all I know in vain.
    Thanks.Could you post WHAT you have tried and also post what error messages you received?

  • How to load a java class at server start-up

    Hi,
    I have one custome java class that is being referenced by all the applications deployed in OC4J container. How can I load that class automatically and be evailable in the path at server start-up time. Is there an option available to give the class name that also gets loaded automatically.
    Thanks

    To me, you have two mixed issues.
    1. OC4J supports a startup/shutdown model where a named class will be invoked when the container is started (or stopped).
    This is described in the doc here:
    http://download-west.oracle.com/docs/cd/B32110_01/web.1013/b28952/startclas.htm#CIHECEIB
    Note that this specifically calls the methods that are implemented from the respective OC4JShutdown and OC4JStartup interfaces -- the class that is instantiated and called here is not available to all other applications by default. This is more to suit the need where something needs to be done when the container is started/stopped.
    2 The next option is where you just want to make a class available to all applications deployed to the container. For this we provide the shared-library mechanism. Using this you can either make use of the implicit global.libraries shared-lib in which you simply drop JAR files into the j2ee/home/applib directory whereupon the classes will become available by default to all applications. Or you can choose to install a shared-library that contains your specific classes (in a JAR file) and then import that into the default application whereupon the configuration will be inherited by all deployed applications.
    cheers
    -steve-

  • How to load a java class when application is at first time browsed.

    Hi
    How can i load a simple java class on application startup.
    For servlet it could be done using "load on startup" tag in web.xml
    but how could the same be achieved for a simple java class.
    Thanks

    Hi
    Code is given below....
    package com;
    import java.io.IOException;
    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class Test {
    Test()
         HttpServletRequest request=null;
         HttpServletResponse response=null;
         RequestDispatcher requestDispatcher = request.getRequestDispatcher("a.jsp");
         try {
              requestDispatcher.forward(request,response);
         } catch (ServletException e) {
              System.out.println("success");
              e.printStackTrace();
         } catch (IOException e) {
              System.out.println("success 1");
              e.printStackTrace();
         finally
              System.out.println("success 2");
         System.out.println("success 3");
    }Web.xml :
    <servlet>
            <servlet-name>simple</servlet-name>
            <servlet-class>com.Test</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
      <servlet-mapping>
          <servlet-name>simple</servlet-name>
          <url-pattern>/init.do</url-pattern>
        </servlet-mapping>Error Trace :
    org.apache.catalina.core.StandardContext loadOnStartup
    SEVERE: Servlet /DispatcherTest threw load() exception
    java.lang.IllegalAccessException: Class org.apache.catalina.core.StandardWrapper can not access a member of class com.Test with modifiers ""
         at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
         at java.lang.Class.newInstance0(Class.java:344)
         at java.lang.Class.newInstance(Class.java:303)
         at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1048)
         at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:925)
         at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3857)
         at org.apache.catalina.core.StandardContext.start(StandardContext.java:4118)
         at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1069)
         at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1162)
         at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:293)
         at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
         at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1304)
         at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1568)
         at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1577)
         at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1557)
         at java.lang.Thread.run(Thread.java:595)

  • How to invoke a java class dynamically?

    Hi all,
    In my usecase I need to invoke a java class dynamically using any of the components like Button or link in jdeveloper.
    How could we invoke a java class which has a main method in it dynamically.
    Kindly come up with your help.
    Thanks,
    Phani.

    public class BackingBean {
    public BackingBean() {
    super();
    public void cb3_action() {
    File fileObj = new File("C:\\Jdeveloper software\\new.doc");
    IDocument myDoc = new Document2004();
    myDoc.addEle(Heading2.with("===== Headings ======").create());
    myDoc.addEle(Paragraph.with("This doc has been generated by the unit test testJava2wordAllInOne() in the class DocumentTest2004Test.java.").create());
    Table tbl = new Table();
    tbl.addTableEle(TableEle.TH, "Name", "Number of gols", "Country");
    tbl.setRepeatTableHeaderOnEveryPage();
    tbl.addTableEle(TableEle.TD, "Arthur Friedenreich", "1329", "Brazil");
    tbl.addTableEle(TableEle.TD, "Pele", "1281", "Brazil");
    myDoc.addEle(tbl);
    PrintWriter writer = null;
    try {
    writer = new PrintWriter(fileObj);
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    String myWord = myDoc.getContent();
    writer.println(myWord);
    writer.close();
    Hi john,
    these are my Backing bean and action now at the run time when I am pressing a button which has to invoke cb3_action() method.
    When I am clicking the button at the runtime I am getting the below error
    Error 500--Internal Server Error
    javax.faces.el.EvaluationException: java.lang.NoClassDefFoundError: word/w2004/Document2004
         at org.apache.myfaces.trinidad.component.MethodExpressionMethodBinding.invoke(MethodExpressionMethodBinding.java:51)
         at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
         at org.apache.myfaces.trinidad.component.UIXCommand.broadcast(UIXCommand.java:190)
         at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:475)
    In the above code if you observe I have used "IDocument myDoc = new Document2004();" line. Here this Document2004 is a class which is in one of the external
    jar files. xstream-1.3.1.jar , java2word-3.0_2011Aug02.jar , log4j-1.2.15.jar .
    these are the jar files I found in net using which I can create a word file and add all the components like table and format the txt etc..
    These jar files works in Tomcat, Jboss ,Struts
    I can even run this class and got the file created.
    But when I try to bind the method in ADF i am getting the error mentioned above.
    Kindly help me on this. Sorry for posting similar question two times on the blog.
    Sorry again if this question is wierd.
    Thanks,
    Phani.

  • I am running 10.5.8, and just updated my java to java 5 update10. Now my firefox is missing the Java plugin, and I can't load any Java applet at all. When I try it with Safari, it hangs when certain Java applet loads. HELP!!!

    Suddenly my Java plugin is missing and i can't load any Java with Firefox at all, even though i have it enabled in the browser! i've tried loading in java embedding plugin, but it doesn't work. what should i do???

    It's not in Tools> Add-ons >plugins?  Should be Java Plug-in 2 for NPAPI browsers 13.5.0. What are you seeing there? I don't think it's called the embedding plugin any longer.
    Might try getting the Firefox 5 standalone application. Trash the current one and replace it. Doing this won't affect your Profile or any settings.
    http://www.mozilla.com/en-US/firefox/all.html
    If it's enabled, how can it be missing?
    If this doesn't work, ask here. No need to register. Make sure you put (Mac) in the title.
    http://forums.mozillazine.org/viewforum.php?f=38
    Message was edited by: WZZZ
    EDIT. Oops, may be different for 10.5.8. Was thinking recent Java update for 10.6. But try installing a new app anyway. In the past, this got me the latest Java plugin.

  • How can I use Seeburger java functions on SAP XI's user defined functions?

    Hi All,
    As my title implies; how can I use Seeburger java functions on SAP XI's user defined functions?  I've tried searching over the net in tutorials regarding this topic but I failed to find one; can someone provide me information regarding my question? thanks very much.
    best regards,
    Mike

    Hi Mike !
    You should check your documentation about which java classes you need to reference in the "import" section of your UDF. And also deploy the java classes into the java stack or include them as a imported archive in integration repository...it should be stated in the seeburger documentation.
    What kind of functions are you trying to use?
    Regards,
    Matias.

  • How can I share a *.java source file across multiple projects in NetBeans?

    I'm sure this simple and a pretty common operation but how can I share a *.java source file across multiple projects in NetBeans? Right now I keep cut, coping and pasting the same source file between multiple projects to re-use the same code. But I could I make this source file a library file or something like that so that I could access it from any project. I assume this would be a generic operation but I mentioned NetBeans for clarity. Thanks.

    fiebigc wrote:
    I know I mentioned NetBeans but I'm most interested in the generic method for creating a library of source files that I can call into whatever program I am developing. I've done such a thing in C using header files and such but I'm trying to get a direction on how this is accomplished in Java. I'm sorry if I could edit the title I would. If anyone wants to be specific about NetBeans I welcome that too.
    Edited by: fiebigc on Jun 20, 2008 5:57 PM
    >I know I mentioned NetBeans but I'm most interested in the generic method for creating a library of source files that I can call into whatever program I am developing. I've done such a thing in C using header files and such but I'm trying to get a direction on how this is accomplished in Java. I'm sorry if I could edit the title I would. If anyone wants to be specific about NetBeans I welcome that too.
    Edited by: fiebigc on Jun 20, 2008 5:57 PM
    Create a class library.
    Write your code, compile it to .class files, put those class files in a .jar file and include the jar file in the classpath whenever you want to compile a project against it.

  • How can I run a a class file on the Apache server?

    Hi Guys and Gurus,
    I am seeking some favor all of experienced gurus, i.e.
    How can I run a a class file on the Apache server?
    Actually, I want to extract some records from a MySQL Database running on Apache Server. I wrote a program just to select the columns and show them. It is now a Class file, Now how can I run this class file from the Server???
    Please advise...
    VJ

    cross posted
    http://forum.java.sun.com/thread.jsp?thread=299137&forum=31&message=1184025

Maybe you are looking for