0

I'm developing in Java but I believe I'm missing some basic knowledge besides coding about building, dependencies, projects, manifests, classpath etc.

I'm going to develop a Java tool which will read and set values from a PLC. I discovered moka7. The documentation says:

Moka7 is deployed as a set of source code classes that you can use in your Java project to communicate with S7 PLCs.

I first, downloaded moka7 and imported the Eclispe project into my IntelliJ IDEA (Windows 10). I was able to build and run the ClientDemo program. Now I wanted to do the same on linux. When I extracted moka7 and I try to run the binaries I get:

java ClientDemo
Error: Could not find or load main class ClientDemo

When I try to compile the source myself I'm getting the following:

/opt/moka7-full-1.0.2/Moka7-Eclipse/src/Moka7Demo# javac ClientDemo.java
ClientDemo.java:28: error: package Moka7 does not exist
import Moka7.*;
^
ClientDemo.java:41: error: cannot find symbol
    private static final S7Client Client = new S7Client();
                         ^
  symbol:   class S7Client
  location: class ClientDemo
ClientDemo.java:41: error: cannot find symbol
    private static final S7Client Client = new S7Client();
                                               ^
  symbol:   class S7Client
  location: class ClientDemo
ClientDemo.java:49: error: cannot find symbol
    private static int CurrentStatus = S7.S7CpuStatusUnknown;
                                       ^
  symbol:   variable S7
  location: class ClientDemo
ClientDemo.java:72: error: cannot find symbol
                System.out.println(S7.GetPrintableStringAt(Buffer, i-15, 16));
                                   ^
  symbol:   variable S7
  location: class ClientDemo
ClientDemo.java:83: error: cannot find symbol
            System.out.println(S7.GetPrintableStringAt(Buffer, Size-r, r));
                               ^
  symbol:   variable S7
  location: class ClientDemo
ClientDemo.java:112: error: cannot find symbol
        System.out.println(S7Client.ErrorText(Code));
                           ^
  symbol:   variable S7Client
  location: class ClientDemo
ClientDemo.java:117: error: cannot find symbol
        S7BlockInfo Block = new S7BlockInfo();
        ^
  symbol:   class S7BlockInfo
  location: class ClientDemo
ClientDemo.java:117: error: cannot find symbol
        S7BlockInfo Block = new S7BlockInfo();
                                ^
  symbol:   class S7BlockInfo
  location: class ClientDemo
ClientDemo.java:144: error: cannot find symbol
        IntByRef SizeRead = new IntByRef(0);
        ^
  symbol:   class IntByRef
  location: class ClientDemo
ClientDemo.java:144: error: cannot find symbol
        IntByRef SizeRead = new IntByRef(0);
                                ^
  symbol:   class IntByRef
  location: class ClientDemo
ClientDemo.java:161: error: cannot find symbol
        int Result = Client.ReadArea(S7.S7AreaDB, DBSample, 0, DataToMove, Buffer);
                                     ^
  symbol:   variable S7
  location: class ClientDemo
ClientDemo.java:172: error: cannot find symbol
        int Result = Client.WriteArea(S7.S7AreaDB, DBSample, 0, DataToMove, Buffer);
                                      ^
  symbol:   variable S7
  location: class ClientDemo
ClientDemo.java:204: error: cannot find symbol
        IntByRef PlcStatus = new IntByRef(S7.S7CpuStatusUnknown);
        ^
  symbol:   class IntByRef
  location: class ClientDemo
ClientDemo.java:204: error: cannot find symbol
        IntByRef PlcStatus = new IntByRef(S7.S7CpuStatusUnknown);
                                 ^
  symbol:   class IntByRef
  location: class ClientDemo
ClientDemo.java:204: error: cannot find symbol
        IntByRef PlcStatus = new IntByRef(S7.S7CpuStatusUnknown);
                                          ^
  symbol:   variable S7
  location: class ClientDemo
ClientDemo.java:210: error: illegal start of type
            switch (PlcStatus.Value)
                   ^
ClientDemo.java:212: error: cannot find symbol
                case S7.S7CpuStatusRun :
                     ^
  symbol:   variable S7
  location: class ClientDemo
