我如何以普通用户身份使用 ant 进行构建(不需要 sudo)COOJA
How can I build with ant as a normal user (no need for sudo) COOJA
最近我开始使用 contiki-ng 从事物联网项目。
我遇到的问题是当我尝试 运行 cooja 时:
$ ant run
在 ~/contiki-ng/tools/cooja
之下。
构建失败
$ ant run
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
Buildfile: /home/user/contiki-ng/tools/cooja/build.xml
init:
compile:
copy configs:
jar_cooja:
[jar] Building jar: /home/user/contiki-ng/tools/cooja/dist/cooja.jar
jar:
init:
compile:
jar:
init:
mspsim:
init:
compile:
jar:
coffee:
init:
compile:
[javac] Compiling 8 source files to /home/user/contiki-ng/tools/cooja/tools/coffee-manager/build
[javac] Note: /home/user/contiki-ng/tools/cooja/tools/coffee-manager/org/contikios/coffee/CoffeeConfiguration.java uses or overrides a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
configs:
jar:
[jar] Building jar: /home/user/contiki-ng/tools/cooja/tools/coffee-manager/coffee.jar
[copy] Copying 1 file to /home/user/contiki-ng/tools/cooja/apps/mspsim/lib
compile:
copy:
jar:
init:
compile:
jar:
init:
clean:
[delete] Deleting directory /home/user/contiki-ng/tools/cooja/apps/serial_socket/build
BUILD FAILED
/home/user/contiki-ng/tools/cooja/build.xml:200: The following error occurred while executing this line:
/home/user/contiki-ng/tools/cooja/apps/serial_socket/build.xml:23: Unable to delete file /home/user/contiki-ng/tools/cooja/apps/serial_socket/build/org/contikios/cooja/serialsocket/SerialSocketClient.class
Total time: 2 seconds
我尝试使用 $ sudo ant run
,它开始正常工作,没有问题.
.
.
$ ant run -verbose 2>> log;cat log
给出:
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
BUILD FAILED
/home/user/contiki-ng/tools/cooja/build.xml:200: The following error occurred while executing this line:
/home/user/contiki-ng/tools/cooja/apps/serial_socket/build.xml:23: Unable to delete file /home/user/contiki-ng/tools/cooja/apps/serial_socket/build/org/contikios/cooja/serialsocket/SerialSocketClient.class
at org.apache.tools.ant.taskdefs.Delete.handle(Delete.java:775)
at org.apache.tools.ant.taskdefs.Delete.removeDir(Delete.java:822)
at org.apache.tools.ant.taskdefs.Delete.removeDir(Delete.java:818)
at org.apache.tools.ant.taskdefs.Delete.removeDir(Delete.java:818)
at org.apache.tools.ant.taskdefs.Delete.removeDir(Delete.java:818)
at org.apache.tools.ant.taskdefs.Delete.removeDir(Delete.java:818)
at org.apache.tools.ant.taskdefs.Delete.execute(Delete.java:641)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:299)
at jdk.internal.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at org.apache.tools.ant.Target.execute(Target.java:449)
at org.apache.tools.ant.Target.performTasks(Target.java:470)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1401)
at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:36)
at org.apache.tools.ant.Project.executeTargets(Project.java:1264)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:437)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:299)
at jdk.internal.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at org.apache.tools.ant.Target.execute(Target.java:449)
at org.apache.tools.ant.Target.performTasks(Target.java:470)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1401)
at org.apache.tools.ant.Project.executeTarget(Project.java:1374)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1264)
at org.apache.tools.ant.Main.runBuild(Main.java:818)
at org.apache.tools.ant.Main.startAnt(Main.java:223)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:284)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:101)
Total time: 2 seconds
我解决了这个问题,首先检查 build.xml
,run
定义的部分:
105. <target name="run" depends="init, compile, jar, copy configs">
106. <java fork="yes" dir="${build}" classname="org.contikios.cooja.Cooja" maxmemory="512m">
107. <sysproperty key="user.language" value="en"/>
108. <arg line="${args}"/>
109. <env key="LD_LIBRARY_PATH" value="."/>
110. <classpath>
111. <pathelement path="${build}"/>
112. <pathelement location="lib/jdom.jar"/>
113. <pathelement location="lib/log4j.jar"/>
114. <pathelement location="lib/syntaxpane-1.2.0.jar"/>
115. <pathelement location="lib/swingx-all-1.6.4.jar"/>
116. </classpath>
117. </java>
118. </target>
您可以看到它取决于 jar
。
18. Build COOJA (dist/cooja.jar) and all default projects (MSPSim et al)
19. > ant jar
所以检查 jar
部分:
196. <target name="jar" depends="jar_cooja">
197. <ant antfile="build.xml" dir="apps/mrm" target="jar" inheritAll="false"/>
198. <ant antfile="build.xml" dir="apps/mspsim" target="jar" inheritAll="false"/>
199. <ant antfile="build.xml" dir="apps/avrora" target="jar" inheritAll="false"/>
200. <ant antfile="build.xml" dir="apps/serial_socket" target="jar" inheritAll="false"/>
201. <ant antfile="build.xml" dir="apps/powertracker" target="jar" inheritAll="false"/>
202. </target>
我可以看到它试图操纵 ./apps/serail_socket
但失败了。
所以我检查了这些目录的所有者和正确权限:
$ ls -li | awk '{print , , , $NF}'
total
drwxr-xr-x root root build
-rw-r--r-- user user build.xml
-rw-r--r-- root root cooja.config
drwxr-xr-x root root java
drwxr-xr-x root root lib
-rw-r--r-- root root serial-socket.jar
所有者是 root
而不是普通用户。也许我 运行 :
git submodule update --init --recursive
命令与 sudo
之类的错误。
所以我更改了这些文件和目录的所有者:
sudo chown -h -R user ./apps/serail_socket ./apps/powertracker
然后它的 正常工作。
最近我开始使用 contiki-ng 从事物联网项目。
我遇到的问题是当我尝试 运行 cooja 时:
$ ant run
在 ~/contiki-ng/tools/cooja
之下。
构建失败
$ ant run
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
Buildfile: /home/user/contiki-ng/tools/cooja/build.xml
init:
compile:
copy configs:
jar_cooja:
[jar] Building jar: /home/user/contiki-ng/tools/cooja/dist/cooja.jar
jar:
init:
compile:
jar:
init:
mspsim:
init:
compile:
jar:
coffee:
init:
compile:
[javac] Compiling 8 source files to /home/user/contiki-ng/tools/cooja/tools/coffee-manager/build
[javac] Note: /home/user/contiki-ng/tools/cooja/tools/coffee-manager/org/contikios/coffee/CoffeeConfiguration.java uses or overrides a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
configs:
jar:
[jar] Building jar: /home/user/contiki-ng/tools/cooja/tools/coffee-manager/coffee.jar
[copy] Copying 1 file to /home/user/contiki-ng/tools/cooja/apps/mspsim/lib
compile:
copy:
jar:
init:
compile:
jar:
init:
clean:
[delete] Deleting directory /home/user/contiki-ng/tools/cooja/apps/serial_socket/build
BUILD FAILED
/home/user/contiki-ng/tools/cooja/build.xml:200: The following error occurred while executing this line:
/home/user/contiki-ng/tools/cooja/apps/serial_socket/build.xml:23: Unable to delete file /home/user/contiki-ng/tools/cooja/apps/serial_socket/build/org/contikios/cooja/serialsocket/SerialSocketClient.class
Total time: 2 seconds
我尝试使用 $ sudo ant run
,它开始正常工作,没有问题.
.
.
$ ant run -verbose 2>> log;cat log
给出:
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
BUILD FAILED
/home/user/contiki-ng/tools/cooja/build.xml:200: The following error occurred while executing this line:
/home/user/contiki-ng/tools/cooja/apps/serial_socket/build.xml:23: Unable to delete file /home/user/contiki-ng/tools/cooja/apps/serial_socket/build/org/contikios/cooja/serialsocket/SerialSocketClient.class
at org.apache.tools.ant.taskdefs.Delete.handle(Delete.java:775)
at org.apache.tools.ant.taskdefs.Delete.removeDir(Delete.java:822)
at org.apache.tools.ant.taskdefs.Delete.removeDir(Delete.java:818)
at org.apache.tools.ant.taskdefs.Delete.removeDir(Delete.java:818)
at org.apache.tools.ant.taskdefs.Delete.removeDir(Delete.java:818)
at org.apache.tools.ant.taskdefs.Delete.removeDir(Delete.java:818)
at org.apache.tools.ant.taskdefs.Delete.execute(Delete.java:641)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:299)
at jdk.internal.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at org.apache.tools.ant.Target.execute(Target.java:449)
at org.apache.tools.ant.Target.performTasks(Target.java:470)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1401)
at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:36)
at org.apache.tools.ant.Project.executeTargets(Project.java:1264)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:437)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:299)
at jdk.internal.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at org.apache.tools.ant.Target.execute(Target.java:449)
at org.apache.tools.ant.Target.performTasks(Target.java:470)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1401)
at org.apache.tools.ant.Project.executeTarget(Project.java:1374)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1264)
at org.apache.tools.ant.Main.runBuild(Main.java:818)
at org.apache.tools.ant.Main.startAnt(Main.java:223)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:284)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:101)
Total time: 2 seconds
我解决了这个问题,首先检查 build.xml
,run
定义的部分:
105. <target name="run" depends="init, compile, jar, copy configs">
106. <java fork="yes" dir="${build}" classname="org.contikios.cooja.Cooja" maxmemory="512m">
107. <sysproperty key="user.language" value="en"/>
108. <arg line="${args}"/>
109. <env key="LD_LIBRARY_PATH" value="."/>
110. <classpath>
111. <pathelement path="${build}"/>
112. <pathelement location="lib/jdom.jar"/>
113. <pathelement location="lib/log4j.jar"/>
114. <pathelement location="lib/syntaxpane-1.2.0.jar"/>
115. <pathelement location="lib/swingx-all-1.6.4.jar"/>
116. </classpath>
117. </java>
118. </target>
您可以看到它取决于 jar
。
18. Build COOJA (dist/cooja.jar) and all default projects (MSPSim et al)
19. > ant jar
所以检查 jar
部分:
196. <target name="jar" depends="jar_cooja">
197. <ant antfile="build.xml" dir="apps/mrm" target="jar" inheritAll="false"/>
198. <ant antfile="build.xml" dir="apps/mspsim" target="jar" inheritAll="false"/>
199. <ant antfile="build.xml" dir="apps/avrora" target="jar" inheritAll="false"/>
200. <ant antfile="build.xml" dir="apps/serial_socket" target="jar" inheritAll="false"/>
201. <ant antfile="build.xml" dir="apps/powertracker" target="jar" inheritAll="false"/>
202. </target>
我可以看到它试图操纵 ./apps/serail_socket
但失败了。
所以我检查了这些目录的所有者和正确权限:
$ ls -li | awk '{print , , , $NF}'
total
drwxr-xr-x root root build
-rw-r--r-- user user build.xml
-rw-r--r-- root root cooja.config
drwxr-xr-x root root java
drwxr-xr-x root root lib
-rw-r--r-- root root serial-socket.jar
所有者是 root
而不是普通用户。也许我 运行 :
git submodule update --init --recursive
命令与 sudo
之类的错误。
所以我更改了这些文件和目录的所有者:
sudo chown -h -R user ./apps/serail_socket ./apps/powertracker
然后它的 正常工作。