JustADude
JustADude

Reputation: 77

AccessDeniedException when copying maven application to Raspberry Pi with ant

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.

Upvotes: 3

Views: 1197

Answers (1)

amyiris
amyiris

Reputation: 113

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.

Upvotes: 1

Related Questions