
Ubuntu 20.04でEclipse IDE(2021-09(4.21.0))を設定して、RaspberryPi上のJavaアプリケーションをリモートデバッグしようとしています。複数の「チュートリアル」(リンク1、リンク2)。これらを組み合わせて、Web上でエラーメッセージを徹底的に検索することで、pom.xmlとbuild.xmlを再作成することができました。
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>
ビルド.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 を変更したくないです。
設定の最後のステップでは、リモートランチャーを動作させる必要があります。チュートリアルに従うと、設定ウィンドウは次のようになります。
接続テストの結果
ビルド プロセスは ssh 経由で接続でき、jar を配置して実行できたため、接続を確立できない理由がわかりません。接続のパラメーターは pom.xml に保存されますが、デバッグ構成のエントリが何をするのかはわかりません。RPi 上のターミナルは、ssh 接続のコマンド ライン コマンド (ssh pi@) を使用して確立できます。セキュリティ アクセスの問題はないはずです。
- 接続が pom.xml ですでに定義されているのに、リモート構成にアドレスとポートが必要なのはなぜですか?
- build.xml は 'Debug_As->RPi_Remote' (作成されたデバッグ構成) を使用して呼び出されますか?
- build.xml を呼び出してブレークポイントの使用を有効にするにはどうすればよいでしょうか?