gpt4 book ai didi

java - Lego Mindstorms ev3 leJOS 在编译期间查找库

转载 作者:太空宇宙 更新时间:2023-11-04 07:09:59 25 4
gpt4 key购买 nike

我尝试在 eclipse 中设置 leJOS,并从 git 导入所有库,但使用 ant 构建进行编译时遇到问题。这是我的构建文件:

<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="SimonSais" basedir="." default="copy">
<property name="source.dir" value="src"/>
<property name="lib.dir" value="../ev3/ev3classes"/>
<property name="class.dir" value="build"/>
<property name="jar.dir" value="dist"/>
<property name="main-class" value="SimonSais"/>
<property name="lejos.home" value="/home/root/lejos"/>
<property name="ev3.host" value="10.0.1.1"/>

<path id="libraries.path">
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
</path>

<target name="clean" description="delete old files">
<delete dir="${class.dir}"/>
<delete dir="${jar.dir}"/>
</target>

<target name="compile" description="build class files" depends="clean">
<mkdir dir="${class.dir}"/>
<javac srcdir="${source.dir}" destdir="${class.dir}">
<classpath refid="libraries.path"/>
</javac>
</target>

<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${class.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
<attribute name="Class-Path" value="${lejos.home}/lib/ev3classes.jar ${lejos.home}/libjna/usr/share/java/jna.jar"/>
</manifest>
</jar>
</target>

<target name="copy" depends="jar">
<scp todir="root:@${ev3.host}:/home/lejos/programs/" trust="true">
<fileset file="${jar.dir}/${ant.project.name}.jar"/>
</scp>
</target>

但是当我尝试运行时,它说 ..ev3/ev3classes 不存在。这是由工作区中引用的类引起的,但实际上并未复制到那里。不过,这就是它所说的这样做的方式。

他们还说您可能需要更改“lib.dir”,但我不知道将其设置到哪里。我尝试将其设置为类实际所在的位置(C:\Users\soc0001\git\ev3\ev3classes),但它给了我编译错误,说它找不到包:

Compiling 1 source file to D:\School\Programs\Lego Mindstorms\SimonSais\build
[javac] D:\School\Programs\Lego Mindstorms\SimonSais\src\SimonSais.java:1: error: package lejos.hardware does not exist
[javac] import lejos.hardware.Button;
[javac] ^
[javac] D:\School\Programs\Lego Mindstorms\SimonSais\src\SimonSais.java:2: error: package lejos.hardware.lcd does not exist
[javac] import lejos.hardware.lcd.LCD;
[javac] ^
[javac] D:\School\Programs\Lego Mindstorms\SimonSais\src\SimonSais.java:7: error: cannot find symbol
[javac] LCD.clear();
[javac] ^
[javac] symbol: variable LCD
[javac] location: class SimonSais
[javac] D:\School\Programs\Lego Mindstorms\SimonSais\src\SimonSais.java:8: error: cannot find symbol
[javac] LCD.drawString("First EV3 Program", 0, 5);
[javac] ^
[javac] symbol: variable LCD
[javac] location: class SimonSais
[javac] D:\School\Programs\Lego Mindstorms\SimonSais\src\SimonSais.java:9: error: cannot find symbol
[javac] Button.waitForAnyPress();
[javac] ^
[javac] symbol: variable Button
[javac] location: class SimonSais
[javac] D:\School\Programs\Lego Mindstorms\SimonSais\src\SimonSais.java:10: error: cannot finsymbol
[javac] LCD.clear();
[javac] ^
[javac] symbol: variable LCD
[javac] location: class SimonSais
[javac] D:\School\Programs\Lego Mindstorms\SimonSais\src\SimonSais.java:11: error: cannot find symbol
[javac] LCD.refresh();
[javac] ^
[javac] symbol: variable LCD
[javac] location: class SimonSais

我不确定构建文件究竟是什么样子,以及将 lib.dir 设置为什么。有人可以给我举个例子吗?

最佳答案

编译目标仅引用libraries.path作为类路径:

<classpath refid="libraries.path"/>

确保正确的 jar 依赖项位于该路径中(即位于 lib.dir 中)。

OP user2971198确认in the comments :

I simply forgot (although it is never mentioned) to build the projects that were imported with their ant scripts first.
That's why it didn't find any jar [(in lib.dir)].

关于java - Lego Mindstorms ev3 leJOS 在编译期间查找库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20795629/

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