Mini scripting in Java?

What I want to be able to do is the following.
Lets say we have the following simple method
String echo(String str) {
     return str;
}So I want to be able to give Java a piece of String like "echo(\"Hello\")" and get back "Hello".
So in essence I want a mini parser from string to code. This is something scripting languages do (like Groovy) but since Groovy is Java there will be a way to do it with only pure Java.
Thanks

Thanks for your replies.
I think this is the way forward:
[Adding dynamic Java code to your application - Java World|http://www.javaworld.com/javaworld/jw-06-2006/jw-0612-dynamic.html]

Similar Messages

  • How can i execute vb scripts in java program

    hi
    how can i execute any batch files or any other exe files (vb scripts) from java programs
    thanks

    Hi,
    You use Runtime.exec to execute commands / exe-files. See the documentation (and remember that it will only work on windows):
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html
    /Kaj

  • How to call a shell script in Java ?

    Hi there,
    i try to call a shell script in java but it wont work.
    please can anybody help me.
    my Code :
    import java.io.*;
    public class SendMessage{
    Runtime rt;
    public SendMessage(){
    rt = Runtime.getRuntime();
    public void send(){
    try{
         rt.exec("sendMessage.sh");
         System.out.println("Message was Send");
    catch(IOException ex)
    ex.printStackTrace();
    the file called sendMessage.sh is also stored in the same directory as the class File.
    the exception never cames up but the script also never starts.
    what is wrong ??? :-((
    need help !
    }

    rt.exec("sendMessage.sh");Oh, sorry, I didn't see that you tried under UNIX.
    BTW you should check for the OS - this stuff is very os and os release dependent.
    I have not experimented with this under unix.
    But something must interpret that sendMessage.sh file.
    Perhaps the hash bang info is used by exec() (did you put a
    #!/bin/sh as first line in your .sh file?
    If not, try
    rt.exec("/bin/sh sendMessage.sh");Regards,
    Marc

  • Converting Perl Scripts into Java Servlets

    Hello,
    I have just been assigned the job of converting some perl scripts into Java Servlets. The first problem i have run into is with quotes. The problem is in perl you can just print out blocks of html without worrying about the quotes. ie (name="joe"). It will be a pain if i have to delimit every quote that is in the html so that i can add it to my java string. I was just wondering if anyone knows of an easy way of accomplishing this task.
    Thanks,
    Jon

    jonhorsman said
       I have just been assigned the job of converting some perl
       scripts into Java Servlets.I was just wondering if anyone
       knows of an easy way of accomplishing this task. The easy way is to not do it - is there a business need to do this or just because someone likes java more than perl.
    But presuming there is a business need, then the easist way I can think (and certainly more interesting than doing it by hand) is to write a perl script that does it for you.

  • What're the differences between JSP, Java Script, and Java Applet?

    I am confused by the concepts: JSP (Java Server Page), Java Script, and Java Applet? What are their main differences?

    I don't know about differences, but one of their main similarities is that each of them has a page in Wikipedia.
    JSP
    JavaScript
    [Java applet|http://en.wikipedia.org/wiki/Java_applet]
    There. That should give you enough information.

  • How to run Perl script in Java program?

    Some say that the following statement can run Perl script in Java program:
    Runtime.getRuntime().exec("C:\\runPerl.pl");
    But when I run it, it'll throw IOException:
    java.io.IOException: CreateProcess: C:\runPerl.pl error=193
    at java.lang.Win32Process.create(Native Method)
    at java.lang.Win32Process.<init>(Win32Process.java:63)
    at java.lang.Runtime.execInternal(Native Method)
    at java.lang.Runtime.exec(Runtime.java:566)
    at java.lang.Runtime.exec(Runtime.java:428)
    at java.lang.Runtime.exec(Runtime.java:364)
    at java.lang.Runtime.exec(Runtime.java:326)
    at test.runPerl.main(runPerl.java:16)
    Exception in thread "main"
    Where is the problem? In fact, I do have a Perl script named "runPerl.pl" in my C:/ directory. Could anybody tell me why it can't be run? Thanks in advance.

    Hello sabre,
    First of all thanks for your reply.
    I have tried like what you mentioned.
    Eventhough, i could get the exact error message.
    I could get the Exception
    "Exception:java.lang.IllegalThreadStateException: process hasn't exited"
    <code>
    import java.io.*;
    public class Sample{
    public static void main(String args[]) {
    String s = null;
    Process p;
    try
         p = Runtime.getRuntime().exec("tar -vf sample.tar");
         //p.waitFor();
         if(p.exitValue() == 0)
              System.out.println("CommandSuccessful");
         else
              System.out.println("CommandFailure");
    catch(Exception ex)
         System.out.println("Exception:"+ex.toString());
    </code>
    In this code, i tried to run the "tar command". In this command i have given -vf instead -xvf.
    But it is throwing
    "Error opening message catalog 'Logging.cat': No such file or directory
    Exception:java.lang.IllegalThreadStateException: process hasn't exited
    CommandFailure"
    "Error opening message catalog 'Logging.cat'" what this line means ie,
    I dont know what is Logging.cat could you explain me its urgent.
    Thanks in advance.
    Rgds
    tskarthikeyan

  • As i am fresher Please share the doc of ECMA script using java script in SharePoint 2013 also how we can insert,update,delete records in list using ECMA script.

    As i am fresher Please share the doc of ECMA script using java script in SharePoint 2013 step by step also how we can insert,update,delete records in list using ECMA script.
    Thanks and Regards, Rangnath Mali

    Hi,
    According to your post, my understanding is that you want to use JavaScript to work with SharePoint list.
    To create list items, we can create a ListItemCreationInformation object, set its properties, and pass it as parameter to the addItem(parameters) function
    of the List object.
    To set list item properties, we can use a column indexer to make an assignment, and call the update() function so that changes will take effect when you callexecuteQueryAsync(succeededCallback,
    failedCallback). 
    And to delete a list item, call the deleteObject() function on the object. 
    There is an MSDN article about the details steps of this topic, you can have a look at it.
    How to: Create, Update, and Delete List Items Using JavaScript
    Thanks & Regards,
    Jason
    Jason Guo
    TechNet Community Support

  • Scripting in java

    Hi All
    I would like to know if there is a way to use java instead of javascript in browsers.
    example: <script src="java" />
    This would make life a lot easier.
    Many thanks
    amoj

    amoj wrote:
    It would be great to use java instead of javascript on the client side. Since every browser has a jre anyway!No they don't. What would be great about it anyway? Seriously, think about it. Javascript gives you access to the DOM, you wouldn't need Java for that. Javascript gives you ways to define and use objects, so you don't need Java for that. Javascript gives you common programming artifacts such as mathematical calculations, string manipulation, loops, variables and arrays, so you don't need Java for that. If it's rich UI you're after, scripting doesn't really help with that since browsers don't understand it, and you can use applets if you really want rich UI in your browser. I'm at a loss to think what advantage you see in using Java client-side as a scripting language (but I bet someone comes up with a fair few good examples of how I'm wrong!)

  • Unix scripting in java

    hello
    im new to java.
    and i need to learn unix scripting in java. is it difficult to learn? can one learn it within a short span of time?! could anyone please give me some links where i can learn.
    tks

    I run UNIX systems, what do you mean by Java scripting?
    do you mean SH, BASH, TCSH, CSH shells and stuff? cause Java is platform independant?
    btw, are you using Linux or FreeBSD?
    p.s. Go FreeBSD!!

  • How to execute unix shell script from Java ...

    Hi,
    Anyone know how to execute unix shell script from Java?
    Suppose I have several shell scripts written in perl or tcl or bash.
    I just want to catch the output of that script.
    Is there any ready to use module/object for this?
    Please let me know, this is quite urgent for my study assigment.
    Thanks in advance,
    Regards,
    me

    Look up Runtime.exec()

  • Run a UNIX Script from java

    Hi,
    how can i run a unix script from java application. This java application is on windows.
    How can i do this.
    thanks,

    Hi,
    how can i run a unix script from java application.
    This java application is on windows.
    So I think it's safe to assume that the target script is on a remote unix server.
    Take a look at http://sourceforge.net/projects/sshtools/

  • Excute unix script from java.

    Hi need to excute unix script from java application.
    My code is:
    public class Test
    public static void main(String args[])
         try{
         p = Runtime.getRuntime().exec("./qfe0"); //qfe0 is the name of the script.
    p.waitFor();
    catch(Exception e)
    e.printStackTrace();
    My problem is that using the waitFor() statement stuck the the script. if i don't use the waitFor() it works good but then i don't know when the script is finished.
    Any idea?

    The problem is likely to be that you script is either waiting for input or has filled the stdout buffer and you are not emptying it. Search this forum for this as its been answered many times before.

  • How execute Unix script from java?

    Can I execute Unix script from java?

    Yes. Using ProcessBuilder. And read [When Runtime.exec() wont|http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html]. It's old, but pretty much all of it is still true.

  • Is it possible to execute SAPGUI scripts from java program?

    Hi everyone..
         I need to develop an java applications that executes the SAPGUI script or any technique that execute set of transaction as client.
         Is it possible to execute SAPGUI scripts from java program? if so, how it can be achieved? is there any other technique to achieve above mention scenario?.
         it will be more helpful, if docs related to that are shared..
         Thanks in advance

    Oh, bummer. Would be much more convenient if I could just use iTunes for everything. Can't stand WMP. I wonder if WinAmp might be a good compromise?
    Thanks for this answer . . .
    Sharon

  • Example: Executing a shell script from java

    Hi. There are many other posts in the forums related to executing a unix script from java, but I wanted to post another example that I thought might be helpful...
    The key thing to executing the script is to include the -c switch for the sh command. This tells the sh command that you are passing a string to be interpreted as input. Without this switch, the script does not execute as you'd expect it to. Also, use a string array to pass each part of the sh command.
    Here is a working sample class, along with a test script to execute it:
    public class TestShellScript {
    public static void main(String[] args)
    String[] chmod = {"chmod","777","testscript1"};
    String[] runscript = {"sh","-c","./testscript1 > jdata.out"};
    Runtime rtime = Runtime.getRuntime();
    try
    rtime.exec(chmod); // Set the authorities for testing
    rtime.exec(runscript); // Run the script with redirection
    catch (IOException e)
    e.printStackTrace();
    rtime = null;
    Here is a test script to wrap the java call:
    #!/bin/sh
    cd /<your script dir>
    export -s CLASSPATH=/<your jar dir>/TestShellScript.jar
    export -s PATH=/<your script dir>:/usr/bin
    java TestShellScript
    - Hope this helps.

    I don't know exactly but the code written below is working fine try the same with your code .Even with your code instead running the code with
    " ./<filename> ",if you execute it with "sh <filename>" command without changing the mode of the file it is executing properly.
    import java.io.*;
    import java.util.*;
    public class ScriptBuilder
    public ScriptBuilder()
    public void writeScript() throws java.io.IOException
    FileWriter writer = new FileWriter(new File("test_script"));
    writer.write("#! /bin/sh\n");
    writer.write("ll>/home/faiyaz/javaprac/checkll");
    writer.flush();
    writer.close();
    Runtime rt= Runtime.getRuntime();
    rt.exec("chmod 777 test_script");
    rt.exec("./test_script");
    } public static void main (String[] args)throws java.io.IOException
    ScriptBuilder sb = new ScriptBuilder();
    sb.writeScript();
    }

Maybe you are looking for

  • Code not working in 9i but works in 10g........!!

    Hi , In the above query , it is possible for me to identify how many duplicate ITEM are present. but my output should be like this EMPID ITEM NAME 201 A D 301 A D 111 D A 11 D A 11 D A 122 E A 12 H A 11 H A 88 H A 44 H A 10 rows selected. SQL> SELECT

  • Problem with connection pool

    Hi All, We have a repository that is built on top of a SQL server database and the front end application works fine. We have now created another repository against another SQL Server database and wanted to have this as a separate subject area in the

  • I removed chrome 10 and newly installed FF4 final, and I can't read PDF files within the browser. There was no problem in Chrome.

    I removed chrome 10 and newly installed FF4 final, and I can't read PDF files within the browser. There was no problem in Chrome. I can't even see the acrobat reader plugin in the plugins page. Acrobat 10 is already installed in my PC. Every time I t

  • Cannot execute switchdb?

    I have a full Platform 7.0 with SP2 installed on Redhat 7.2 and I am evaluating Integration by installing the WLI template from Configuration Wizard. I tried to run the RunSamples script but I am getting the attached error. At first I thought its env

  • Error: FRM-41076: Error populating Group

    hi frs, i have a created a record group with static values. while populating the group getting error like FRM-41076: Error populating Group how to solve it help pls. Regards Rajesh