Dynamically Create and Compile Java Classes

Hi,
I have a requirement to dynamically create and compile Java classes and would like some advice on the best method to do so.
Basically the project I am working on involves creating "Factors". Factors are items that have both attributes and weights so for example Factor A could have attribute B with weight 0.76, and attribute C with weight 1.33. There are a number of methods common to all factors such as calculateTotal, identify etc etc.
At the moment the application has 5 factors, but there is a requirement to dynamically add and remove factors on the fly.
I current solution I have been considering is using XML to describe the new class, build up the class and compile it; something along the lines of what is descibed at
http://www.javaworld.com/javaworld/jw-02-2002/jw-0201-xslt_p.html
however i would like to consider all options.
Any help with this is greatly appreciated.

You want to dynamically create and compile Java classes.
I would try the following:
(1) Write the Source code of the new class into a text file with the name MyNewClass.java
(2) compile this new .java-file with Runtime r = getRuntime();
try {
    r.exec ("javac MyNewClass.java");
} catch (IOException e) {
    System.out.println("ooops " + e.getMessage());
} (3) somehow try to load that new class, maybe using ClassLoader cl = ClassLoader.getSystemClassLoader();
cl.loadClass("MyNewClass");

Similar Messages

  • Compiling and putting java classes in database schema

    hi..good evening to all...
    I have total 7 java classes which i have to compile and put in the database schema. those 7 classes are interdependent on each other thats why there is a particular order of execution.
    i want to compile and put them in the schema thorugh the command line.
    i have tried doing this one by one by executing the following command in cmd...
    D:\>loadjava -u username/password@sid -v -resolve javaclassname.java
    then its working fine..
    But i have to do this in one time i.e i have to compile and put all the 7 classes in schema by a single command.
    Thats why i have put all the 7 classes one by one in the required order...save the file as 'java_sources.java' and then run the following command...
    D:\>loadjava -u username/password@sid -v -resolve java_sources.java
    but it is not working... :(
    please help...thanks in advance

    Hi,
    It is not required to load one by one class files into the schema. Can create a jar file for all the class files and load the jar file using the '-o' option in loadjava
    eg:
    loadjava -u username/password@sid -v -r -o jar_file_name.jarI hope you might use any IDE to develop the java class files. All the IDE have option to develop jar file if not get oracle JDeveloper for easy option.
    Check the version of jdk used in your oracle server and use appropiate version of Jdeveloepr and compile the classes.
    If your class files use any builtin library jar files those also need to be loaded.
    As thomaso said if pasted with errors can resovle easier
    NB:
    http://download.oracle.com/docs/cd/B10500_01/java.920/a96659/02_load.htm

  • Ant or what tool to compile Java Classes

    For the past year I have been using Windows command window to compile Java Classes for my Servlets, Java Beans and Helper classes. I use Cold Fusion studio as my IDE for creating the Java classes. All of my Web Applications use MVC for Forms feeding small databases and I only have around 7 to 10 class files per Web application.
    Should I start to use Ant and/or what is recommended so I can keep up with current technology instead of using Windows Command Window to compile my Java classes?

    Try the following link.
    https://www.sdn.sap.com/irj/sdn/downloaditem?rid=/library/uuid/cfc19866-0401-0010-35b2-dc8158247fb6
    The download in the above link has NWDS and portal as well. Unzip the file and install NWDS studio.

  • Difference between a java program and a java class

    Hi there,
    What is the difference between a java program and a java class?

    HI,
    A java class is an object - described in a .class file - which has been given properties and behaviours and which can be instantiated in a program.
    A java program( application ) consists of at least one class (one of which must be declared public) and which executes its main() method ( of the public class ) when it is started.
    Every program is a class but not every class is a program.
    Examples:
    A java program
    // this simple program will print out the first command line argument you put
    // in after calling : java ScreenWriter "arguments"
    class ScreenWriter
    public static void main( String [] args )
    if( args.length > 0 )
    System.out.println( args[0] );
    A java class
    //the Math class is already defined in the java.lang package
    //and contains a constant for PI
    //So I can include the Math class with the PI constant in my simple program
    //and now I have a program that involves my ScreenWriter class and the Math class too.
    class ScreenWriter
    public static void main( String [] args )
    if( args.length > 0 )
    System.out.println( args[0] );
    System.out.println( "The value of Pi is: " + Math.PI );
    When you see package and import declarations at the start of a program they are there to ensure the compiler knows which classes are used in the program.
    Hope that helps,
    Terry

  • Dynamically create and remove TEXT items in forms

    Hi Guys,
    Is there a way to dynamically create and remove TEXT items in form. For example I have the EMP and DEPT table and when
    I select the EMP table name from the LOV, rows of the EMP table with column name and data should get displayed on the screen and likewise a similar action for DEPT table and
    so on. I have about 90 tables from where data could be required to view and edit. They all have varying number of columns.
    Any suggestions ?
    Thanks
    KMD
    null

    Use OLE concept of developer and map Excel as an object
    Nadeem
    null

  • Suffering an complie error when trying to compile java class in EBS11i

    Hi,
    When I trying to compile java classes with which imported the HttpServletResponse class, will get the follow error message:
    package javax.servlet does not exist
    cannot resolve symbol
    symbol : class HttpServletResponse
    It seems the javax.servlet package is not included in the classpath. But I checked the $CLASSPATH, it seems no problem.
    echo $CLASSPATH
    /u02/applvis/viscomn/util/java/1.4/j2sdk1.4.2_04/lib/tools.jar:/u02/applvis/viscomn/util/java/1.4/j2sdk1.4.2_04/lib/dt.jar:/u02/applvis/viscomn/util/java/1.4/j2sdk1.4.2_04/jre/lib/charsets.jar:/u02/applvis/viscomn/util/java/1.4/j2sdk1.4.2_04/jre/lib/rt.jar:/u02/applvis/viscomn/java/appsborg2.zip:/u02/applvis/visora/8.0.6/forms60/java:/u02/applvis/viscomn/java
    Does anyone know the reason?
    environment: ebs 11i
    Thanks&Regards,
    Xiaofeng

    resolved this issue.
    1. Edit $APPL_TOP/admin/adovars.env file -
    Add the following jar files to the AF_CLASSPATH line -
    Full path of /...../iAS/Apache/Jsdk/lib/jsdk.jar
    Full path of /...../iAS/Apache/Jserv/libexec/ApacheJServ.jar
    2. Bounce the concurrent manager in order to have the changes take effect.

  • TableFilter and TableSorter Java Classes

    Does anybody has link to TableFilter and TableSorter java classes for CE 7.11 Tables?
    Thanks

    Hi Michael Vstling,
    Did you try the java classes library (SDOAPI) that can be downloaded from OTN?
    It may provide you with a better alternative when manipulating geometries in the Java space. There is an adapter in SDOAPI which can convert a JDBC STRUCT object into Java Geometry object defined in SDOAPI, and vice versa.
    There are at least two ways in mixing PL/SQL and Java. The first one, as you mentioned, is to define your custom function in terms of PL/SQL and call it from within your Java program. With SDOAPI, you have the second option, which is to define your own functions in Java using SDOAPI and deploy them as Java stored procedures in db. You can then call them from within your PL/SQL code. In either way performance depends on a lot of things and generally it requires a "try and improve" approach.
    About JPublisher and sdo_ordinate_array it may not be a spatial related problem. Did you try search the Java-related forums first?
    LJ

  • Error while compiling java class (ora-29535 source requires recompilation)

    Hello. I`m new with oracle and i`m having a problem with java classes. Few days ago i loaded java classes (loadjava) from jar file(biojava3-structure-3.0.2.jar) and compiled ( everything compiled with status valid). Now i`m writing my own class and i can`t import classes from biojava3. I`m getting error:
    Projekt:7: cannot access org.biojava.bio.structure.Atom
    bad class file: null
    class file has wrong version 50.0, should be 49.0
    Please remove or make sure it appears in the correct subdirectory of the classpath.
    import org.biojava.bio.structure.Atom;
    I have tryed to change jdk version in netbeans from 1.7 to 1.6. I created java class in sql plus That still not resolved my problem.
    Please help me.

    consider posting in Java forum instead of Database forum
    https://forums.oracle.com/forums/category.jspa?categoryID=285

  • Compiling java classes from JDeveloper

    Hi guys... perhaps this thred need to be created in JDeveloper fourm, it so please let me know.
    I generated the classes from a web service which complie without errors and exedcute correctly. When trying to compile the main stub in Oracle database, I get an error "CONNOT RESOLVE SYMBOL" reviewing the java class, I see that extends the wrapper generated by Jdev. So I try to complie the extendable class, after trying to generate and compile it in the database, I get the error: "class$ is reserved for internal use" The code has the next line:
    static java.lang.Class class$(java.lang.String param1)
    Is this error launched from the oracle database? My guess is that maybe Im missing some library or something and thats why I can create the such Java Name procedures. But I will like if anyone could guide me through this exception.
    Thanks
    JP

    Do you have .jar (or the .class) files created after the compile from JDeveloper?
    If you do, you can load all of them using the command line utility loadjava:
    $ loadjava
    loadjava: Usage: loadjava [-definer] [-encoding encoding] [-force] [-genmissing] [-genmissingjar jar] [-grant grants] [-help] [-nousage] [-noverify] [-oci8] [-order] [-resolve] [-resolver resolver] [-schema schema] [-synonym] [-thin] [-tableschema schema] [-user user/password@database] [-verbose] classes..jars..resources..properties...
    $

  • Problem to compile .java class

    hi,
    i'm using/creating a package of classes....and as per my knowledge there is no need to write explicit import if u r importing/using an instance of class1 in other class2 in the same package.....
    I'm doing the same.....
    but the problem arrises here that....while compiling class2 the error occures..........
    D:\tomcat\webapps\Books\WEB-INF\classes\BookForm.java:6: cannot resolve symbol
    symbol : class Book
    location: class BookForm
         private Book book =new Book();
    why so????? as i have included the package in CLASSPATH also..........
    PLZ reply....
    .....Amita

    You don't need to import classes that are in the same package but they do need to be in the classpath. My guess is that you are compiling BookForm.java from the D:\tomcat\webapps\Books\WEB-INF\classes directory. Either add "D:\tomcat\webapps\Books\WEB-INF\classes" explicitly to your classpath or add a dot (".") to your classpath.

  • Need help with tomcat 5.5 and using java classes

    hey there,
    i am trying to set up tomcat 5.5 on my computer at home and have sucessfully done so. i have been trying to use Java classes inside my JSP files however tomcat thows an internal servlet error as follows:
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 144 in the jsp file: /order.jsp
    Generated servlet error:
    ProductList cannot be resolved to a type
    An error occurred at line: 144 in the jsp file: /order.jsp
    Generated servlet error:
    ProductList cannot be resolved to a type
    An error occurred at line: 144 in the jsp file: /order.jsp
    Generated servlet error:
    Product cannot be resolved to a type
    i have the classes located as the setup tutorial recommends (root/WEB-INF/classes/) and still nothing works. i would appreciate any help anyone can give.
    thanks,

    Which tutorial are you following?
    As of java1.4, all classes must be in packages for them to work in Tomcat. This means your beans and servlets too.
    Put your beans in a package, and then recompile them, and put them in the right place.
    eg
    package com.mypackage
    public class MyClass ...
    once compiled would go into WEB-INF/classes/com/mypackage/MyClass.class
    Are you using Product and ProductList classes in scriptlet code?
    Have you imported them with a page directive
    <%@ page import="com.mypackage.Product, com.mypackage.ProductList" %> ?

  • Compiling java classes into dll

    Hi,
    Just trying to find out is there anyway I can compile the java classes into dll?
    If I am to use JNI and C++, will the dll compiled be able to work well in a platform that does not have JVM?
    Thank you.

    Hi,
    Just trying to find out is there anyway I can
    an compile the java classes into dll?
    No, but you can start the jvm and run your main class from a dll using jni. And, if you do that, you'll of course need a JVM on the client that'll be running your code.

  • Compile Java class

    Hi everyone,
    I am new to WSAD env. Can anybody tell me "How I can compile a Java class using WSAD?".After compilation, where does it(the dir structure and location) keep the .class file?
    Thanks in advance

    In a project I have in WSAD Integration Edition 5.1, a .java file is compiled to a .class file in
    /WebContent/WEB-INF/classes/
    I'm not sure if that was your question if it relates to JavaServer Pages

  • Is it possible to get the Source from the Compiled Java Class File?

    Hello All,
    I wrote a java file which uses Java Swing to crea a GUI.I have also compiled the jave file.
    The problem now is that i've made many changes and compiled it many times.Now suddenly due to some problem,the contents of tha Java file have been deleted and it shows 0 bytes.
    Is there any way to recover my Java source file from the Class file?I would be thankful to anyone who can help me out on this.
    Thanks in Advance,
    Regards,
    Vijayakannan

    Yes and no, you can reverse engineer it to an extent, it wont look exactly like your original source though, it'll be full of commented out bytecode bits etc. As its your own code though you've got the best chance of deciphering it. Go to somewhere like www.tucows.com to download the software for doing it.
    ARB

  • Unable to compile java classes in NWDS- "JSPDynPage cannot be resolved "

    Hi All,
    I am trying to write small JSPDynaPage when i am getting following complilation error in my Java classess.
    1) "PageProcessorComponent cannot be resolved or is not a valid superclass"
    2) "JSPDynPage cannot be resolved or is not a valid superclass"
    I did check for the existance of
    com.sap.portal.htmlbbridge.jar & prtapi.jar which is present in my C:\NetWeaverDevStudio\eclipse\plugins\com.sap.ep.applicationDevelopment and
    ECLIPSE_HOME=C:/NetWeaverDevStudio/eclipse but for some reason i am unable to compile my classes. Please help me to resolve this issue.
    Thanks,
    Manju

    Try the following link.
    https://www.sdn.sap.com/irj/sdn/downloaditem?rid=/library/uuid/cfc19866-0401-0010-35b2-dc8158247fb6
    The download in the above link has NWDS and portal as well. Unzip the file and install NWDS studio.

Maybe you are looking for

  • Hp 6500A plus wireless printer = hp eprint not working with pdf

    I have a brand new HP 6500 A plus wireless printer. I tried to print using hp eprint center by sending a pdf as attachement to printers email address. But the printer doesn't like the pdf and prints a error page instead with below message. ======= Pl

  • Different print mode behavior between 1.5 and 1.6.

    We recently upgraded to 1.6. There seems to be some behavior that is working differently now(no other changes made). Here is the situation: I have a tabular report of projects with a link column that allows the user to go to a page of each project's

  • ITunes Library File in Documents Folder? Mac problem not Windows

    I am confused! I have several very small iTunes Library folders in my Music/iTunes file which date back to iTunes 4. Some of the files are less than 10kb. I also have a folder titled Previous Libraries in my Music/iTunes file which has two Libraries

  • Image capture NOT THERE!

    Image capture has been recommended in this forum for downloading videos from my Digital camera. Alas, it´s not there! I have installed Mac OS X 10.4.5. Can anyone help?

  • How can I download a song without automatically launching/putting it into iTunes?

    How can I download a song without automatically launching/putting it into iTunes? I download my royalty-free music from VideoBlocks and it automatically launches iTunes and plays the song in iTunes. I just want to save it to a location without going