1

I am trying to configure the Eclipse IDE (2021-09 (4.21.0)) on Ubuntu 20.04 to remote debug java applications on a RaspberryPi. I followed multiple 'tutortials' (link1, link2). With the combination of both and intensive search for error messages on the web I was able to recreate the pom.xml and the build.xml

pom.xml

<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org

/2001/XMLSchema-instance"
  xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>pi</groupId>
  <artifactId>hello</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>hello</name>
  <url>http://maven.apache.org</url>

<build>
      <plugins>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
               <archive>
                  <manifest>
                     <mainClass>pi.hello.App</mainClass>
                  </manifest>
               </archive>
            </configuration>
         </plugin>
      </plugins>
   </build>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>6</maven.compiler.source>
    <maven.compiler.target>1.6</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="hello" default="remote-run" basedir="."
    xmlns:artifact="antlib:org.apache.maven.artifact.ant">

    <!-- Setup RASPBERRY PI properties -->
    <property name="raspberrypi" value="192.168.4.2" />
    <property name="raspberryfolder" value="~" />
    <property name="username" value="pi" />
    <property name="password" value="raspberry" />

    <!--
    <path id="maven-ant-tasks.classpath" path="${ant.libs.dir}/maven-ant-tasks-2.1.3.jar" />
    <typedef 
        resource="org/apache/maven/artifact/ant/antlib.xml"
        uri="antlib:org.apache.maven.artifact.ant"
        classpathref="maven-ant-tasks.classpath" />

        
    <path id="maven-ant-tasks.classpath" path="lib/maven-ant-tasks-2.1.3.jar" />
    <typedef 
        resource="org/apache/maven/artifact/ant/antlib.xml" 
        uri="antlib:org.apache.maven.artifact.ant" 
        classpathref="maven-ant-tasks.classpath" />
    -->

    <!-- Add maven install target to be run before deploy -->
        
    <target name="maven-install"> 
        <artifact:mvn pom="pom.xml"> 
            <arg value="install"/> 
        </artifact:mvn> 
    </target> 

    <!-- Locate the prokect jar and transfer via scp to RASPBERRY PI -->
    <target name="transfer" depends="maven-install">
        <first id="jars">
            <!--
            <fileset dir="target" includes="**/*-SNAPSHOT-jar-with-dependencies.jar" />
            -->
            <fileset dir="target" includes="**/*.jar" />
        </first>
        <pathconvert pathsep="," property="jar.path" refid="jars" />
        <basename file="${jar.path}" property="jar.filename" />
        <echo>">>> Found application ${jar.path}"</echo>

        <echo>">>> Copying application to ${raspberrypi}:${raspberryfolder}/${jar.filename}"</echo>
        <scp 
            localfile="${jar.path}" 
            todir="${username}:${password}@${raspberrypi}:${raspberryfolder}" 
            trust="true" />

    </target>
        
    <!-- Run java -->
    <target name="remote-run" depends="transfer">   
        <echo>">>> Starting ${raspberrypi}:${raspberryfolder}/${jar.filename}"</echo>

        <sshexec 
            host="${raspberrypi}" 
            username="${username}" 
            password="${password}" 
            trust="true" 
            failonerror="true" 
            usepty="true" 
            command="java -jar ${jar.filename}" />
    </target>
    
    <!-- Run java in debug mode and keep waiting for execution -->
    <target name="remote-debug" depends="transfer"> 
        <echo>">>> Starting ${raspberrypi}:${raspberryfolder}/${jar.filename} in debug mode"</echo>
        <sshexec 
            host="${raspberrypi}" 
            username="${username}" 
            password="${password}" 
            trust="true" 
            failonerror="true" 
            usepty="true" 
            command="java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=y -jar ${jar.filename}" />
    </target>
</project>

The output when the build.xml is compiled using

Run As -> Ant build

results in

