Eclipse IDE를 사용하여 Raspberry Pi에서 Java Maven 프로젝트를 원격 디버깅: 핸드셰이크 오류

Eclipse IDE를 사용하여 Raspberry Pi에서 Java Maven 프로젝트를 원격 디버깅: 핸드셰이크 오류

RaspberryPi에서 Java 애플리케이션을 원격 디버그하기 위해 Ubuntu 20.04에서 Eclipse IDE(2021-09(4.21.0))를 구성하려고 합니다. 나는 여러 '튜토리얼'을 따랐습니다(링크1,링크2). 두 가지를 조합하고 웹에서 오류 메시지를 집중적으로 검색하여 pom.xml과 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>

다음을 사용하여 build.xml을 컴파일할 때의 출력

다음으로 실행 -> Ant 빌드

결과

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

Maven 프로젝트(마법사를 통해 생성됨)의 기본 build.xml에 대한 다른 모든 플러그인 또는 아티팩트 조합은 일부 플러그인의 잘못된 버전으로 인해 오류를 생성했습니다(올바른 버전이 설치된 경우에도 마찬가지).

'org.apache.maven.plugins:maven-resources-plugin' 버전 확인 중 오류 발생: 플러그인에는 Maven 버전 3.0이 필요합니다.

현재 버전

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"

작업을 시작하려면 현재 build.xml을 변경하지 않는 것이 좋습니다.

구성의 마지막 단계에서는 원격 실행 프로그램을 작동시켜야 합니다. 튜토리얼에 따르면 구성 창은 다음과 같습니다. debug_config

연결 결과 테스트

error_vm

빌드 프로세스가 SSH를 통해 연결할 수 있었기 때문에 jar를 배치하고 실행할 수 있었기 때문에 연결을 설정할 수 없는 이유를 모르겠습니다. 연결에 대한 매개변수는 pom.xml에 저장됩니다. 디버그 구성의 항목이 무엇을 하는지 잘 모르겠습니다. RPi의 터미널은 ssh 연결(ssh pi@)에 대한 명령줄 명령을 사용하여 설정할 수 있습니다. 보안 접근 문제가 없어야 합니다.

  1. pom.xml에 연결이 이미 정의되어 있는데 원격 구성에 주소, 포트가 필요한 이유는 무엇입니까?
  2. build.xml이 'Debug_As->RPi_Remote'(생성된 디버그 구성)를 사용하여 호출됩니까?
  3. build.xml을 호출하고 중단점을 사용하려면 어떻게 해야 합니까?

관련 정보