Java Comm环境设置

在linux下安装java comm运行环境-bca发送短信流程所需环境2008-11-04 16:18BCA配置发送短信的流程,需要Java Comm环境。使用java comm可以访问RS232接口(串口)及有限制地访问IEEE-1284(并口)。
下面介绍在Linux下的Java comm环境配置方法。
1、下载javacomm的linux版本,下载地址:http://java.sun.com/products/javacomm/
点击页面左侧的“Downloads ”链接,打开下载页,注意下载的时候,Platform(平台)选择“Linux”。
下载后得到“comm3.0_u1_linux.zip”压缩包文件(3.0是版本号,所以文件名会随着版本变化而有所不同,以下操作针对“comm3.0_u1_linux.zip”进行操作)。

2. 安装javacomm环境
执行命令:
(1),unzip comm3.0_u1_linux.zip 到 /home/appusr/JavaComm 下
(2),cp /home/appusr/JavaComm/libLinuxSerialParallel.so /usr/lib
(3),cp /home/appusr/JavaComm/javax.comm.properties /usr/JDK路径/lib
(4),cp /home/appusr/JavaComm/comm_linux.jar /usr/JDK路径/lib
(5),export CLASSPATH=$CLASSPATH:/home/appusr/JavaComm/comm.jar
(6),export LANG=zh_CN.GBK   #设置中文,否则针对短信进行UCS2编码不正确。

其中comm.jar是comm3.0_u1_linux.zip解压缩得到的jar包
注意:使用export 设置环境变量,操作系统重启后,环境变量将失效,需要重新设置。

注1:如果没有ROOT权限,可以直接执行如下命令: export LD_LIBRARY_PATH=/home/appusr/JavaComm: $LD_LIBRARY_PATH
export CLASSPATH=.:javacomm_linux.jar: $CLASSPATH
export LANG=zh_CN.GBK注2:针对javax.comm.properties的搜索顺序如下: Current directory.   
Each directory in ${java.classpath} (ie.   $CLASSPATH or -classpath setting).
<JDK>/lib.   
<JDK>/jre/lib  注3:以上用到的.jar文件和.properties文件在comm3.0_u1_linux.zip压缩包内的位置:
      |---docs--|
               |              |__javax.comm.properties
commapi --|--jar--|
                |       |--|
                |          |__comm.jar
                |--lib--|
                        |_libLinuxSerialParallel.so 引用:
3.另附sun官方API说明
1.Ensure that the library libLinuxSerialParallel.so can be loaded. You can do this
either by adding libLinuxSerialParallel.so to the environment LD_LIBRARY_PATH   or
by copying libLinuxSerialParallel.so to /usr/lib.
 
Example: Assuming your current working directory is where you extracted the distribution,

    % setenv LD_LIBRARY_PATH `pwd`LD_LIBRARY_PATH

   or

   $ export LD_LIBRARY_PATH=$PWDLD_LIBRARY_PATH

or, if you have administrative privileges on your machine,

    % cp libLinuxSerialParallel.so /usr/lib
 
 

2.If you are using JDK (not JRE) Add comm.jar to your classpath.
 
Example: If you don't have a CLASSPATH set currently,

    % setenv CLASSPATH `pwd`/comm.jar

or,   if you have something in your CLASSPATH already,

% setenv CLASSPATH `pwd`/comm.jarCLASSPATH
 

3.Copy the file javax.comm.properties to your <JDK>/jre/lib or your <JRE>/lib directory.
If you don't have write permission to <JDK>/jre/lib or <JRE>/lib, you can keep
javax.comm.properties in the same directory as comm.jar. The search order for
javax.comm.properties is:
 
<JRE>/lib
the directory that contains the first valid comm.jar that is included in the classpath.
 
The javax.comm.properties file must be installed. If it is not, no ports will be found by the system.
 
 
4.You should now be able to run your comm application Example:
   % java YourCommAppPkg.YourCommApp
Note: If you are using JDK 1.1.6, include the -native flag. Example:

   % java -native YourCommAppPkg.YourCommApp
 

5.Several serial port sample applications are provided with this release. One of them is BlackBox.
To run BlackBox, first add BlackBox.jar to your classpath:
 
 
   % setenv CLASSPATH BlackBox.jarCLASSPATH
then run BlackBox:

   % java BlackBox
 

6.One sample driver NullDriver is included in the samples/NullDriver directory.
This is useful for folks attempting to write a new driver for their own hardware.补充:

如果使用Red Had操作系统,配置java comm的环境变量步骤可以简化为(包括配置JDK部分):
在etc/profile.d/下建立java.sh,代码如下: JAVA_HOME=/usr/java/jdk1.6.0
PATH=$PATH: $JAVA_HOME/bin
CLASSPATH=.: $JAVA_HOME/lib/dt.jar: $JAVA_HOME/lib/tools.jar: $JAVA_HOME/lib/comm.jar
export JAVA_HOME PATH CLASSPATH  保存,然后注销系统,重新登陆。
其中JDK路径请根据实际路径填写,comm.jar要拷贝到相应的目录下,本实例的路径为:$JAVA_HOME/lib/comm.jar

使用这种方法,重启后环境变量仍然有效。

补充:
配置完java comm环境以后,请修改bca的set-bca-cp.sh文件里相应的comm.jar文件的路径,修改为comm.jar的实际路径,如: export LD_LIBRARY_PATH=$PWD:$LD_LIBRARY_PATH

