Call apt inside a java class

Hi all,
Is it possible to call the Annotation Processing Tool inside a Java class ?
If yes, how to perform this call ?
Thanks.
Micka�l

Hello Micka�l,
Here is a test class for one of my apt processors.
https://rapt.dev.java.net/source/browse/rapt/test/net/java/dev/rapt/exploratory/mixin/TestMixins.java?rev=1.1&view=markup
The code to call apt is in the last method called "runApt". Note that this method takes the source code to be compiled as a String and writes it to a file, but YOU may not want to do that.
Oh, and if you try to understand the rest of the code, there is lots of source inside javadoc comments. Basically, each @LongString static String is initialized to the value of its javadoc comment. Which is cool for writing tests but really confusing if you are not aware of what is happening - and I was hoping to help you, not confuse you :)
Bruce

Similar Messages

  • Calling a servlet in java class

    Hello,
    I try to call a servlet from java class
    but is dose not work
    what should be the problem
       public void callServlet()
              try
                            // xxservlet is the servlet name
                   URL url = new URL("http://www.mydomain.com/xxservlet");
                   URLConnection hpCon = url.openConnection();
                   hpCon.setDoOutput(true);
                   OutputStreamWriter out = new OutputStreamWriter(hpCon.getOutputStream());
                   out.write("This Is a Test");
                   out.flush();
                   out.close();
              }catch(Exception ex){ex.printStackTrace();}     
    // My Servlet  is in package servlets
    public class XXServlet extends HttpServlet
        public void service(HttpServletRequest req, HttpServletResponse resp) {
            try {
                 ServletInputStream sin = req.getInputStream();
                 int len = req.getContentLength();
                    byte[] input = new byte[len];
                    ServletInputStream sin = req.getInputStream();
                   int c, count = 0 ;
                   while ((c = sin.read(input, count, input.length-count)) != -1) {
                       count +=c;
                  sin.close();
                  String inString = new String(input);
                  System.out.println("Servlet is running ...."+inString);
            } catch (IOException e) {
                try{
                    resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
                    resp.getWriter().print(e.getMessage());
                    resp.getWriter().close();
                } catch (IOException ioe) {
    // web.xml
    <servlet>
           <servlet-name>xxservlet</servlet-name>
           <servlet-class>servlets.XXServlet</servlet-class>
        </servlet>
       <servlet-mapping>
        <servlet-name>xxservlet</servlet-name>
        <url-pattern>/xxservlet</url-pattern>
      </servlet-mapping>
    }regards
    Edited by: the_Orient on Mar 30, 2009 3:16 AM

    I have start servlet from brwoser only to test that servlet works fine
    A gain what I need
    I want to call a servlet from a javs class
    URL url = new URL("http://www.mydomain.com/myservlet");
      URLConnection hpCon = url.openConnection();
      hpCon.setDoOutput(true);
      OutputStreamWriter out = new OutputStreamWriter(hpCon.getOutputStream());
      out.write("Hello Woprld");
      out.flush();
      out.close();// Servlet
    public void doGet(HttpServletRequest req, HttpServletResponse resp) {
            try {
                  String xp =req.getSession().getServletContext().getRealPath("/");
                  File f = new File(xp+"/students/info.txt");
                  f.createNewFile();
            } catch (IOException e) {
                try{
                    resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
                    resp.getWriter().print(e.getMessage());
                    resp.getWriter().close();
                } catch (IOException ioe) {
    problem file can not be created
        public void doPost(HttpServletRequest req, HttpServletResponse resp)
    }I hope that is clear

  • How to get the status of Javascript inside a java class

    Hi,
    Can anybody let me know the way by which I can get the status of Javascript (enabled/disabled) in browser inside a Java Class.
    I do have a trick -
    <input type="hidden" name="jstatus" value="disabled">
    <input type="submit" name="submit" onClick="doChecking()">
    <script language= javascript>
    function doChecking()
    document.form.jstatus.value = "enabled";
    submit();
    Now inside our java class we can check the value of "jstatus" if it is disabled then it is disabled else it is enabled.
    Ha ha wat a stupid trick...... ;-)
    Plz let me know a real approach to determine the Javascript status.
    Cheers !!!
    Irshad

    Actually, I don't think that trick is stupid at all. Javascript and Java are normally in no way related (javascript is just plain text content to your servlets / jsp's). So a good way of getting such information to your server is submitting it, like you do.
    Another possibility would be to do it with Ajax in the background, but that all depends on what you do with the information.

  • How to get caller principal in a Java class?

    I understand if I implement the web service with an EJB, I should be able to get
    the caller's principal using EJBContext. How do I get the caller's principal if
    I implement a web service with WL70 using a Java class?
    Thanks,
    - Hao

    Bruce, thank you for your response.
    However, the getCurrentUser() method does not seem to work. It throws an exception
    but I couldn't see what exception it throws. The documention also says that class
    and its methods are deprecated.
    Is there any other Weblobic class that is doing similar thing?
    - Hao
    "bruce leroy" <[email protected]> wrote:
    >
    i think you could use the getcurrentuser method
    http://e-docs.bea.com/wls/docs70/javadocs/weblogic/security/acl/Security.html#getCurrentUser()
    "Hao" <[email protected]> wrote:
    I understand if I implement the web service with an EJB, I should be
    able to get
    the caller's principal using EJBContext. How do I get the caller's principal
    if
    I implement a web service with WL70 using a Java class?
    Thanks,
    - Hao

  • Call Bean from normal java class

    Dear Friends,
    Is it ok to call an entity bean or session bean frm normal Java class.
    (Java class is in the same application as the beans).
    Is there a special way to lookup the beans from normal java classes.
    Thanking You,
    Chamal.

    it is ok and very commonly done.
    Note that the simple java program must be running in the same local network. You cannot have the java program and EJBs distributed over internet. (I m not certain of it, but mostly I shoudl be correct. If you have the resources, try it out and let me know)
    In most of the cases, EJBs are called by
    1. A servlet
    2. Another EJB
    3. a simple java program.
    In the first 2 cases, you can go for Local Interfaces (more so in the second case than the first). The reason being that the the client and server will be in the same JVM (typically the Application server). Thus, in the first case, if the Web container and the ejb container are in the same app server, EJBs can be local.
    However, in the third case, it is unlikey that you will have the client runnng and the same jvm as the server, because the app server has its own jvm.
    sample code (this method is being called from the main method of a simple java program. it is self explanatory):
    public  void processRequestForSessionBean()
             System.out.println("REQUEST RECEIVED");
             try
                   Hashtable nameHashtable = new Hashtable();
                   nameHashtable.put( Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory" );
                   nameHashtable.put( Context.PROVIDER_URL, "t3://localhost:7001" );
                   InitialContext context = new InitialContext(nameHashtable);
                   System.out.println("created initial context");
                   Object lookupObject = context.lookup("CustomerBean");
                   System.out.println("Got the lookup object");
                   CustomerDataHome home = (CustomerDataHome) PortableRemoteObject.narrow(lookupObject,
                             Class.forName("com.shiv.business.CustomerDataHome"));
                   System.out.println("Home interface");
                   customerData = home.create();
                   System.out.println("Remote Interface");
                   addDataToSB(customerData);
                   ArrayList namesList = customerData.getNames();
                   System.out.println(namesList.toString());
                   //customerData.remove();             
              catch (Exception exception)
                   System.out.println("FATAL ERRORS");
                   exception.printStackTrace();
              }

  • How to call JCS in simple java class

    I want to make a atsratup class and this class will have to communicate with a
    java controls.But i am not able to create an instance of java control in simple
    startup class.
    IF any body has called java control in simple java class pls. let me know

    Hi Surinder,
    you can use (some types of) controls with the following code:
    Class controlClass = Class.forName("mypackage.MyControl");
    MyControl control = (MyControl)WlwProxy.create(controlClass, request);
    control.callMethod();
    Unfortunatelly it requires a request (or an URL), so you will need some
    tricks to use it in a startup class.
    This is an internal, undocumneted... call and does not set any
    parameters of the control, so use it with care.
    Let me know if you can solve your problem, pls
    BR,
    don
    surinder wrote:
    I want to make a startup class and this class will have to communicate with a java
    controls.But i am not able to create an instance of java control in simple startup
    class.
    IF any body has called java control in simple java class pls. let me know
    "surinder" <[email protected]> wrote:
    I want to make a atsratup class and this class will have to communicate
    with a
    java controls.But i am not able to create an instance of java control
    in simple
    startup class.
    IF any body has called java control in simple java class pls. let me
    know

  • Insert/flag data to PV9 (db) with CVP script (Call Studio) and create java class

    Hi all,
    i already created workflow with CVP script using Call studio, i have a problem how to insert call entered digit to PV9 and check the bill customerID with java class.
    The workFlow design:
    1. Customer enter the customerID (sessionID from ICM)
    2. Play the customerID ---> Insert to PV9 (ex: 12390)
    3. Check monthly bill
    4. Option enter another customerID
    5. Back to step 2 ---> Insert to PV9 (ex:12390,12380)
    When we want to create a java class is enough to install default call studio + JDK and create new call studio project? because when i created new call studio project only will be created callflow folder and app.callflow
    thx before,
    darma

    Hi Chintan,
    This'is my callflow design with callStudio
    i want create java class to get value from REST Url, i already have the script but i'm still confused how to deploy it in call studio, my call studio project is like this
    this'is the java source, how to compile and what prerequisites are required?
    /*   1:    */ import com.audium.server.AudiumException;
    /*   2:    */ import com.audium.server.session.ActionElementData;
    /*   3:    */ import com.audium.server.voiceElement.ActionElementBase;
    /*   4:    */ import java.io.BufferedReader;
    /*   5:    */ import java.io.InputStreamReader;
    /*   6:    */ import java.io.PrintStream;
    /*   7:    */ import java.net.URL;
    /*   8:    */ import java.net.URLConnection;
    /*   9:    */ 
    /*  10:    */ public class MyBill
    /*  11:    */   extends ActionElementBase
    /*  12:    */ {
    /*  13:    */   static final int PREDICT_THRESHOLD = 3;
    /*  14:    */   private static String vBill;
    /*  15:    */   
    /*  16:    */   public static void GetDataBill(String strDataBill)
    /*  17:    */     throws Exception
    /*  18:    */   {
    /*  19: 23 */     vBill = "0";
    /*  20:    */     
    /*  21: 25 */     URL strBill = new URL("http://192.168.10.23//wsclient.php?id=" + strDataBill);
    /*  22:    */     
    /*  23:    */ 
    /*  24:    */ 
    /*  25: 29 */     URLConnection hpCon = strBill.openConnection();
    /*  26: 30 */     int len = hpCon.getContentLength();
    /*  27: 32 */     if (len > 0)
    /*  28:    */     {
    /*  29: 36 */       BufferedReader in = new BufferedReader(
    /*  30: 37 */         new InputStreamReader(strBill.openStream()));
    /*  31: 38 */       vBill = in.readLine();
    /*  32:    */     }
    /*  33:    */     else
    /*  34:    */     {
    /*  35: 45 */       vBill = "0";
    /*  36:    */     }
    /*  37: 49 */     System.out.println("YourBill : " + vBill);
    /*  38:    */   }
    /*  39:    */   
    /*  40:    */   public void doAction(String name, ActionElementData actionAPI)
    /*  41:    */     throws AudiumException
    /*  42:    */   {
    /*  43: 63 */     String strCustID = (String)actionAPI.getSessionData("QueueIDs");
    /*  44:    */     try
    /*  45:    */     {
    /*  46: 66 */       GetDataBill(strCustID);
    /*  47:    */     }
    /*  48:    */     catch (Exception e)
    /*  49:    */     {
    /*  50: 69 */       System.out.println("0");
    /*  51:    */     }
    /*  52: 74 */     String balance = vBill.trim();
    /*  53: 81 */     if (balance == "0")
    /*  54:    */     {
    /*  55: 83 */       actionAPI.removeAllSessionData();
    /*  56: 84 */       actionAPI.setSessionData("balance", balance);
    /*  57:    */     }
    /*  58:    */     else
    /*  59:    */     {
    /*  60: 91 */       String strSess = balance.substring(0, 1);
    /*  61: 92 */       String strSess2 = balance.substring(1);
    /*  62:    */       
    /*  63:    */ 
    /*  64: 95 */       actionAPI.setSessionData("StsBill", strSess);
    /*  65: 96 */       actionAPI.setSessionData("ValBill", strSess2);
    /*  66: 99 */       if (strSess > "1")
    /*  67:    */       {
    /*  68:102 */         actionAPI.setSessionData("StsBill", "1");
    /*  69:103 */         actionAPI.setSessionData("balance", strSess2);
    /*  70:    */       }
    /*  76:110 */       if (strSess == "0")
    /*  77:    */       {
    /*  78:112 */         actionAPI.setSessionData("StsBill", "0");
    /*  79:113 */         actionAPI.setSessionData("balance", strSess2);
    /*  80:    */       }
    /*  81:115 */       if (strSess == "9")
    /*  82:    */       {
    /*  83:117 */         actionAPI.setSessionData("StsBill", "9");
    /*  84:118 */         actionAPI.setSessionData("balance", "0");
    /*  85:    */       }
    /*  86:121 */       if (strSess2.trim() == "") {
    /*  87:122 */         actionAPI.setSessionData("balance", "0");
    /*  88:    */       } else {
    /*  89:124 */         actionAPI.setSessionData("balance", strSess2);
    /*  90:    */       }
    /*  91:    */     }
    /*  92:    */   }
    /*  93:    */ }
    please help Me

  • Calling Servlet from a java class

    Hi,
    I don�t know what I�m doing wrong...
    I try to call a servlet located in a tomcat webserver, from a class, and capture its output. I use an URLConnection object... Everything is all right when I want to get an html page, but, it reports an IOException (FileNotFoundException) when the requested resource is a servlet.
    This servlet is working correctly.
    Can�t I use an URLConnection to access servlets?
    Cheers

    try setting up the user agent property of HTTP protocol to a browsers,its worth a shot.
    Cheers
    Khalid

  • Can I call my own custom java class from JavaScript?

    You can instantiate a "JavObject" from client-side JavaScript:
    http://developer.netscape.com/docs/manuals/js/client/jsref/javobj.htm#1193137
    What I don't know is, does JavaObject mean only the browser's JRE classes? Can I instantiate a class I wrote?

    Also, does this even work in IE anymore? I'm trying it and it doesn't seem to work! Anyone know if this feature was removed? I have the latest Java plug-in.

  • How to run jscript or vbscript inside a java class

    I would like to create a class that can excecute jscripts and/or Vbscripts. Does any one knows if there is a class or a way to host jscrips so the script can access only the methods I specify in my "hosting env"? This is similar as using MS scripting utility to run vbscripts inside a VBprogram.
    Thanks
    G/

    see the rhino project at
    http://www.mozilla.org/rhino/

  • Call apt with multiple arguments

    Is it possible to call apt inside a java class and pass multiple .class files?
    For example:
    String[] args = new String[5];
    args[0] = "-nowarn";
    args[1] = "-XclassesAsDecls";
    args[2] = "-classpath";
    args[3] = System.getProperty("java.class.path");          
    args[4] = "packageName.FirstClass packageName.SecondClass";
    return Main.process(new MyAnnotationProcessorFactory(),args);Result of the above example is:
    error: Could not find class file for packageName.FirstClass packageName.SecondClass
    1 error

    The class path contains classes that we need.
    This example works:
    String[] args = new String[6];
    args[0] = "-nowarn";
    args[1] = "-XclassesAsDecls";
    args[2] = "-classpath";
    args[3] = System.getProperty("java.class.path");     
    args[4] = "packageName.FirstClass";
    args[5] = "packageName.SecondClass";
    return Main.process(new IapiAnnotationProcessorFactory(),args);I replaced args[4] = "packageName.FirstClass packageName.SecondClass"; with a
    args[4] = "packageName.FirstClass";
    args[5] = "packageName.SecondClass";

  • Is there an easy way to call a java class from an applet?

    Does anyone know of an easy way to call a server based java class from an applet? Has anyone done it or came across it? If yes how/where?
    Cheers, Chris.

    I'm not sure about the issue. Are you talking about "servelets"? "RMI"? Take a look at those issues.

  • Custom Java class called from RTF template generates error

    We are running a report in BI Publisher and the report calls a custom developed Java class that is used to bind PDFs together and sent the result to another application.
    On the RTF template we have some XSLT that reads the input XML and sets a variable which is then passed to the Java class. We are however getting the following error when the report is called simultaneously 2 or more times:
    XML-22044: (Error) Extension function error: Error invoking 'JavaClassName': 'java.lang.Error: Cannot interweave overlay template with pdf input, combined number of pages is odd!
    I read this as the real cause of the error is the Java code but I'm not 100% sure. Also I don't understand what the error message means.
    Could someone help out please?
    Many thanks

    Since our this requirement is in Quotes module, its not using OAF. It is using plain JSPs and java classes.
    What i was thinking is, create the Option values as flex fields, and write a custom java class to fetch these data from the flex tables and use it in the JSP.
    The main problem we are facing now is,
    "...we wrote a simple java class, which establishes database connection, executes a simple insert & select query to our custom table. compiled & placed the class file under our new pkg structure under $JAVA_TOP eg. oracle.apps.xxx.quot.tmpl , bounced the apache."
    But when we tried to import this class in the jsp (which is being customized), the app just throwed Internal Server Error and we couldnt find any info in the Log file.
    Couldnt guess, why is this simple thing failing. Any idea ?

  • Calling Servlet from Java Class in eclipse

    Hi ,
    I am calling a Servlet from JAVA Class as I am using IDE: Eclipse. The Problem is below
    URL url = new URL(ServletPath);
    URLConnection connet = url.openConnection();
    I am using the above code in JAVA to Connect to Servlet I have given Print statement in Servlet such that whenever it calls it prints on Console but when I try to run the code the Statement is not printed in the Console of eclipse I think URL connection is not able to establish any connection ..... if any has solution for this please reply
    Thanks & Regards,
    Arvind

    I am calling a Servlet from JAVA Class as I am using IDE: Eclipse. The Problem is below
    URL url = new URL(ServletPath);
    URLConnection connet = url.openConnection();Why should the Servlet running in different Runtime print on your Eclipse Runtime. Please be more clear about the question.

  • How to get access to PageContext in a java class (.java file)?

    Hi all,
    I am trying to get access to PageContext from inside a java class, and it doesn't seem to work.
    I could get the PageContext from a jsp page, at the object instantiation, through the constructor, but my class is not called by a jsp page.
    Any ideas?
    Thanks,
    Paul

    Basically I do not need to change any attributes from pageContext. However I need the pageContext object because I am using a third party component that is initialized with the pageContext .
    I cannot change the implementation of that component: it is a black box to me, I simply need the pageContext in my java class that uses the component.
    Any thoughts based on this clarification?
    Thanks,
    Paul

Maybe you are looking for

  • Cannot log in to Windows 8.1 Pro virtual machine!

    Hello. I installed Windows 7 Ultimate on my iMac (Mid 2011) via Boot Camp, then I installed Parallels Desktop 8 and my Windows virtual machine was recognised by PD8. Then I upgraded my Windows version to Windows 8 Pro and added Windows Media Centre.

  • K7T266 Pro Raid and Geforce 2 GTS problem

    (Originally posted to wrong group) Hello everyone. I have been experiencing a problem for some time now regarding lockups and crashes caused by my video card, which vary in severity depending on the driver version used. Since I'm using an MSI K7T266

  • In a dynamic page how to share variable between PL/SQL and javascript

    For example, my dynamic page contains such PL/SQL codes: <ORACLE> DECLARE info varchar(100); rowid urowid; procedure doDelete( row_id in urowid ) IS begin Delete From xxx WHERE rowid = row_id; end doDelete; BEGIN Select name, rowid INTO info, rowid F

  • Uninstall problem in cc applications after time machine migration to new mac

    Newbie to cc. Having problems with cc programs that were migrated across to new iMac via Time Machine back up when setting up new mac. Attempting to open PS cc results in error message 86. I have now uninstalled Creative Cloud program and a PS cc pro

  • How to control field length in SAP query's report output

    HI everybody, I have one scenario in SAP query in which there are two fields in the report output: Milestone descrition and milestone description Long Text. In CJ02 (WBS element overview), these two fields are populated with some text. If description