1. New MAVEN Project
2. Pom File Add dependency
Add 3 main dependencies
<Dependency> <groupId>Com.twitter</groupId> <Artifactid>scrooge-core_2.10</Artifactid> <version>${scrooge.version}</version> </Dependency> <Dependency> <groupId>Com.twitter</groupId> <Artifactid>finagle-thrift_2.10</Artifactid> <version>${finagle.version}</version> </Dependency> <Dependency> <groupId>Com.twitter</groupId> <Artifactid>finagle-serversets_2.10</Artifactid> <version>${finagle.version}</version> <Exclusions> <exclusion> <groupId>Org.slf4j</groupId> <Artifactid>Slf4j-jdk14</Artifactid> </exclusion> </Exclusions> </Dependency>
PS: for note useFinagle.version 6.20.0
Then add the dependency source Note: This URL is the wall please configure the agent in Maven.
<repositories>
<repository>
<id>twitter-twttr</id>
<url>http://maven.twttr.com/</url>
</repository>
</repositories>
3. Then configure a plugin to generate Java files from the thrift file (this plugin is important)
In<Build>Of<Plugins>The following configuration<plugin> <groupId>Com.twitter</groupId> <Artifactid>Scrooge-maven-plugin</Artifactid> <version>${scrooge.version}</version> <Configuration> <thriftnamespacemappings> <thriftnamespacemapping> < from>Com.twitter.demo</ from> < to>xxxxxxxx</ to> </thriftnamespacemapping> </thriftnamespacemappings> <language>Java</language> <!--default is Scala - <thriftopts> <!--Add other Scrooge command line options using Thriftopts - <thriftopt>--finagle</thriftopt> <!--<thriftOpt>\-\-ostrich</thriftOpt> - </thriftopts> <!--Tell Scrooge to extract thrifts from these artifacts - <Dependencyincludes> <include>Event-logger-thrift</include> </Dependencyincludes> </Configuration> <executions> <Execution> <ID>Thrift-sources</ID> <Phase>Generate-sources</Phase> <Goals> <goal>Compile</goal> </Goals> </Execution> <Execution> <ID>Thrift-test-sources</ID> <Phase>Generate-test-sources</Phase> <Goals> <goal>Testcompile</goal> </Goals> </Execution> </executions> </plugin>
Note: Red part to need to fill in the desired package name, that is, the package name of the generated file
4. Create a new Thrift folder (and Java folder sibling) under Project file Src/main
New Thrift File: Write Thrift: No wordy. The compilation will then automatically generate thrift corresponding Java files.
5, according to Java files inherit xxx. Serveriface implementation-defined interfaces
Java Build Finagle