maven-install:
[artifact:mvn] [INFO] Scanning for projects...
[artifact:mvn] [INFO] ------------------------------------------------------------------------
[artifact:mvn] [INFO] Building hello
[artifact:mvn] [INFO]    task-segment: [install]
[artifact:mvn] [INFO] ------------------------------------------------------------------------
[artifact:mvn] [INFO] [resources:resources]
[artifact:mvn] [INFO] Using 'UTF-8' encoding to copy filtered resources.
[artifact:mvn] [INFO] skip non existing resourceDirectory /media/stefan/DATA/Electronics/java/hello/src/main/resources
[artifact:mvn] [INFO] [compiler:compile]
[artifact:mvn] [INFO] Nothing to compile - all classes are up to date
[artifact:mvn] [INFO] [resources:testResources]
[artifact:mvn] [INFO] Using 'UTF-8' encoding to copy filtered resources.
[artifact:mvn] [INFO] skip non existing resourceDirectory /media/stefan/DATA/Electronics/java/hello/src/test/resources
[artifact:mvn] [INFO] [compiler:testCompile]
[artifact:mvn] [INFO] Nothing to compile - all classes are up to date
[artifact:mvn] [INFO] [surefire:test]
[artifact:mvn] [INFO] Surefire report directory: /media/stefan/DATA/Electronics/java/hello/target/surefire-reports
[artifact:mvn] -------------------------------------------------------
[artifact:mvn]  T E S T S
[artifact:mvn] -------------------------------------------------------
[artifact:mvn] Running pi.hello.AppTest
[artifact:mvn] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.021 sec
[artifact:mvn] Results :
[artifact:mvn] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[artifact:mvn] [INFO] [jar:jar]
[artifact:mvn] [INFO] [install:install]
[artifact:mvn] [INFO] Installing /media/stefan/DATA/Electronics/java/hello/target/hello-0.0.1-SNAPSHOT.jar to /home/stefan/.m2/repository/pi/hello/0.0.1-SNAPSHOT/hello-0.0.1-SNAPSHOT.jar
[artifact:mvn] [INFO] ------------------------------------------------------------------------
[artifact:mvn] [INFO] BUILD SUCCESSFUL
[artifact:mvn] [INFO] ------------------------------------------------------------------------
[artifact:mvn] [INFO] Total time: 1 second
[artifact:mvn] [INFO] Finished at: Tue Nov 30 17:12:36 CET 2021
[artifact:mvn] [INFO] Final Memory: 18M/70M
[artifact:mvn] [INFO] ------------------------------------------------------------------------
transfer:
     [echo] ">>> Found application /media/stefan/DATA/Electronics/java/hello/target/hello-0.0.1-SNAPSHOT.jar"
     [echo] ">>> Copying application to 192.168.4.2:~/hello-0.0.1-SNAPSHOT.jar"
      [scp] Connecting to 192.168.4.2:22
      [scp] done.
remote-run:
     [echo] ">>> Starting 192.168.4.2:~/hello-0.0.1-SNAPSHOT.jar"
  [sshexec] Connecting to 192.168.4.2:22
  [sshexec] cmd : java -jar hello-0.0.1-SNAPSHOT.jar
  [sshexec] Hello World!
  [sshexec] 
BUILD SUCCESSFUL
Total time: 6 seconds

Every other combination of plugins or artifacts for the default build.xml of the maven project (created via wizard) did produce error because of wrong versions in some plugins (even that the correct version is installed

Error resolving version for 'org.apache.maven.plugins:maven-resources-plugin': Plugin requires Maven version 3.0

current version

mvn -version
Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 11.0.11, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.11.0-40-generic", arch: "amd64", family: "unix"

In order to start working I would rather not change my current build.xml.

For the last step in the configuration I need to get the remote launcher working. Following the tutorials the configuration window looks like debug_config

Testing the connection results in

error_vm

Since the build process was able to connect via ssh, place and run the jar I do not know why the connection can not be established. The parameter for the connection are stored in the pom.xml I am not sure what the entries in the debug configuration do. A terminal on the RPi can be established using the command line commands for the ssh-connection (ssh pi@). There should not be a security access problem.

  1. Why does the remote configuration need the address, port when the connection is already defined in the pom.xml?
  2. Is the build.xml even called using 'Debug_As->RPi_Remote' (the created debug configuration)?
  3. How can I call the build.xml and enable the use of breakpoints?

0

You must log in to answer this question.

Browse other questions tagged .