ClientDemo.java:215: error: cannot find symbol
                case S7.S7CpuStatusStop :
                     ^
  symbol:   variable S7
  location: class ClientDemo
ClientDemo.java:248: error: cannot find symbol
                case S7.S7CpuStatusRun :
                     ^
  symbol:   variable S7
  location: class ClientDemo
ClientDemo.java:253: error: cannot find symbol
                case S7.S7CpuStatusStop :
                     ^
  symbol:   variable S7
  location: class ClientDemo
ClientDemo.java:264: error: cannot find symbol
        S7OrderCode OrderCode = new S7OrderCode();
        ^
  symbol:   class S7OrderCode
  location: class ClientDemo
ClientDemo.java:264: error: cannot find symbol
        S7OrderCode OrderCode = new S7OrderCode();
                                    ^
  symbol:   class S7OrderCode
  location: class ClientDemo
ClientDemo.java:274: error: cannot find symbol
        S7CpuInfo CpuInfo = new S7CpuInfo();
        ^
  symbol:   class S7CpuInfo
  location: class ClientDemo
ClientDemo.java:274: error: cannot find symbol
        S7CpuInfo CpuInfo = new S7CpuInfo();
                                ^
  symbol:   class S7CpuInfo
  location: class ClientDemo
ClientDemo.java:287: error: cannot find symbol
        S7CpInfo CpInfo = new S7CpInfo();
        ^
  symbol:   class S7CpInfo
  location: class ClientDemo
ClientDemo.java:287: error: cannot find symbol
        S7CpInfo CpInfo = new S7CpInfo();
                              ^
  symbol:   class S7CpInfo
  location: class ClientDemo
ClientDemo.java:318: error: cannot find symbol
        S7Szl SZL = new S7Szl(1024);
        ^
  symbol:   class S7Szl
  location: class ClientDemo
ClientDemo.java:318: error: cannot find symbol
        S7Szl SZL = new S7Szl(1024);
                        ^
  symbol:   class S7Szl
  location: class ClientDemo
ClientDemo.java:333: error: cannot find symbol
        S7Protection Protection = new S7Protection();
        ^
  symbol:   class S7Protection
  location: class ClientDemo
ClientDemo.java:333: error: cannot find symbol
        S7Protection Protection = new S7Protection();
                                      ^
  symbol:   class S7Protection
  location: class ClientDemo
ClientDemo.java:360: error: cannot find symbol
        Client.SetConnectionType(S7.OP);
                                 ^
  symbol:   variable S7
  location: class ClientDemo
ClientDemo.java:383: error: cannot find symbol
        BlockInfo(S7.Block_SFC,1); // Get SFC 1 info (always present in a CPU)
                  ^
  symbol:   variable S7
  location: class ClientDemo
33 errors

When I create a jar file using this node which refers to this blog, i can run the jar:

root@rpi:/opt# java -jar Moka7-Eclipse.jar
Usage
  client <IP> [Rack=0 Slot=2]
Example
  client 192.168.1.101 0 2
or
  client 192.168.1.101
root@rpi:/opt#

What am I doing wrong?
How to code properly in Java on linux?
Or do I just code on Windows in any IDEA and use the jar way to run on linux?

Yaerox
  • 608
  • 2
  • 11
  • 27
  • 1
    One word: classpath - In a few more words: make sure to put the Moka7 libraries onto your classpath while compiling and running your application. Read the documentation on `java` and `javac` how to do this. – Thomas Jun 29 '17 at 13:26
  • When i run `javac -cp "/opt/Moka7-Eclipse/src/Moka7/" ClientDemo.java` I'm getting the same errors. Setting CLASSPATH instead of using the -cp option doesn't change the result. – Yaerox Jun 29 '17 at 14:38
  • `src/Moka7/` indicates you're doing it wrong since `src` indicates the folder contains uncompiled source files that are no use on the classpath. When compiling on the command line you best use a build tool such as Ant, Maven or Gradle (and those 3 at least are easily integratable in most common IDEs). – Thomas Jun 29 '17 at 14:52
  • When I use the directory `bin/Moka7` as classpath the result doesn't change. – Yaerox Jun 30 '17 at 07:18

0 Answers0