Compiling zookeeper projects with Javac

Source: Internet
Author: User
Tags zookeeper

Here's a note on zookeeper compiling some details on the source code.

There's a lot on the web about how to use ant Eclipse to build a record of the eclipse project that zookeeper corresponds to. It's not too much to repeat here. Just a brief explanation.

Here's how to compile the Zookeeper project without using any tools directly using Javac, and run it directly using Java.

I. Using ANT to Build a Eclispe engineering compilation method is very simple. Just download the Zookeeper project code on GitHub. There are already written build.xml and Ivy.xml and set up documents. All dependent dependencies are downloaded. and the build compiles. After the compilation is complete, directly in the Eclis Can be imported in PE. Very simple.

Two. If there are no ant,maven and other environments on Linux, you can only pass the Javac way when you want to compile zookeeper and other large projects.

Using the Javac way to compile zookeeper will find zookeeper Java source code directory package is less org.apache.zookeeper.data and Org.apache.zookeeper.proto. One of the two packages is zookeep. One of the related implementations of ER ACLs is the various commands related to communication protocols.

And not only are these two packages not. And a lot of dependencies are not. The list of jars that zookeeper relies on is as follows:

commons-cli-1.2. Jarjackson-core-asl-1.9.11. Jarjackson-mapper-asl-1.9.11. Jarjavacc.jarjetty-6.1.26. Jarjetty-util-6.1.26. Jarjline-2.11. jarlog4j-1.2.17 . Jarnetty-3.10.5. Final.jarservlet-api-2.5-20081211. jarslf4j-api-1.7.5. jarslf4j-log4j12-1.7.5.jar

  After you have downloaded these dependent jar packages, set them to the CLASSPATH variable. How to set it up easily. There will be an introduction at the end.

A dependent package is available. But the two source packages of the zookeeper itself are not in the source code directory. Many people here will be confused. Why the source code package is missing. How to find the corresponding source package when Ant compiles.

In fact, the Zookeeper project packages all the source code into a jar package to upload to repo1.maven.org/maven2/org/apache/zookeeper/ Zookeeper. Using Ivy to solve dependency problems will automatically search for the corresponding jar file and download it. After using ant, you will find that there is a generated directory in the source directory. The missing source code project package in this directory is here.

So when you build it manually, you need to go to maven to download the Zookeeper-<version>-source.jar file and unzip it to the corresponding directory.

When everything is complete, you can compile it with Javac. Put all the files in a file with the package path. Then compile the package file by Javac.

# find./-name ' *.java ' >source_list  A collection of all source code files. # javac-d./build @source_list       This will be generated by the package path in the build directory of the current directory after compiling

  After the compilation is successful, it can be run directly through Java. Java org.apache.zookeeper.server.quorum.QuorumPeerMain config.cfg can be run.

Three. In the use of Javac compile time is more trouble is the super-long classpath setup problem.

The quick way to set up classpath is to write a simple bash function into/etc/profile. This function is used to set the classpath.

function Classpath () {Local path=$1Find $path-name \*.jar | Awk'{if (nr==1) {jarp=$0}else{jarp=jarp ":" $0}}end{print Jarp}'} #函数的作用就是找出给出的目录下所有的jar文件 and then generate the form of xxx:xxx:xxx that conforms to the path format.
Export Java_home=/home/cloud/install/jdk1.7. 0_75export PATH= $JAVA _home/bin: $JAVA _home/jre/bin: $PATH:. Export CLASSPATH=.:..: $ (classpath $JAVA _home) export Classpath= $CLASSPATH: $ (CLASSPATH'/home/user/install/jar') #像这样直接把依赖的jar包放到这个目录里然后这样设置classpath就可以轻松使用javac编译大型项目了. Even projects such as Hadoop can still be compiled as long as the classpath settings are fully functional.
#在编译完之后需要将存放class文件的目录也添加到classpath中. This will not be a problem if you use the Java runtime.

Compiling zookeeper projects with Javac

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.