Install Apache Thrift
Ubuntu Linux Run:
#!/bin/bash
#下载
wget http://mirrors.cnnic.cn/apache/thrift/0.9.1/thrift-0.9.1.tar.gz
tar zxvf thrift-0.9.1.tar.gz
cd thrift-0.9.1.tar.gz
./configure make make
install
#编译java依赖包
CD Lib/java
Ant
Installing Ubuntu dependencies
sudo apt-get install Libboost-dev libboost-test-dev libboost-program-options-dev Libevent-dev Automake Flex Bison Pkg-config g++ Libssl-dev
Writing Thrift Files Hello.thrift
namespace Java Com.micmiu.thrift.demo
service helloworldservice {
string SayHello (1:string username)
}
Run
Thrift-gen Java Hello.thrift
The Gen-java/com/micmiu/thrift/demo/helloworldservice.java file will be generated in the sibling directory
Writing test procedures
Building with Maven
Pom.xml file
<?xml version= "1.0" encoding= "UTF-8"?> <project xmlns= "http://maven.apache.org/POM/4.0.0" HT Tp://www.w3.org/2001/xmlschema-instance "xsi:schemalocation=" http://maven.apache.org/POM/4.0.0 http:// Maven.apache.org/xsd/maven-4.0.0.xsd "> <modelVersion>4.0.0</modelVersion> <groupid >com.micmiu.thrift.demo</groupId> <artifactId>thrift-test</artifactId> <version>0.1.0 -snapshot</version> <dependencies> <strong> <dependency> <groupid>org. Apache.thrift</groupid> <artifactId>libthrift</artifactId> <version>0.9.1</version&
Gt </dependency></strong> <dependency> <groupId>org.slf4j</groupId> <artif actid>slf4j-log4j12</artifactid> <version>1.5.8</version> </dependency> </depend Encies> <build>
<plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <ve rsion>2.2-beta-5</version> <configuration> <descriptorRefs> <descriptorref >jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> </ plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactid>ma Ven-compiler-plugin</artifactid> <version>2.3.2</version> <configuration> <
Source>1.6</source> <target>1.6</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </build> </project>