Execute java commands through java code

Hi guys,
I want to run a java class from another class.
I tried like this..
Runtime.getRuntime("java C:\test2");But test2 did not run.
But I could execute this command sucessfully.
Runtime.getRuntime("javac C\test2.java");
I could see class file generated for this.
Please suggest me how to run a java class .....
Thanks in advance.

Hi guys,
I want to run a java class from another class.
I tried like this..
Runtime.getRuntime("java C:\test2");But test2 did not
run.Because the JVM (the java command) does not take a file as its argument. It takes a class name. You'd want something like java -cp C:\ test2
But I could execute this command sucessfully.
Runtime.getRuntime("javac C\test2.java");Because javac, unlike java, does take files (rather than a class name) as its argument.

Similar Messages

  • Execute dos commands through java

    Hi,
    Im trying to execute dos commands through java like
              try {
                   java.lang.Runtime.getRuntime().exec("cmd /c cls");
              }catch(IOException e){
                   System.out.println(e.getMessage());
              }Not sure if its possible? however
    open notepad would work
              try {
                   java.lang.Runtime.getRuntime().exec("notepad");
              }catch(IOException e){
                   System.out.println(e.getMessage());
              }Im trying to execute a cls commands to clear screen but without luck.

    The question is, which shell do you want to clear?
    I don't really know, but it could be that Runtime.exec executes its command in a new shell window...

  • Execute Java Code on client

    Hello,
    how can i execute java code on clientside?

    I guess you will have to add an applet to the web page.
    http://developers.sun.com/prodtech/javatools/jscreator/reference/techart/2/applet.html

  • Error executing RDS command. Status Code : 503 , Reason : Service Unavailable

    Hi,
    I am being trying to connect a Flex desktop application with a Java application running in Tomcat (6.0.29), and I get this error message when trying to use the Data wizard to connect with Blaze DS.
    I have read all the tutorials and everything looks good from the server side. This is what appears in the server log:
    2011-01-27 16:02:33,030 [ INFO] - RemotingDestinationExporter - Created remoting destination with id 'accounts'
    2011-01-27 16:02:33,046 [ INFO] - RemotingDestinationExporter - Remoting destination 'accounts' has been started started successfully.
    2011-01-27 16:02:33,046 [ INFO] - RemotingDestinationExporter - Created remoting destination with id 'customers'
    2011-01-27 16:02:33,046 [ INFO] - RemotingDestinationExporter - Remoting destination 'customers' has been started started successfully.
    2011-01-27 16:02:33,061 [ INFO] - FrameworkServlet - FrameworkServlet 'flex': initialization completed in 3887 ms
    2011-01-27 16:02:50,813 [ INFO] - MessageBrokerHandlerAdapter - Channel endpoint my-amf received request.
    2011-01-27 16:43:42,897 [ INFO] - MessageBrokerHandlerAdapter - Channel endpoint my-amf received request.
    (The last two lines appears when I put the AMF channel's URI in a browser).
    Below is what appears in the Event log from Eclipse.
    java.lang.RuntimeException: java.lang.RuntimeException: RDS server message:
    Error executing RDS command. Status Code : 503 , Reason : Service Unavailable
    at com.adobe.flexbuilder.services.j2eeservice.J2EEServicePage.setVisible(J2EEServicePage.jav a:149)
    at org.eclipse.jface.wizard.WizardDialog.updateForPage(WizardDialog.java:1171)
    at org.eclipse.jface.wizard.WizardDialog.access$2(WizardDialog.java:1149)
    at org.eclipse.jface.wizard.WizardDialog$5.run(WizardDialog.java:1138)
    at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
    at org.eclipse.jface.wizard.WizardDialog.showPage(WizardDialog.java:1136)
    at org.eclipse.jface.wizard.WizardDialog.nextPressed(WizardDialog.java:830)
    at com.adobe.flexbuilder.DCDService.ui.wizard.ServiceWizardDialog.nextPressed(ServiceWizardD ialog.java:93)
    at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:369)
    at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:624)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:228)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3910)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3503)
    at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
    at org.eclipse.jface.window.Window.open(Window.java:801)
    at com.adobe.flexbuilder.DCDService.ui.wizard.ServiceWizard.show(ServiceWizard.java:190)
    at com.adobe.flexbuilder.DCDService.ui.wizard.ServiceWizard.createService(ServiceWizard.java :152)
    at com.adobe.flexbuilder.dcrad.views.ServiceExplorerView$1.handleEvent(ServiceExplorerView.j ava:528)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1027)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1012)
    at org.eclipse.swt.widgets.Link.wmNotifyChild(Link.java:1004)
    at org.eclipse.swt.widgets.Control.wmNotify(Control.java:4877)
    at org.eclipse.swt.widgets.Composite.wmNotify(Composite.java:1757)
    at org.eclipse.swt.widgets.Control.WM_NOTIFY(Control.java:4507)
    at org.eclipse.swt.widgets.Control.windowProc(Control.java:4000)
    at org.eclipse.swt.widgets.Display.windowProc(Display.java:4632)
    at org.eclipse.swt.internal.win32.OS.CallWindowProcW(Native Method)
    at org.eclipse.swt.internal.win32.OS.CallWindowProc(OS.java:2314)
    at org.eclipse.swt.widgets.Link.callWindowProc(Link.java:172)
    at org.eclipse.swt.widgets.Widget.wmLButtonUp(Widget.java:1917)
    at org.eclipse.swt.widgets.Control.WM_LBUTTONUP(Control.java:4301)
    at org.eclipse.swt.widgets.Link.WM_LBUTTONUP(Link.java:842)
    at org.eclipse.swt.widgets.Control.windowProc(Control.java:3982)
    at org.eclipse.swt.widgets.Display.windowProc(Display.java:4632)
    at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
    at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2411)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3501)
    at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2405)
    at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2369)
    at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2221)
    at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:493)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:194)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLau ncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.jav a:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:368)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:559)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1287)
    Caused by: java.lang.RuntimeException: RDS server message:
    Error executing RDS command. Status Code : 503 , Reason : Service Unavailable
    at com.adobe.flexbuilder.services.j2eeservice.J2EEServicePage.initialize(J2EEServicePage.jav a:187)
    at com.adobe.flexbuilder.services.j2eeservice.J2EEServicePage.setVisible(J2EEServicePage.jav a:136)
    ... 61 more
    Any help wolud be appreciated.
    Thanks

    Hi There,
    I am getting the same error. can anyone tell me what could be problem?

  • Facing Problem while executing a command through WLST

    Hi,
    Iam using Weblogic 11g(10.3.2).Whenever I execute the below command in WLST on windows it is working fine.
    reassociateSecurityStore(domain="base_domain",admin="cn=orcladmin",password="welcome1",ldapurl="ldap://<hostname>:389",servertype="OID",jpsroot="cn=jpsroot_idm_idmhost1")
    But whenever i execute the same in Linux,it is throwing the error as below:
    wls:/base_domain/serverConfig> reassociateSecurityStore(domain="base_domain",admin="cn=orcladmin",password="welcome1",ldapurl="ldap://<hoistname>:389",servertype="OID",jpsroot="cn=jpsroot_idm_idm1")
    Traceback (innermost last):
    File "<console>", line 1, in ?
    NameError: reassociateSecurityStore
    Please suggest....
    Regards
    Pavan

    Facing Problem while executing a command through WLST

  • Executing Unix command through Java

    Hi,
    Hi, I am trying to run some unix command through:
    Runtime.getRuntime().exec("some unix command line");
    I am running the code on Linux platform. However, I always got some errors. Here are the stack trace of them:
    java.io.IOException: Cannot allocate memory
    java.io.IOException: java.io.IOException: Cannot allocate memory
            at java.lang.UNIXProcess.<init>(UNIXProcess.java:148)
            at java.lang.ProcessImpl.start(ProcessImpl.java:65)
            at java.lang.ProcessBuilder.start(ProcessBuilder.java:451)
            at java.lang.Runtime.exec(Runtime.java:591)
            at java.lang.Runtime.exec(Runtime.java:429)
            at java.lang.Runtime.exec(Runtime.java:326)Anybody has any idea why is this happening? Thanks.
    Aulia

    Hi, thanks for your reply so far. I tried the following code:
         public boolean executeCommand() {
              boolean success = true;
              for (int i = 0; i < 5; i++) {
                   Process p = null;
                   try {
                        p = Runtime
                        .getRuntime()
                        .exec("ls");
                        InputStreamReader inR = new InputStreamReader(p
                                  .getErrorStream());
                        BufferedReader buf = new BufferedReader(inR);
                        String line;
                        while ((line = buf.readLine()) != null) {
                             System.out.println(line);
                        p.destroy();
                   } catch (Exception e) {
                        System.err.println(e.getMessage());
                        e.printStackTrace();
                        success = false;
                   } finally {
                        p = null;
              return success;
         }However, it still throws the same exception. Yes, I put it in a tight loop, but not recursively.

  • Java.lang.NoClassDefFoundError when executing JAVA code

    Hy everyone,
    Trying to execute some java code through forms I got this error when running my program : java.lang.NoClassDefFoundError : simple (where simple is a java class I developped).
    These are the steps I followed:
    1- Devopping a simple JAVA class (simple.java) and compiling in JDK 1.4 (for compatibilty with forms 10.1.2.0.2)
    2- Creating the JAR file
    3- Copying the JAR file in <ORACLE_HOME>\forms\java
    4- Adding the adress of the JAR file in CLASSPATH (environment variable of the server)
    5- Adding the adress of the JAR file in CLASSPATH (environmental file of OAS default.env)
    6- Importing the JAVA class trought forms builder (program>>import java class)
    7- Invoking the JAVA class via the PL/SQL packages created by forms builder
    8- Running the program
    Thanks for your help.
    Regards.

    In most cases, you should not have to stop and restart OC4J_BI_FORMS to pick such changes. However, since you are having problems, I would ensure that all frmweb processes have been stopped, then stop and restart OC4J_BI_FORMS and retest. If that doesn't work, you should review how you imported the java into your app. Look closely at the Importer options you used and ensure that you have not change the file name at any point. Because you are working with Java, case sensitivity is critical.
    Also, where are you seeing the error message? Client java console or in a server side log? If server side, exactly which log file is reporting the problem? I would suggest you post the first 4 ro 5 lines of the error and not just the NoClassDefFound part.

  • Executing Java Code in ODI Procedure

    Hi All,
    I have following  java code which i need to write on ODI procedure but i am not sure which technology to chose (Jython,Sunopsis API or Java BeanShell).
    I tried to execute the procedure Jyhton with <% "Java code"%> but getting the error.Any boddy can suggest where i doing wrong.
    <%
    import javax.naming.Context;
    import javax.naming.NamingEnumeration;
    import javax.naming.directory.*;
    import java.util.Hashtable;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    String userName = "HXXXXXX";
    String CN1=null;
    String Dis_Name=null;
    String Mem_of=null;
    String Mail=null;
    String SGID=null;
    File file = new File("C:/Project/ODI/LDAPID.txt");
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "LDAP://XX.if.YYYY.net:389/OU=XYZ,DC=ZZ,DC=if,DC=XYZ,DC=COM");
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, new String("" + "\\" + userName));
    env.put(Context.SECURITY_CREDENTIALS, "");
    DirContext ctx = null;
    NamingEnumeration results = null;
    ctx = new InitialDirContext(env);
    SearchControls controls = new SearchControls();
    controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    results = ctx.search("", "(objectclass=person)", controls);
    FileWriter fw = new FileWriter(file.getAbsoluteFile());
    BufferedWriter bw = new BufferedWriter(fw);
       while (results.hasMore())
             SearchResult searchResult = (SearchResult) results.next();
             Attributes attributes = searchResult.getAttributes();
             Attribute attr = attributes.get("cn");
             String cn = (String) attr.get();
             CN1=(String.valueOf(attributes.get("cn")));
             Dis_Name=(String.valueOf(attributes.get("displayName")));
             SGID=(String.valueOf(attributes.get("userPrincipalName")));
             Mem_of=(String.valueOf(attributes.get("memberOf")));
             Mail=(String.valueOf(attributes.get("mail")));
             bw.write(CN1 + " || " + Dis_Name + " || " + SGID + " || " + Mail);
             bw.newLine();
    bw.close();
    results.close();
    ctx.close();
    %>
    I am getting following error.
    The application script threw an exception: java.lang.NullPointerException BSF info: CODE_JAVA at line: 0 column: columnNo
    Please suggest what went wrong with the code.
    Thanks
    Regards

    In Jython you don not need to declare the type so String userName = "HXXXXXX"; should simply read userName = "HXXXXXX" . Lots of your code need to be rewritten to work with Jython if you choose that as your technology.

  • Execute java code taken from a properties file

    I have a requirement to store some java code in the Properties file & use the code inside the program later. Is there a way I can execute this code after I get it from the .properties file which is retrieved using the ResourceBundle?
    Example:
    File: system.properties
    Item_list=blocksBean.menu(QueryValue,request.getContextPath())
    Inside my Java program I'm using this..
    theBody=codesBean.replaceAll(theBody, "%%menu%%",ResourceBundle.getBundle("system").getString("Item_list"), true);
    instead of
    theBody=codesBean.replaceAll(theBody, "%%menu%%",blocksBean.menu(QueryValue,request.getContextPath()), true);
    This doesn't work because ResourceBundle.getBundle("... returns the value.. which is a string "blocksBean.menu(QueryValue,request.getContextPath())". But what I need is it has to be executed..
    blocksBean.menu() returns a string value of html code fetched from the dartabase.
    Is there a way I can execute blocksBean.menu() which is retrieved from the .properties file.. If anyone has done it / have an idea on this.. please e-mail me [email protected]
    I need something like an eval() in javaScript..
    Thanks in advance
    -ashok

    These boys might have something that will help you:
    http://www.beanshell.org/
    Good luck
    Lee

  • Execute java code before rendering the page

    Hi,
    In a task flow, can I execute some java code before the page/view is rendered (i.e. some preprocessing). I would need to be able to have access to the bindings on the page.
    Thanks!

    Can you try doing as specified below:
    If it is simple JSPX, you could use the phase listener as follows:
    JSPX Code:
    <f:view beforePhase="#{SamplePageBean.phaseListener}">
    <af:document id="d1">
    <af:form id="f1">
    <af:panelFormLayout id="pfl1">
    <f:facet name="footer"/>
    </af:panelFormLayout>
    </af:form>
    </af:document>
    </f:view>
    Bean Code:
    public class SamplePageBean {
    public SamplePageBean() {
    public void phaseListener(PhaseEvent phaseEvent) {
    if (phaseEvent.getPhaseId().equals(phaseEvent.getPhaseId().RENDER_RESPONSE)) {
    // DO NECESSARY INITIALIZATION
    Thanks,
    Navaneeth

  • Execute Java code after login

    Hi experts,
    I'd like to execute some Java code after a successful login. I guess I could write a custom login module or use a WD Java iView to do this but a "better" solution may exist.
    Regards,
    Pierre

    Customizing your login module is probably your best bet. As soon as you're user is authenticated, you can execute your custom Java code.
    From my experience, I have not seen an easier / cleaner way to capture that event.
    Regards,
    Tom

  • Using a button of type=button to execute java code

    Hello,
    I here what I need to do.
    - A user fill a form
    - He press submit
    - the button goes and execute some java code and then refresh the page (same page)
    Now I don't want to use a input=Submit, that call a a servlet that just update the information, and output to the servlet;
         out.println("<html>");
          out.println("<body>");
          out.println("<head>");
          out.println("<meta content=\"1; url=" + "SamePage.jsp" + "\" http-equiv=refresh>");
          out.println("</head>");
          out.println("</body>");
          out.println("</html>");Instead, I would like to do: <INPUT TYPE="button" VALUE="Close Window"   onClick="window.close();"> but instead of JavaScript in the onClick it would be JavaCode that would update the object (already instantiated in the JSP) and would then refresh the page.
    Is this possible?
    thanks.

    Hi,
    it is not possible because JSP code is executed server-side, while javascript code is executed client-side (in client's browser).

  • Class compiling/executing JAVA-Code??

    Hi!
    Stupid question: ;-)
    Is there a possibility to "parse" Java-Code into a JAVA-Class or to give JAVA-Code to a class that compiles the code and execute it?
    Thanks for answering!
    Mark Hauchwitz.

    background: we're running servlets and simply need to "parse" specialized/customized java-code for every customer into the servlet code. Source: database or whatever...
    How to get started?

  • Batch file to execute java code

    Hi,
    I need to write a batch file to execute a sequence of java applications.
    The problem i face is in addition to the usual libraries I am also using certain jar files i downloaded like the mail interface etc.
    When i just compile a java code using a simple batch file giving the path of the compiler and the java code, it fails citing not knowing the location if the packages.
    could anyone please let me know what i need to do. Is there like a skeleton that i might find somewhere for this operation

    dexterity wrote:
    Hi,
    I need to write a batch file to execute a sequence of java applications.
    The problem i face is in addition to the usual libraries I am also using certain jar files i downloaded like the mail interface etc.
    When i just compile a java code using a simple batch file giving the path of the compiler and the java code, it fails citing not knowing the location if the packages.
    could anyone please let me know what i need to do. Is there like a skeleton that i might find somewhere for this operationSet the classpath correctly at runtime.
    Why do you need the location of your compiler? Are you compiling or running? If you are compiling go look at Ant.

  • How to execute System command through Applet

    Hi all,
    How can I execute a System command through Applet.
    I have written a code Runtime.exec("ls") in my applet but it gives me
    this execption even if I certify the applet ->
    java.security.AccessControlException: access denied (java.io.FilePermission <<ALL FILES>> execute)
         at java.security.AccessControlContext.checkPermission(AccessControlContext.java:272)
         at java.security.AccessController.checkPermission(AccessController.java:399)
         at java.lang.SecurityManager.checkPermission(SecurityManager.java:545)
         at java.lang.SecurityManager.checkExec(SecurityManager.java:802)
         at java.lang.Runtime.exec(Runtime.java:548)
         at java.lang.Runtime.exec(Runtime.java:418)
         at java.lang.Runtime.exec(Runtime.java:361)
         at java.lang.Runtime.exec(Runtime.java:325)
         at Test.init(Test.java:24)
         at sun.applet.AppletPanel.run(AppletPanel.java:344)
         at sun.plugin.navig.motif.MotifAppletViewer.maf_run(MotifAppletViewer.java:123)
         at sun.plugin.navig.motif.MotifAppletViewer.run(MotifAppletViewer.java:119)
         at java.lang.Thread.run(Thread.java:484)
    Thanks,
    Manoj.

    There should be a lesson about this somewhere.
    When you visit a web page, does it ask you if you want to have an applet loaded?
    Answer: No
    So, if you visit a page, and an applet is silently loaded which can then execute commands on your computer, is this good?
    Answer: No
    So why do you want to do this?
    Is it good for anyone?
    I mean, if I want to do "ls", can't I just open a command line? Do I need an applet to do it for me?
    Either you have devious desires or your hacking together something that probably shouldn't be.
    If you want to learn start here:
    http://java.sun.com/docs/books/tutorial/security1.2/index.html
    With the article entitled:
    Quick Tour of Controlling Applets
    Ian

  • Error while executing the payroll through transaction code PC00_M40_CALC

    Dear Sir/ Madam,
    While executing the payroll through the transaction code PC00_M40_CALC , i am getting the error as mentioned below :
    "Division by zero not performed "
    Calculation rule X0133****5            RTE = ISDIVP DIVID ARR ZERO=A   ADD
    I am not able to resolve this error. So request to guide me on this.
    Thanks & regards,
    vijaya.s.c.
    Moderator message: wrong forum, please have a look in the (I guess) ERP HCM forums.
    Edited by: Thomas Zloch on Jan 24, 2012

    Hi,
    Maintain have you changed any x013 rule?
    If not, just maintain attendance/time events then process the payroll.

Maybe you are looking for

  • HP 3650 deskjet will not print in Windows 7

    New pc w/ Windows 7. My HP deskjet 3650 will not print PDF, Quicken, Website selections, etc. HELP!

  • Parser for Java v2 decimal formatting bug

    XML Parser for Java v2 (up to 2.0.2.7) does not seem to format decimal numbers correctly with format-number() function. It can handle floats, but not doubles. When can this bug get fixed? BTW, is there a bug database for Java XML Parser? Thanks, null

  • Does TM9.1 SP02 support the check of resource availiability across FROs?

    hi TM experts, In planning or FRO/FU checks of TM9.1 SP02, will system check the current resource has been used in another document at the same time or whether it is in the downtime? If the answer is YES, in which topic I can find in the application

  • To stop all billing,purchase activities in a plant

    Dear All, In our organization we have 34 plants in which two plants have been closed. I want to know how we can stop all the billing,purchasing activities for this particular plants alone.But i need all the reporting activities to take place. In whic

  • Spreadsheet output

    Hi Friends, I want to create a report in spreadsheet format and can also be uploaded to excel file. The length of width is 200 chars. Is it possible to do it on Oracle Reports? Thanks a lot