3

I'm trying to run my Maven program from my Windows PC on my Raspberry Pi through Ant in Eclipse. Full disclosure, i have basically no experience with Raspberry, Linux and Ant. I was following this guide and the code is from there.

The code for the build.xml

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

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

<!--     <path id="maven-ant-tasks.classpath" path="${ant.libs.dir}/maven-ant-tasks-2.1.3.jar" /> -->



<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" />


    <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 project 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 project builds succesfully, but fails at the transfer with the following message:

transfer:
     [echo] ">>> Found application "
     [echo] ">>> Copying application to censored_IP:~/Der_HFBot"
      [scp] Connecting to censored_IP:22

BUILD FAILED
C:\Users\Paddy\Desktop\Google Drive\Telegram Bots\Der_HFBot\build.xml:47: java.nio.file.AccessDeniedException: C:\Users\Paddy\Desktop\Google Drive\Telegram Bots\Der_HFBot

Total time: 3 seconds

I've tried running Eclipse as admin and moving the project to a folder outside of Drive.

edit: It seems like ${jar.path} doesn't return a path? It's supposed to echo "Found application ${jar.path}" but in the console it returns "Found application ".

edit2: When i enter the path manually the transfer works, so the problem is in the code that finds the jar path. Since this is a personal project i have no problem enterin the path manually, if your fingers are itching to fix the code feel free though.

JustADude
  • 77
  • 6

1 Answers1

1

AccessDeniedExceptions usually come from a lack of file permission. Use chmod 777 filename on both the program itself and all other applicable files, this will allow everything to read/write/execute on these files, so make sure you have a safe development environment.

amyiris
  • 103
  • 2
  • 16
  • My bad, i didn't make this clear enough. I'm writing the program and trying to access the Raspberry through a windows PC. So all the files are on the windows PC still. – JustADude Dec 28 '19 at 19:30
  • 1
    Do you have openssh-server properly set up? This includes setting it up, and adding port forwarding in your router. – amyiris Dec 28 '19 at 19:32
  • I can access the Raspberry through a ssh connection in the console from my PC, yes. I've added the port forwarding manually now but nothing changed – JustADude Dec 28 '19 at 19:45
  • 1
    Try using `scp` to transfer a file to the Raspberry, give me the output. – amyiris Dec 28 '19 at 19:47
  • I just realized when i enter the path to the jar manually the transfer works, so the problem is in the code that finds the jar path. Since this is a personal project i have no problem entering the path manually, thanks for your help though – JustADude Dec 28 '19 at 19:56
  • 1
    Awesome @JustADude! If you need me to help edit the pathfinding code later, I'd be happy to help. Otherwise, a answer accept/upvote would be greatly appreciated, but not necessary. If you have more questions my Discord is ProgrammerPlays#8264, which is probably the quickest way to contact me since I don't read StackOverflow chat or emails ._. – amyiris Dec 28 '19 at 19:58