Executing Third Party Java Runtime in LabVIEW

Updated Oct 24, 2023

Environment

Software

  • LabVIEW

Other

  • Java Runtime Environment (JRE)

This article shows you how to run a third party Java runtime package in LabVIEW. This article will be using PDFBox standalone Java package as an example that can be obtained here. Basic knowledge of Java programming language is required to read and use command line tools.

Required Software

Running Java runtime requires Java Runtime Environment (JRE). Proceed to link below to download from Java's download page. Command Line Tool

Most third party Java runtime has command lines that can be used to execute specific functions. Please refer to Java runtime documentation that you are using and take note of the command lines that you would like to use. The command line for PDFBox standalone Java package can be checkedΒ hereΒ and this article will be usingΒ 𝚓𝚊𝚟𝚊 -𝚓𝚊𝚛 𝚙𝚍𝚏𝚋𝚘𝚡-𝚊𝚙𝚙-𝟸.𝚢.𝚣.𝚓𝚊𝚛 𝙴𝚡𝚝𝚛𝚊𝚌𝚝𝚃𝚎𝚡𝚝 [𝙾𝙿𝚃𝙸𝙾𝙽𝚂] <𝚒𝚗𝚙𝚞𝚝𝚏𝚒𝚕𝚎> [𝚃𝚎𝚡𝚝 𝚏𝚒𝚕𝚎]Β functionΒ to extract text from a PDF file as an example.

Programming in LabVIEW

This section will cover what functions to use in LabVIEW.
  1. Identify the input and output required from your command line.
  2. Based on the information above, create the necessary control and/or indicator in LabVIEW.
  3. After creating the necessary control and/or indicator, use theΒ Format into String Function to format the inputs to string and Scan from String Function to obtain the output. Please make sure you are using the correct Format Specifier Syntax to convert to and from string.Β 
  4. Running Java runtime requires LabVIEW to access command prompt. Therefore, place aΒ System Exec.viΒ in your block diagram and wire in your command line, standard input and standard output.
  5. Run your VI and obtain your output.

​​​​​Result

A successful execution of Java runtime will not produce any error message in command prompt and the intended output is produced.

Example

This example will be using PDFbox Standalone Java Package which can be obtained on the link above.
  1. The command line needed to change PDF to text file isΒ 𝚓𝚊𝚟𝚊 -𝚓𝚊𝚛 𝚙𝚍𝚏𝚋𝚘𝚡-𝚊𝚙𝚙-𝟸.𝚢.𝚣.𝚓𝚊𝚛 𝙴𝚡𝚝𝚛𝚊𝚌𝚝𝚃𝚎𝚡𝚝 [𝙾𝙿𝚃𝙸𝙾𝙽𝚂] <𝚒𝚗𝚙𝚞𝚝𝚏𝚒𝚕𝚎> [𝚃𝚎𝚡𝚝 𝚏𝚒𝚕𝚎].
  2. This command line requires three inputs which are 𝚙𝚍𝚏𝚋𝚘𝚡-𝚊𝚙𝚙-𝟸.𝚢.𝚣.𝚓𝚊𝚛, <𝚒𝚗𝚙𝚞𝚝𝚏𝚒𝚕𝚎>Β and [𝚃𝚎𝚡𝚝 𝚏𝚒𝚕𝚎].Β 𝚙𝚍𝚏𝚋𝚘𝚡-𝚊𝚙𝚙-𝟸.𝚢.𝚣.𝚓𝚊𝚛Β is the directory to the Java runtime, <𝚒𝚗𝚙𝚞𝚝𝚏𝚒𝚕𝚎>Β Β is the directory for the PDF file and [𝚃𝚎𝚡𝚝 𝚏𝚒𝚕𝚎] is the directory to the output text file.
  3. Create three directory control path and wire into Format into String Function.
  4. Change the command line above intoΒ 𝚌𝚖𝚍 /𝚔 𝚓𝚊𝚟𝚊 -𝚓𝚊𝚛 %𝚜 𝙴𝚡𝚝𝚛𝚊𝚌𝚝𝚃𝚎𝚡𝚝 %𝚜 %𝚜Β as a format string where 𝚌𝚖𝚍 /𝚔 is a command that ensures the command prompt stays open after executing, first %𝚜 is the string format specifier for the Java runtime directory, second %𝚜 and third %𝚜 is the string format specifier to the PDF directory and text file directory.
  5. Wire all connection and run the VI. Please refer to picture below on the wiring diagram.
  6. PDF to Text File