gpt4 book ai didi

java - 使用 Ant 将 Maven 应用程序复制到 Raspberry Pi 时出现 AccessDeniedException

转载 作者:行者123 更新时间:2023-12-05 06:21:58 25 4
gpt4 key购买 nike

我正在尝试通过 Eclipse 中的 Ant 从我的 Windows PC 在我的 Raspberry Pi 上运行我的 Maven 程序。完全公开,我基本上没有使用 Raspberry、Linux 和 Ant 的经验。我在关注 this guide代码来自那里。

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>

项目构建成功,但在传输时失败并显示以下消息:

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

我试过以管理员身份运行 Eclipse 并将项目移动到 Drive 之外的文件夹。

编辑:${jar.path} 似乎没有返回路径?它应该回显“找到的应用程序 ${jar.path}”,但在控制台中它返回“找到的应用程序”。

edit2:当我手动输入路径时,传输有效,所以问题出在找到 jar 路径的代码中。由于这是一个个人项目,我可以手动输入路径,如果您的手指很想修复代码,请随意。

最佳答案

AccessDeniedException 通常是由于缺少文件权限。在程序本身和所有其他适用文件上使用 chmod 777 filename,这将允许对这些文件进行读/写/执行,因此请确保您有一个安全的开发环境。

关于java - 使用 Ant 将 Maven 应用程序复制到 Raspberry Pi 时出现 AccessDeniedException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59514047/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com