export BCALIBH=../jres/libs
export JAVA_HOME=../jdk
CLASSPATH=../dist/bca.jar:../dist/BcaAgentX.jar

CLASSPATH=$CLASSPATH:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/comm.jar
CLASSPATH=$CLASSPATH:$BCALIBH/common-tools/ant-1.5.3.jar:$BCALIBH/common-tools/ant-optional-1.5.3.jar:$BCALIBH/common-tools/commons-beanutils.jar:$BCALIBH/common-tools/commons-codec-1.3.jar:$BCALIBH/common-tools/commons-collections-3.2.jar:$BCALIBH/common-tools/commons-configuration-1.4.jar:$BCALIBH/common-tools/commons-dbcp-1.1.jar:$BCALIBH/common-tools/commons-dbcp.jar:$BCALIBH/common-tools/commons-httpclient-3.1.jar:$BCALIBH/common-tools/commons-lang-2.3.jar:$BCALIBH/common-tools/commons-logging-1.0.3.jar:$BCALIBH/common-tools/commons-pool-1.1.jar:$BCALIBH/common-tools/connector.licence.txt:$BCALIBH/common-tools/docking-0.3.2.jar:$BCALIBH/common-tools/dom4j-1.4.jar:$BCALIBH/common-tools/edtftpj.jar:$BCALIBH/common-tools/log4j-1.2.8.jar:$BCALIBH/common-tools/velocity-1.4.jar:$BCALIBH/common-tools/velocity-dep-1.4.jar
CLASSPATH=$CLASSPATH:$BCALIBH/db/informix/ifxjdbc.jar:$BCALIBH/db/mssql/msutil.jar:$BCALIBH/db/mssql/mysqljdbc.jar:$BCALIBH/db/oracle/classes12.jar
CLASSPATH=$CLASSPATH:$BCALIBH/graph/jgraph-all.jar:$BCALIBH/graph/jgraph.jar:$BCALIBH/graph/jgraphpad.jar
CLASSPATH=$CLASSPATH:$BCALIBH/hibernate/antlr-2.7.6rc1.jar:$BCALIBH/hibernate/asm.jar:$BCALIBH/hibernate/c3p0-0.9.0-bca.jar:$BCALIBH/hibernate/c3p0-0.9.0-ex.jar:$BCALIBH/hibernate/cglib-2.1.3.jar:$BCALIBH/hibernate/hibernate3-bca.jar:$BCALIBH/hibernate/hibernate3-ex.jar:$BCALIBH/hibernate/jta.jar:$BCALIBH/hibernate/middlegen-2.1-bca.jar:$BCALIBH/hibernate/middlegen-hibernate-plugin-2.1.jar
CLASSPATH=$CLASSPATH:$BCALIBH/j2ee/servlet-api.jar:$BCALIBH/j2ee/servlet.jar
CLASSPATH=$CLASSPATH:$BCALIBH/java-se/jga-0.7.2-cddl.jar:$BCALIBH/java-se/swingx-ws.jar:$BCALIBH/java-se/swingx.jar:$BCALIBH/java-se/tools.jar:$BCALIBH/java-se/validation-1.0.1.jar:$BCALIBH/util/quartz-1.6.0.jar
CLASSPATH=$CLASSPATH:$BCALIBH/office/jxl.jar
CLASSPATH=$CLASSPATH:$BCALIBH/SMS/kvem.jar:$BCALIBH/SMS/midpapi20.jar:$BCALIBH/SMS/spApi.jar:$BCALIBH/SMS/wma20.jar
CLASSPATH=$CLASSPATH:$BCALIBH/util/htmlparser.jar:$BCALIBH/util/JSAP-2.0a.jar

export CLASSPATH

修改其中的这句:CLASSPATH=$CLASSPATHJAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/comm.jar
=================================================================================

注:文章中,因为原帖论坛的过滤机制,英文输入法状态下的冒号被替换成了笑脸图像,请自行替换回来。


一、纠错:一楼帖子的comm_linux.jar,在大部分java comm压缩包里的名称是comm.jar
二、补充:如果使用Red Had操作系统,配置java comm的环境变量步骤可以简化为(包括配置JDK部分):
在etc/profile.d/下建立java.sh,代码如下:

JAVA_HOME=/usr/java/jdk1.6.0
PATH=$PATH: $JAVA_HOME/bin
CLASSPATH=.: $JAVA_HOME/lib/dt.jar: $JAVA_HOME/lib/tools.jar: $JAVA_HOME/lib/comm.jar
export JAVA_HOME PATH CLASSPATH
  
保存,然后注销系统,重新登陆。
其中JDK路径请根据实际路径填写,comm.jar要拷贝到相应的目录下,本实例的路径为:$JAVA_HOME/lib/comm.jar
纠错:
一楼的set换成export
即: set CLASSPATH=.:/home/appusr/JavaComm/comm_linux.jarCLASSPATH 换成: exportCLASSPATH=$CLASSPATH:/home/appusr/JavaComm/comm_linux.jar 其中/home/appusr/JavaComm/comm_linux.jar 是你的comm_linux.jar路径,通常名字是comm.jar
注意:export设置环境变量,在系统重启后消失,需要重新设置。

你可能感兴趣的:(java,jdk,Hibernate,linux,velocity)