Launching applications from java code

I have found a solution to launch applications from java.I thought this will be useful for programmers who want to open a
1. Browser
2. Player
3. Files etc.
There are 2 solutions :
I)To use a known application :
eg: to open windows media player
String[] cmd = new String[3];
cmd[0] = "cmd.exe";
cmd[1] = "/C";
cmd[2] = "START MPLAYER2.exe "+mediaURL+" /PLAY /CLOSE /FULLSCREEN";
//eg: mediaURL = "\"D:/project/songs/track1.mp3\""
// /PLAY /CLOSE /FULLSCREEN this option can be used only for windows media player
// for any other application use cmd[2] as START apl.exe //apl can be any windows application
Process p = Runtime.getRuntime().exec(cmd);
II) To use a default application:
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
// url can be any url
ref: [http://forums.sun.com/thread.jspa?threadID=5203313|http://forums.sun.com/thread.jspa?threadID=5203313]
[http://www.ericphelps.com/batch/rundll/|http://www.ericphelps.com/batch/rundll/]
Edited by: veda_sishta on ? ?????, ???? ??:?? ???????
Edited by: veda_sishta on ? ?????, ???? ??:?? ???????

To post code, use the code tags -- [code]Your Code[/code] will display asYour CodeOr use the code button above the editing area and paste your code between the {code}{code} tags it generates.
And make up your mind what file type you're having a problem with. Maybe .asx doesn't have a file association on your computer.
This works just fine for .m3u:import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
public class Playlist {
   public static void main(String[] args) {
      try {
         Desktop.getDesktop().
               open(new File("E:/Music/Playlists/test.m3u"));
      } catch (IOException ex) {
         ex.printStackTrace();
}db
edit Did you try searching the net for the error you got? ("Invalid menu handle")
Edited by: Darryl.Burke

Similar Messages

  • How to find particular CRM BAPIs from Java code of ISA B2B application?

    Hi Guys,
    I am newbie in CRM ISA field. I am supporting CRM ISA 5.0 B2B application.
    Basically I had a question about how to go about finding the BAPIs which are getting called from the Java side of ISA.
    I know that the framework uses JCO connection in order to execute BAPIs in the back-end and usually these BAPIs are standard.
    So I can put a break-point on the CRM bapis and see which is called when.
    But if I want to track BAPIs from Java code, what should be my approach?
    Please help.
    Thanks!

    Hi,
    To setup the trace logs you need to use the following URL.
    https://<system domain name>:port/<application_name>/admin
    typically it should look like as below:
    https://abc.com:50001/b2b/admin
    Here there is an option to start and stop the logs and after stopping it will generate a Zip file which you need to download and from there you can easily find out the BAPI's or teh RFC calls.
    Also when you search you should alwways keep one thing mind that these FM's normally start with CRM_ISA*
    Hope it helps.
    Regards
    Sidd

  • Starting exetutable java file from java code

    Hi I was wondering how I can start a executable java file from java code?
    thanks

    Hi Mkaveli,
    Yes, it's possible. If you have a JAR executable, you've just to call the main method of its starter class. For a simple executable class, just call its main method.
    This way :
    SomeStarter.main(null); // if there's no argumentSmall precision : the executable JAR or class must be specified in the classpath of your application.

  • Problem when connecting locally to Oracle Database 10g from Java code

    Good afternoon,
    I try to connect to my local Oracle 10g from JAVA code. Could somebody tells me what are the 'values' to enter in place of 'value1, value2, value3' in the following:
    final String connectionURLThin = "jdbc:oracle:thin:@value1:value2:value3";
    I tried to put my 'user' and 'pw' credentials I used when connecting with SQL*PLUS:
    value1=my_user_name
    value2=my_pw
    value3=my_schema
    but it doest work. Besides where could have I to put the 'WORKSPACE" name?
    Thanks for any help.
    Claude
    Details:
    ERR MESSAGE----------------------
    Exception in thread "main" java.lang.NoClassDefFoundError: oracle/dms/instrument/ExecutionContextForJDBC
    at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:365)
    at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:854)
    at java.sql.DriverManager.getConnection(DriverManager.java:620)
    at java.sql.DriverManager.getConnection(DriverManager.java:200)
    at javaapplication6.ConnectionExample.driverManager(ConnectionExample.java:138)
    at javaapplication6.Main.main(Main.java:36)
    Caused by: java.lang.ClassNotFoundException: oracle.dms.instrument.ExecutionContextForJDBC
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:319)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:264)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:332)
    ... 8 more
    Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)
    ---------------------ERR MESSAGE
    JAVA code------------------it compiles but throw an error when running there -> (*)...
    final String driverClass = "oracle.jdbc.driver.OracleDriver";
    final String connectionURLThin = "jdbc:oracle:thin:@jeffreyh3:1521:CUSTDB";
    final String userID = "scott";
    final String userPassword = "tiger";
    final String queryString = "SELECT" +
    " user " +
    " , TO_CHAR(sysdate, 'DD-MON-YYYY HH24:MI:SS') " +
    "FROM dual";
    public void driverManager() {
    Connection con = null;
    Statement stmt = null;
    ResultSet rset = null;
    try {
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    con = DriverManager.getConnection(connectionURLThin, userID, userPassword); // (*) prob here
    stmt = con.createStatement ();
    rset = stmt.executeQuery(queryString);
    rset.close();
    stmt.close();
    } catch (SQLException e) {e.printStackTrace();
    --------------------JAVA JDK 1.6
    My system ------------------------
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
    PL/SQL Release 10.2.0.1.0 - Production
    CORE 10.2.0.1.0 Production
    TNS for Linux: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production

    Yes, the network connection could not be established. Like the error said.
    What you're asking about is the exact reason, but that could be any number of things and not at all related to code. You could have the wrong host, the wrong port. A firewall could be blocking the outgoing connection, a firewall could be blocking the incoming connection. Etc. etc.

  • Executing a DDL statement from java code

    Hi all,
    this is code from jdev11.1.1.3 version. I am trying to execute a DDL statement in oracle db from java code, but "ORA-00900: invalid SQL statement" error is coming.
    I am trying to create a table in same schema in same db by using 'Copy' command.
    Same DDL command is executing from sql command prompt & table is being created. Plz help me , as how to do from java?
            public String cmb_action() {
            // Add event code here...
            try {
                //getting source db connection
                InitialContext initialContext = new InitialContext();
                DataSource ds = (DataSource) initialContext.lookup("java:comp/env/jdbc/SourceConnDS");
                Connection sourceconn = ds.getConnection();
                sourceconn.setAutoCommit(false);
                String sql = "Copy from myschema/mypass@DB insert t_dept using select * from dept;"                       
                Statement stat = sourceconn.createStatement();
                stat.executeUpdate(sql);
                sourceconn.commit();
                System.out.println("done");
              catch (Exception ne) {
                // TODO: Add catch code
                ne.printStackTrace();
            return null;
        }

    I have a requirement to transfer data from one db to another db from Java Application Layer.Maybe, maye not. We get all sorts of weird "requirements" - which are nothing but thoughts or proposed solutions.
    But,
    Did the "requirement" mention whether the table existed already or not in the target database? - If not, did it tell you to create it - drop/create it?
    Did the "requirement" deliver some explanation to why this copying was neeeded? - Are we talking replication? - Or a one time cloning?
    Etc, etc,
    Personally I would always argue against a "reuirement" like that. - It just isn't the way to do it. Period.
    Regards
    Peter
    P.S: If you are satisfied with what COPY does, then you could let Java make an OS call and do it from there?

  • Create web service from java code in Jdeveloper 11.1.1.5

    I am try to create web service from java code by default it is connected to Integrated web logic server and generate a
    WSDL like this.
    http://localhost:7101/javaexcel-project1-context-root/MyWebService1Soap12HttpPort.
    please tell me how we can change this local host to our needed Host and how to deploy this web service to web logic server.

    Hi,
    Just right click on your project and deploy it to your application server (Weblogic Server (Not the Integrated server)). {Before that, you have create your Application server connection in the Jdeveloper).
    After deployment open the Admin console of the weblogic server and find your ear of the project.Click on that (Go to the "Testing tab") and you will get the "WSDL" (Concreate wsdl)  and "Test Client" of the Project.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Executing system commands like cd on Linux from Java Code

    Hi,
    I need to execute a few system commands (like cd, ls, tar, etc.,) on RedHat Linux 7.1 from Java code. Any ideas plz.
    best wishes,
    Issac

    Since this thread mentioned using the DOS START command
    from an exec(), I was wondering whether anyone else is
    seeing the odd behavior I am.
    Most of the examples showing how to read stdout and stderr
    while the process is running show simple loops that use
    getInputStream and getErrorStream and do read's until they
    get back -1. Most of these examples are insensitive to the
    state of the Process.waitFor that happens elsewhere and sort
    of rely on the -1 and the waitFor happening roughly together.
    Whenever I use this technique to launch an arbitrary DOS
    command (e.g. Runtime.exec("dir")), it works fine, and
    everything seems to terminate as expected.
    However, when my command is something like:
    Runtime.exec("cmd /c start my.bat")
    where I deliberately use the START command to fork off
    a different process, something odd happens.
    Those simple read loops get an initial burst of stdout/stderr
    bytes from the "start" part of the command. But then eventually,
    these loops do a "read" which blocks on those InputStreams. Now,
    even if my Process.waitFor returns (because the start returned
    immediately), those read loops stay blocked **until that script
    started by 'start' runs to completion**. It is like the child
    of the child is holding those streams open somehow.
    I found that by doing something like an InputStream.available() or
    a BufferedReader.ready( ) check before dropping into the read,
    and allowing the Process.waitFor completion to exit those read loops,
    them I get what I expect -- namely immediate return from the START,
    but apparently complete copies of stdout and stderr.
    Curiously, in the case where the reads block until the child process
    started by START terminates, they still don't get the child's/child's
    stdout and stderr. It is just a long duration thread block that
    yields no data.
    Can anyone explain what is happening to a
    Process.getInputStream( ).read()
    when the process immediately does a START and returns? Why would
    the read( ) stay blocked when the START finished launching a new child
    process?
    ... ron cain

  • Launching applications (use Java or is it possible in C)

    I'm a very newbie programmer in university still...
    In any case i'm only fimilar with C, C++ and Java. I'm trying to create a program that takes arguments from the command line, then launches the program identified in the command line.
    I know I can launch programs from java applications with: Runtime.getRuntime().exec
    but i'm not sure how a Java program would recieve arguments from the command line.
    I was thinking C or C++ might be more feasible, however i don't know how to lauch applications from within either language. I hear it's pretty easy to do what i'm asking with Visual Basic (but as I said I don't know it).
    Any help?
    Thanx in advance.

    but i'm not sure how a Java program would recieve
    arguments from the command line.Strange as it might sound, through the arguments of the main method:
    public static void main(String arguments[])

  • Launching applications from an applet

    How do you launch applications from an applet? For example,launch a notepad exceutable when you click on a button (an awt component)?

    Hi,
    you can launch an application from the applet using the Java RunTime environment.
    Runtime.getRuntime().exec(applicationName);
    But to do this the applet needs permissions.It should be a trusted applet.

  • Running sqlplus scripts from Java code?

    hi
    I need to programmatically run sqlplus scripts from Java code on a machine that doesn't have sqlplus installed.
    Is there any Java class library available for doing this?

    The Ant approach could probably work for me, thanks for the tip.
    The setup seems rather complex however, given the simplicity of the task. I would prefer just running a Java based SQL*Plus from in a separate process or doing this via an API that would allow me to run SQL*Plus scripts (parse script, substitute variables, run statements).
    Oracle SQL Developer v1.1 appears to include an API that does exactly this.
    The ScriptParser, Substitution and SQLPLUS classes in the oracle.dbtools.raptor.scriptrunner package (oracle.sqldeveloper.jar) seem to do just what I need based on my tests.
    Can I use these classes for this purpose in my application? Is repackaging allowed?
    Does Oracle have any plans for releasing this sort of functionality separately e.g. as part of the Instant Client?

  • Executing jar from java code, then kill parent java code

    Please suggest if there is any best way around on executing jar from java code then killing parent java code.
    a) I have desktop based java application say "Monitor.java" which runs every 5 minutes.
    b) How can I START external java application say "execute.jar" from Monitor.java THEN EXIT Monitor.java
    I tried various options using "ProcessBuilder" and calling bat file but I need Monitor (parent application to EXIT, immediately after calling child (execute.jar)
    Try1) ProcessBuilder builder = new ProcessBuilder("java -jar execute.jar");          
    Process process = builder.start();
    Try2) Runtime r = Runtime.getRuntime();
    Process p = null;
    p = r.exec(new String[] { "cmd", "/c", "start C:/temp/Test.bat" });

    I have a requirement to transfer data from one db to another db from Java Application Layer.Maybe, maye not. We get all sorts of weird "requirements" - which are nothing but thoughts or proposed solutions.
    But,
    Did the "requirement" mention whether the table existed already or not in the target database? - If not, did it tell you to create it - drop/create it?
    Did the "requirement" deliver some explanation to why this copying was neeeded? - Are we talking replication? - Or a one time cloning?
    Etc, etc,
    Personally I would always argue against a "reuirement" like that. - It just isn't the way to do it. Period.
    Regards
    Peter
    P.S: If you are satisfied with what COPY does, then you could let Java make an OS call and do it from there?

  • Generation of xml file from java code

    hi,
    I want to manipulate data in a xml file with java code.I have read data from xml file and also changed it. But i am unable to covert it again in xml file from java code. Can you please tell me how i can do this?

    Let me know which parser are you using currently for reading xml files so that i assist you. For now, you can refer to STAX Parser API under this link
    http://java.sun.com/webservices/docs/1.6/tutorial/doc/SJSXP3.html

  • How to call a VB application from Java

    Hi,
    does anybody know how to call a VB application from java.
    Would appreciate if you can provide me with an example.
    thanks

    try exec()ing the cad program with the name of the file as a command line parameter...
    Runtime.getRuntime().exec("CADProg.exe Test.prt");
    i have no clue if this will work but it seems like it's worth a try.

  • How to call a .bat file from java code?

    How to call a .bat file from java code? and how can i pass parameters to that .bat file?
    Thanks in advance

    thanks for ur reply
    but still i am getting the same error.
    I am trying to run a .bat file of together tool, my code looks like below
    import java.lang.Runtime;
    import java.lang.Process;
    import java.io.File;
    class SysCall{
         public static void main(String args[]){
              String cmd="D://Borland//Together6.2//bin//Together.bat -script:com.togethersoft.modules.qa.QA -metrics out:D://MySamples//Metrics// -fmt:html D://Borland//Together6.2//samples//java//CashSales//CashSales.tpr";
              //String path="D://Borland//Together6.2//bin//Together.bat ";
              Runtime r= Runtime.getRuntime(); //Declare the system call
              try{
                   System.out.println("Before batch is called");
                   Process p=r.exec(cmd);
                   System.out.println(" Exit value =" + p.exitValue());
                   System.out.println("After batch is called");
              /*can produce errors which must be caught*/
              catch(Exception e) {
                   e.printStackTrace();
                   System.out.println (e.toString());
    I am getting the below exception
    Before batch is called
    java.lang.IllegalThreadStateException: process has not exited
    at java.lang.Win32Process.exitValue(Native Method)
    at SysCall.main(SysCall.java:17)
    java.lang.IllegalThreadStateException: process has not exited

  • How to modify an existing xml file from java code.

    Hi
    I have worked on creating a new xml file from java code using xmlbeans.But if i try to modify an already existing file using java code I am unable to get errorfree xmlfile.
    For example if xml file(studlist.xml) is as below:
    <?xml version="1.0" encoding="UTF-8"?>
    <StudentList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="D:\kchaitanya\xmlprac1\abc\Studlist.xsd">
         <Student>
              <Name>ram</Name>
              <Age>27</Age>
         </Student>
    <Student>
              <Name>sham</Name>
              <Age>26</Age>
         </Student>
    </StudentList>
    Now suppose i have set name to victor using student.setName,
    and set age to 20 using setAge from javacode,
    the new xml file is as follows:
    <?xml version="1.0" encoding="UTF-8"?>
    <StudentList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="D:\kchaitanya\xmlprac1\abc\Studlist.xsd">
         <Student>
              <Name>ram</Name>
              <Age>27</Age>
         </Student>
    <Student>
              <Name>sham</Name>
              <Age>26</Age>
         </Student>
    </StudentList>
    <Student>
              <Name>victor</Name>
              <Age>20</Age>
         </Student>
    As observed this is not a valid xml file.But how can i modify without any errors?

    I know it's an old post, but I found this while doing a google search for something else, and don't like to leave it un-aswered
    Just in case anyone has a similar problem... In this case the new elements have been appended outside of the root element
    What you need to do is first get the root element and then append the new children to that, there are several ways of getting the root element, which depend on what you want to do with the elements you get back here's a simple (incomplete) way.
    // gets the root element of the specified file (code not shown)
    Element rootElement= new SAXReader().read(file).getRootElement();Then just append the new elements as below (this is non-generic code and would need to be modified for your situation)
    // write a new student element
    Element student = document.createElement("Student");  // creates the new student
    rootElement.appendChild(student); // ***appends it to the root element***
    Element name = document.createElement("Name"); // creates the name element
    name.appendChild(document.createTextNode("Fred")); // adds the name text to the name element
    student.appendChild(name); // appends the name to the student
    Element age= document.createElement("Age"); // creates the age element
    age.appendChild(document.createTextNode("26")); // adds the age text to the age element
    student.appendChild(age); // appends the name to the studentThen flush ya buffers or whatever and write the file
    Edited by: Dream-Scourge on Apr 23, 2008 11:10 AM

Maybe you are looking for

  • Status bar has disappeared

    Hi. The status bar which usually appears at the bottom of the Adobe Reader screen has disappeared. It is the one with the page numbers, reader view and various other useful bits of information. I am definitely not in full screen mode. Any help greatl

  • Urgent...Consignment fill up error

    Dear All, I am new to the area of consignment. I am implementing consignment process from scratch. I tried creating a Consignment fill up and got the following error. Please advise me in detail ERROR: Consignment orders must be created from notificat

  • Time Machin does not backup automatically

    First backup worked fine, and also the subsequent hourly automatic backups. But then the automatic backup stopped, and it does no longer show the next backup time. I can again manually backup but the automatic backup does not work any longer. Who has

  • Edits missing in LR 6

    Hi, Just realised that all my edits which were in LR 5, are missing in LR 6. All the xmp files are in the folders with the photos. I have just loaded a back up catalog from before the update to to LR 6, but no edits present. any ideas? thanks, Paul

  • My Black Berry Desk Top Manager doesn't work on my computer help!

    On March 6 I took my BlackBerry® Style™ 9670 smartphone  in for software issues after tech support did a hard reset on the device. I went home to back up my information and was unsuccessful. The connection failed this is the first time that the desk