Ubuntu下编译AllJoyn源码及遇到的问题

环境:

操作系统 ubuntu-14.04-desktop-i386

到https://allseenalliance.org网站上下载源码包 alljoyn-suite-14.06.00_beta-src.tar.gz

copy到/opt下,解压,更名为/opt/alljoyn-14.06

下载好junit-4.9.jar

$ sudo cp junit-4.9.jar /usr/share/java/

环境变量 

JAVA_HOME=/usr/java/jdk1.7.0_25

CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:/usr/share/java/junit-4.9.jar

PATH=$JAVA_HOME/bin:$PATH

AJ_ROOT=/opt/alljoyn-14.06

重要参考资料:Configuring the Build Environment (Linux Platform)

下面开始记录过程

$ cd $AJ_ROOT/core/alljoyn

查看该目录结构,初始的内容如下

$ tree -L 1
.
├── alljoyn_c
├── alljoyn_core
├── alljoyn_java
├── alljoyn_js
├── alljoyn_objc
├── alljoyn_unity
├── build_core
├── build.xml
├── common
├── README.md
├── README.txt
├── SConstruct
└── services

由于我不需要JavaScript, Objective-C, Unity的BINDINGS,我可以直接把这3个相关的目录删掉,也可以在编译时指定参数,如

$ scons OS=linux CPU=x86 BINDINGS=c,cpp,java

命令开始执行后,一开始编译cpp时,进展还比较顺利。可当编译到Java时,输出内容包括以下几类信息

(1)

warning: [path] bad path element "/usr/share/java/junit4.9.jar": no such file or directory
alljoyn_java/test/org/alljoyn/bus/AddressBookTest.java:23: error: package junit.framework does not exist

(2)

alljoyn_java/test/org/alljoyn/bus/MarshalTest.java:1153: warning: [rawtypes] found raw type: TreeMap
        TreeMap<String, String>[] aaess = (TreeMap<String, String>[]) new TreeMap[2];
                                                                          ^
  missing type arguments for generic class TreeMap<K,V>
  where K,V are type-variables:
    K extends Object declared in class TreeMap
    V extends Object declared in class TreeMap

alljoyn_java/test/org/alljoyn/bus/MultipleReturnValuesTest.java:69: warning: [rawtypes] found raw type: HashMap
            HashMap<String,String>[] hm = (HashMap<String,String>[]) new HashMap[2];
                                                                         ^
  missing type arguments for generic class HashMap<K,V>
  where K,V are type-variables:
    K extends Object declared in class HashMap
    V extends Object declared in class HashMap
(3)

(......前面还有若干行类似的)
alljoyn_java/test/org/alljoyn/bus/ifaces/IntrospectableTest.java:54: warning: [rawtypes] found raw type: Class
                                                         new Class[] { Introspectable.class });
                                                             ^
  missing type arguments for generic class Class<T>
  where T is a type-variable:
    T extends Object declared in class Class
alljoyn_java/test/org/alljoyn/bus/ifaces/PeerTest.java:64: warning: [rawtypes] found raw type: Class
                                                         new Class[] { Peer.class });
                                                             ^
  missing type arguments for generic class Class<T>
  where T is a type-variable:
    T extends Object declared in class Class
100 errors
93 warnings
scons: *** [alljoyn_java/test/build/linux/x86/debug/obj/classes/org/alljoyn/bus/AddressBookInterface.class] Error 1
scons: building terminated because of errors.
第(1)类errors很多,都是跟junit相关的。其实我在阅读官方文档时已经注意到junit的问题了,junit-4.9.jar的包也下好了,也添加了相应的环境变量,可坑爹的是,我设置环境变量时少打了个"-",囧rz。如果你压根没下载junit的jar包,或者没设置junit的环境变量,那么编译java的时候肯定是会报这些errors的。

第(2)(3)类warnings,一看就是泛型的问题,忽略之。

更正错误,在CLASSPATH环境变量里面添加/usr/share/java/junit-4.9.jar后

再次输入编译命令

$ scons OS=linux CPU=x86 BINDINGS=c,cpp,java

输出信息包括

wsbuild(["ws"], ["build_core/$DISTDIR"])
Evaluating whitespace compliance...
Config: /opt/alljoyn-14.06/core/alljoyn/build_core/tools/conf/ajuncrustify.cfg
Note: enter 'scons -h' to see whitespace (WS) options
whitespace.db not found a new one will be created.
It appears that 'uncrustify' is not installed or is not on your PATH. Please check your system and try again.
scons: *** [ws] Explicit exit, status 2
scons: building terminated because of errors.

查看官方文档可以看到这么一段:

Whitespace policy checker

By default the whitespace policy checker runs every time. If you continually get build errors associated with the whitespace.py script, it can be shut off using this command:
$ scons WS=off
If the whitespace policy checker reports a whitespace policy violation, it lists which files have the violation. To see the lines of code that are violating the AllJoyn whitespace policy, run:
$ scons WS=detail
Uncrustify can automatically fix your files to adhere to the whitespace policy.
$ scons WS=fix

于是将编译命令改为

$ scons OS=linux CPU=x86 WS=off BINDINGS=c,cpp,java

终于得到输出

scons: done building targets.

而且可以看到

spark@jaguarh:/opt/alljoyn-14.06/core/alljoyn/build/linux/x86/debug/dist/java/lib$ ls
liballjoyn_java.so

终于得到想要的liballjoyn_java.so,这是linux下的共享库,有点类似Windows下的.dll文件。

用AllJoyn框架编写的Java程序在需要运行时,会用到liballjoyn_java.so






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值