Starting Guide
Starting Guide
0
Starting Guide
Guide
Starting
-
SDK
Java
UA
OPC
Prosys
Table of Contents
1. Tools for Java Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1. Integrated Development Environment (IDE) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2. Java Runtime Environment (JRE) and Java Development Kit (JDK). . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3. Build and dependency management tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2. Using the Prosys OPC UA Java SDK in Eclipse IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.1. Creating New Java Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.2. Importing the Prosys OPC UA Java SDK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.3. Adding Javadoc documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
This guide is intended for new Java developers and covers the basics of setting up a new Java project in
the Eclipse IDE in order to start using the Prosys OPC UA Java SDK.
This is a basic guide. It is a trade-off between doing things quick and easy versus
doing things according to what is considered to be modern Java development.
This guide uses Eclipse as the example IDE. It is free and open source. The reason for selecting Eclipse is
that the writers of this guide have the most experience with it.
Other popular IDEs are the IntelliJ IDEA and the NetBeans IDE.
There are multiple JRE/JDK vendors to choose from. We generally recommend Oracle or OpenJDK. The
Oracle Java can be downloaded from
http://www.oracle.com/technetwork/java/javase/downloads/index.html. OpenJDK is typically available
for Linux distro’s package managers.
This guide expects you to have Java version 8 runtime. Therefore, if you do
download the Oracle one from the above link, please select a Java SE 8uXX JDK
(where XX is the update number). It includes the JRE.
The Prosys OPC UA Java SDK (3.0.0) is expected to work on Java versions from 6 to
8. At the moment of writing this guide, later versions of Java are not tested to work
with the Prosys OPC UA Java SDK. Java is in general a very backwards compatible
language, but in version 9 it introduced some compatibility-breaking changes.
After obtaining and installing a JDK, you should be able to run java -version on the command line. You
may skip checking this and just try to start Eclipse. This is the first thing to try, because Eclipse is a Java
program by itself. Eclipse requires that the bin folders of the installed JRE and JDK are placed in your
PATH or alternatively configured in the 'eclipse.ini' file (in the Eclipse installation folder).
1
This tutorial uses Java version 8 because it is required by the latest Eclipse version
as of the writing of this guide. This does also mean that by default your
This guide ignores this part and instead stops at the point where you can run the samples provided in
the SDK package from Eclipse. However, learning to use these tools is eventually very recommended
(they all have their advantages and disadvantages and having a basic understanding of all of them is
beneficial).
• Apache Maven
• Gradle
• Apache Ant (sometimes combined with Apache Ivy)
Oxygen.2 Release (4.7.2) and the steps might be slightly different on other
versions.
2
Figure 1. New Java Project.
3. The Use default location checkbox is enabled by default and points to the Eclipse workspace, which
is suitable for this tutorial. You may untick the checkbox and define another location where the
project will be saved.
3
Figure 2. Settings for new Java project.
1. Open the project folder (either in Eclipse or your operating system’s file manager).
2. Create two new folders called lib and javadoc at the project root folder. A src folder should already
be created, but if not, then create it as well.
4
Figure 3. Project root folder.
3. Copy the contents of the samples/sampleconsoleserver (available only with the server version of the
SDK) and samples/sampleconsoleclient of the SDK package into the src folder (no need to copy the
.bat and .sh files). You can replace the files in the destination if prompted.
4. Copy the contents of the lib folder of the SDK package into the lib folder of the project.
5. Copy the contents of the javadoc folder of the SDK package into the javadoc folder of the project.
6. If you did the operations in your operating system’s file manager, refresh the project in Eclipse (by
selecting it and either pressing F5 or via right-click menu).
5
Figure 4. View of the Eclipse Package Explorer after adding the required files to the project folder and
refreshing the project.
7. Add each file from the lib folder to the projects Build Path (select one or more and right-click and
click Build Path ¬ Add to Build Path).
6
Figure 5. Add library to Build Path.
8. Finally, you can expand the src folder and find the SampleConsoleClient and SampleConsoleServer
Java classes. You can run these by right-clicking them and selecting Run As ¬ Java Application.
7
Figure 6. Running the sample application.
The following steps are only for the Source version of the SDK:
9. Find the source files for the SDK and the OPC UA Java Stack in the 'sources' folder of the SDK
distribution package. They are provided as compressed '*-sources.zip' files.
10. Create a new folder named 'sources' in the root of the project folder, similarly to the 'lib' and
'javadoc' folders created previously.
11. Copy the source files from the SDK distribution package into the new 'sources' folder.
12. Refresh the project in Eclipse (by selecting it and either pressing F5 or via right-click menu).
13. Right-click on the library for the SDK or the Stack in the Referenced Libraries section of the Eclipse
Package Explorer. The prosys-opc-ua-java-sdk-client-server-evaluation-3.x.x-xxx.jar and opc-ua-stack-
1.x.xxx-xxx.jar are the libraries for the SDK and the Stack respectively.
14. From the pop-up menu select Properties.
8
18. From the pop-up window locate and expand the 'sources' folder.
19. Select the .zip file corresponding to the name of the library you are configuring.
20. Click OK in the pop-up.
22. Perform this operation for both the SDK and Stack libraries.
1. Right-click on the library for the SDK or the Stack in the Referenced Libraries section of the Eclipse
Package Explorer. The prosys-opc-ua-java-sdk-client-server-evaluation-3.x.x-xxx.jar and opc-ua-stack-
1.x.xxx-xxx.jar are the libraries for the SDK and the Stack respectively.
2. From the pop-up menu select Properties.
9
3. Click Javadoc Location from the left-side menu.
7. Locate the javadoc folder under the root folder (named according to what you defined in the
beginning).
8. Inside the javadoc folder, you should click the Javadoc file that should be associated to the current
library, i.e. opc-ua-stack-1.x.xxx-xxx-javadoc.zip for the Stack and prosys-opc-ua-java-sdk-client-server-
evaluation-3.x.x-xxx-javadoc.zip for the SDK.
9. Click OK.
10. Repeat the same procedure for both the SDK and the Stack libraries.
10
The project structure created here is suited for testing out the SDK. In general,
more advanced development typically uses some build tool, which usually follows
some conventions on how the project folders should be organized. In addition, the
libraries are typically not within a project folder, but instead they are linked by the
dependency management tool (which is typically also the build tool). Furthermore,
they also typically link the Javadocs from the same place where they link the
libraries. The reason for this is that typically the project folder is in a version
control system (e.g. Git) and putting binaries to it is not generally seen as a good
idea (size grows large when new versions of libraries are released). Instead the
library and Javadoc dependencies are declared in a file for the dependency
management tool.
11