22-Native-Apps

22-Native-Apps - 2006 Marty Hall Invoking Native...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
J2EE Training: http://courses.coreservlets.com/ Servlets, JSP, Struts, JSF, Hibernate, AJAX, Java 5, etc. Developed and taught by well-known author and developer. At public venues or onsite at your location. © 2006 Marty Hall Invoking Native Applications from Java Developed and taught by well-known author and developer. At public venues or onsite at your location. © 2006 Marty Hall For live Java training, please see training courses at http://courses.coreservlets.com/. Servlets, JSP, Struts, JSF, AJAX, Java 5, etc. Taught by the author of Core Servlets and JSP , More Servlets and JSP , and this tutorial. Available at public venues, or customized versions can be held on-site at your organization.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
J2EE training: http://courses.coreservlets.com Agenda Integration options Invoking native programs Calling native functions J2EE training: http://courses.coreservlets.com Linking to Programs in Other Languages Invoke the program at the OS level Use ProcessBuilder to invoke a random program, pass in arguments via the standard input, and read results via the standard output Pros: easy to set up, can call arbitrary programs Cons: limited argument passing, slow: big startup overhead Use sockets Use regular sockets to exchange data Pros: fast if on same machine, can split in future Cons: work to set up on both ends, need to parse data Use native methods Use JNI to link C and Java code Pros: fast: suitable for fine-grained interactions Cons: lots of work to set up, requires C, C++, or assembly
Background image of page 2
J2EE training: http://courses.coreservlets.com Invoking Native Programs 1. Create a ProcessBuilder ProcessBuilder builder = new ProcessBuilder("program", "argument"); Note that environment variables such as PATH are not automatically set, so you should use full path to program 2. Start the process builder.start(); Options Wait for process to terminate Process p = builder.start(); int returnCode = p.waitFor(); Examine return code later int returnCode = p.exitCode(); J2EE training: http://courses.coreservlets.com Example: Starting Internet Explorer Full path to Internet Explorer: C:\Program Files\Internet Explorer\iexplore.exe
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 12

22-Native-Apps - 2006 Marty Hall Invoking Native...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online