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
Tariff Impact Update Learn more

Was this information helpful?

Yes

No