MAC OS===>IntelliJ IDEA__ant__zookeeper源码编译
1:配置ant环境
- https://archive.apache.org/dist/ant/binaries/ 官网下载文件 1.10.0以上需要JDK1.8以上
- 否则会报
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/tools/ant/launch/Launcher : Unsupported major.minor version 52.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:800) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) at java.net.URLClassLoader.access$100(URLClassLoader.java:71) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
- 查看本地环境JDK版本 java -version
查看本机JDK环境 ~ $java -version java version "1.7.0_79" Java(TM) SE Runtime Environment (build 1.7.0_79-b15) Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode) ~ $
- 本机下载的版本1.9.4,下载完之后,本地解压
- 环境变量配置
第一步: ~ $vim .bash_profile 第二步: //配置文件中增加ant的文件路径 export ANT_HOME=/Users/quruirui/ruirui.qu/Install/q/ant/apache-ant-1.9.4 export PATH=${PATH}:${ANT_HOME}/bin //保存退出 第三步: ~ $source .bash_profile
-
~ $ant -version Apache Ant(TM) version 1.9.4 compiled on March 5 2013
安装完毕
2.编译zk
1) 下载源码:https://github.com/apache/zookeeper
2) git clone https://github.com/apache/zookeeper.git
3) 进入源目录 执行ant eclipse
网上看帖子,别人都比较顺利,但是我这边问题比较多,列举如下解决方法
1.
zookeeper $ant eclipse Buildfile: /Users/quruirui/ruirui.qu/pay/pay_learn/zookeeper/build.xml ant-eclipse-download: [get] Getting: https://downloads.sourceforge.net/project/ant-eclipse/ant-eclipse/1.0/ant-eclipse-1.0.bin.tar.bz2 [get] To: /Users/quruirui/ruirui.qu/pay/pay_learn/zookeeper/src/java/ant-eclipse-1.0.bin.tar.bz2 [get] Error getting https://downloads.sourceforge.net/project/ant-eclipse/ant-eclipse/1.0/ant-eclipse-1.0.bin.tar.bz2 to /Users/quruirui/ruirui.qu/pay/pay_learn/zookeeper/src/java/ant-eclipse-1.0.bin.tar.bz2 BUILD FAILED /Users/quruirui/ruirui.qu/pay/pay_learn/zookeeper/build.xml:1909: java.net.SocketException: Connection reset at java.net.SocketInputStream.read(SocketInputStream.java:196) at java.net.SocketInputStream.read(SocketInputStream.java:122) at sun.security.ssl.InputRecord.readFully(InputRecord.java:442) at sun.security.ssl.InputRecord.read(InputRecord.java:480) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:934) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343) at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185) at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153) at org.apache.tools.ant.taskdefs.Get$GetThread.openConnection(Get.java:660) at org.apache.tools.ant.taskdefs.Get$GetThread.get(Get.java:579) at org.apache.tools.ant.taskdefs.Get$GetThread.run(Get.java:569) =================》 //解决方法:将地址 get src="http://downloads.sourceforge.net/project/ant-eclipse/ant-eclipse/1.0/ant-eclipse-1.0.bin.tar.bz2" //替换为 <get src="http://ufpr.dl.sourceforge.net/project/ant-eclipse/ant-eclipse/1.0/ant-eclipse-1.0.bin.tar.bz2" dest="${src.dir}/java/ant-eclipse-1.0.bin.tar.bz2" usetimestamp="false" />
2:
zookeeper $ant eclipse Buildfile: /Users/quruirui/ruirui.qu/pay/pay_learn/zookeeper/build.xml ant-eclipse-download: [get] Getting: https://downloads.sourceforge.net/project/ant-eclipse/ant-eclipse/1.0/ant-eclipse-1.0.bin.tar.bz2 [get] To: /Users/quruirui/ruirui.qu/pay/pay_learn/zookeeper/src/java/ant-eclipse-1.0.bin.tar.bz2 [get] Error getting https://downloads.sourceforge.net/project/ant-eclipse/ant-eclipse/1.0/ant-eclipse-1.0.bin.tar.bz2 to /Users/quruirui/ruirui.qu/pay/pay_learn/zookeeper/src/java/ant-eclipse-1.0.bin.tar.bz2 BUILD FAILED /Users/quruirui/ruirui.qu/pay/pay_learn/zookeeper/build.xml:1909: java.net.SocketException: Connection reset at java.net.SocketInputStream.read(SocketInputStream.java:196) at java.net.SocketInputStream.read(SocketInputStream.java:122) at sun.security.ssl.InputRecord.readFully(InputRecord.java:442) at sun.security.ssl.InputRecord.read(InputRecord.java:480) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:934) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343) at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185) at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153) at org.apache.tools.ant.taskdefs.Get$GetThread.openConnection(Get.java:712) at org.apache.tools.ant.taskdefs.Get$GetThread.get(Get.java:626) at org.apache.tools.ant.taskdefs.Get$GetThread.run(Get.java:616) zookeeper $ant eclipse Buildfile: /Users/quruirui/ruirui.qu/pay/pay_learn/zookeeper/build.xml ant-eclipse-download: [get] Getting: http://ufpr.dl.sourceforge.net/project/ant-eclipse/ant-eclipse/1.0/ant-eclipse-1.0.bin.tar.bz2 [get] To: /Users/quruirui/ruirui.qu/pay/pay_learn/zookeeper/src/java/ant-eclipse-1.0.bin.tar.bz2 [bunzip2] Expanding /Users/quruirui/ruirui.qu/pay/pay_learn/zookeeper/src/java/ant-eclipse-1.0.bin.tar.bz2 to /Users/quruirui/ruirui.qu/pay/pay_learn/zookeeper/src/java/ant-eclipse-1.0.bin.tar BUILD FAILED /Users/quruirui/ruirui.qu/pay/pay_learn/zookeeper/build.xml:1911: Problem expanding bzip2 unexpected end of stream Total time: 1 minute 57 seconds //====>诡异 后来自己好了
3.
====>诡异 后来自己好了 zookeeper $ant eclipse Buildfile: /Users/quruirui/ruirui.qu/pay/pay_learn/zookeeper/build.xml ant-eclipse-download: init: ivy-download: [get] Getting: https://repo1.maven.org/maven2/org/apache/ivy/ivy/2.4.0/ivy-2.4.0.jar [get] To: /Users/quruirui/ruirui.qu/pay/pay_learn/zookeeper/src/java/lib/ivy-2.4.0.jar [get] Error getting https://repo1.maven.org/maven2/org/apache/ivy/ivy/2.4.0/ivy-2.4.0.jar to /Users/quruirui/ruirui.qu/pay/pay_learn/zookeeper/src/java/lib/ivy-2.4.0.jar BUILD FAILED /Users/quruirui/ruirui.qu/pay/pay_learn/zookeeper/build.xml:401: javax.net.ssl.SSLException: Received fatal alert: protocol_version at sun.security.ssl.Alerts.getSSLException(Alerts.java:208) at sun.security.ssl.Alerts.getSSLException(Alerts.java:154) at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1979) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1086) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343) at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185) at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153) at org.apache.tools.ant.taskdefs.Get$GetThread.openConnection(Get.java:712) at org.apache.tools.ant.taskdefs.Get$GetThread.get(Get.java:626) at org.apache.tools.ant.taskdefs.Get$GetThread.run(Get.java:616)
[ivy:retrieve] :: commons-cli#commons-cli;1.2: not found
[ivy:retrieve] :: log4j#log4j;1.2.17: not found
[ivy:retrieve] :: org.apache.yetus#audience-annotations;0.5.0: not found
[ivy:retrieve] :: io.netty#netty;3.10.6.Final: not found
[ivy:retrieve] ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:retrieve] :::: ERRORS
[ivy:retrieve] Server access error at url https://repo1.maven.org/maven2/jline/jline/2.11/jline-2.11.pom (javax.net.ssl.SSLException: Received fatal alert: protocol_version)
[ivy:retrieve] Server access error at url https://repo1.maven.org/maven2/jline/jline/2.11/jline-2.11.jar (javax.net.ssl.SSLException: Received fatal alert: protocol_version)
[ivy:retrieve] Server access error at url https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-server/9.4.10.v20180503/jetty-server-9.4.10.v20180503.pom (javax.net.ssl.SSLException: Received fatal alert: protocol_version)
[ivy:retrieve] Server access error at url https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-server/9.4.10.v20180503/jetty-server-9.4.10.v20180503.jar (javax.net.ssl.SSLException: Received fatal alert: protocol_version)
[ivy:retrieve] Server access error at url https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-servlet/9.4.10.v20180503/jetty-servlet-9.4.10.v20180503.pom (javax.net.ssl.SSLException: Received fatal alert: protocol_version)
[ivy:retrieve] Server access error at url https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-servlet/9.4.10.v20180503/jetty-servlet-9.4.10.v20180503.jar (javax.net.ssl.SSLException: Received fatal alert: protocol_version)
[ivy:retrieve] Server access error at url https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.9.5/jackson-databind-2.9.5.pom (javax.net.ssl.SSLException: Received fatal alert: protocol_version)
[ivy:retrieve] Server access error at url https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.9.5/jackson-databind-2.9.5.jar (javax.net.ssl.SSLException: Received fatal alert: protocol_version)
[ivy:retrieve] Server access error at url https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.pom (javax.net.ssl.SSLException: Received fatal alert: protocol_version)
[ivy:retrieve] Server access error at url https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar (javax.net.ssl.SSLException: Received fatal alert: protocol_version)
[ivy:retrieve] Server access error at url https://repo1.maven.org/maven2/org/slf4j/slf4j-log4j12/1.7.25/slf4j-log4j12-1.7.25.pom (javax.net.ssl.SSLException: Received fatal alert: protocol_version)
[ivy:retrieve] Server access error at url https://repo1.maven.org/maven2/org/slf4j/slf4j-log4j12/1.7.25/slf4j-log4j12-1.7.25.jar (javax.net.ssl.SSLException: Received fatal alert: protocol_version)
[ivy:retrieve] Server access error at url https://repo1.maven.org/maven2/commons-cli/commons-cli/1.2/commons-cli-1.2.pom (javax.net.ssl.SSLException: Received fatal alert: protocol_version)
[ivy:retrieve] Server access error at url https://repo1.maven.org/maven2/commons-cli/commons-cli/1.2/commons-cli-1.2.jar (javax.net.ssl.SSLException: Received fatal alert: protocol_version)
[ivy:retrieve] Server access error at url https://repo1.maven.org/maven2/log4j/log4j/1.2.17/log4j-1.2.17.pom (javax.net.ssl.SSLException: Received fatal alert: protocol_version)
[ivy:retrieve] Server access error at url https://repo1.maven.org/maven2/log4j/log4j/1.2.17/log4j-1.2.17.jar (javax.net.ssl.SSLException: Received fatal alert: protocol_version)
[ivy:retrieve] Server access error at url https://repo1.maven.org/maven2/org/apache/yetus/audience-annotations/0.5.0/audience-annotations-0.5.0.pom (javax.net.ssl.SSLException: Received fatal alert: protocol_version)
[ivy:retrieve] Server access error at url https://repo1.maven.org/maven2/org/apache/yetus/audience-annotations/0.5.0/audience-annotations-0.5.0.jar (javax.net.ssl.SSLException: Received fatal alert: protocol_version)
[ivy:retrieve] Server access error at url https://repo1.maven.org/maven2/io/netty/netty/3.10.6.Final/netty-3.10.6.Final.pom (javax.net.ssl.SSLException: Received fatal alert: protocol_version)
[ivy:retrieve] Server access error at url https://repo1.maven.org/maven2/io/netty/netty/3.10.6.Final/netty-3.10.6.Final.jar (javax.net.ssl.SSLException: Received fatal alert: protocol_version)
[ivy:retrieve]
[ivy:retrieve] :: USE VERBOSE OR DEBUG MESSAGE LEVEL FOR MORE DETAILS
BUILD FAILED
/Users/quruirui/ruirui.qu/pay/pay_learn/zookeeper/build.xml:417: impossible to resolve dependencies:
resolve failed - see output for details
//======不知道是不是因为公司内网的原因,以上两种错误都是将ivy.xml ivysettings.xml中所有的https 替换为http 搞定
4.
[ivy:retrieve] :: resolving dependencies :: org.apache.zookeeper#zookeeper;3.6.0-SNAPSHOT [ivy:retrieve] confs: [javacc] [ivy:retrieve] found net.java.dev.javacc#javacc;5.0 in maven2 [ivy:retrieve] :: resolution report :: resolve 35ms :: artifacts dl 1ms --------------------------------------------------------------------- | | modules || artifacts | | conf | number| search|dwnlded|evicted|| number|dwnlded| --------------------------------------------------------------------- | javacc | 1 | 0 | 0 | 0 || 1 | 0 | --------------------------------------------------------------------- [ivy:retrieve] :: retrieving :: org.apache.zookeeper#zookeeper [ivy:retrieve] confs: [javacc] [ivy:retrieve] 1 artifacts copied, 0 already retrieved (291kB/7ms) generate_jute_parser: [ivy:artifactproperty] DEPRECATED: 'ivy.conf.file' is deprecated, use 'ivy.settings.file' instead [ivy:artifactproperty] :: loading settings :: file = /Users/quruirui/ruirui.qu/pay/pay_learn/zookeeper/ivysettings.xml [move] Moving 1 file to /Users/quruirui/ruirui.qu/pay/pay_learn/zookeeper/build/javacc/lib jute: [javac] Compiling 39 source files to /Users/quruirui/ruirui.qu/pay/pay_learn/zookeeper/build/classes [javac] javac: 无效的目标发行版: 1.8 [javac] 用法: javac <options> <source files> [javac] -help 用于列出可能的选项 BUILD FAILED /Users/quruirui/ruirui.qu/pay/pay_learn/zookeeper/build.xml:321: Compile failed; see the compiler error output for details. Total time: 1 second
//=======这个是因为本地的JDK版本不一致导致的,因为我本机装的是JDK1.7 两种方法:将本地的1.7升级为1.8;或者将build.xml中的如下两个值改为你本机配置的JDK版本
<property name="javac.target" value="1.7" />
<property name="javac.source" value="1.7" />
5.再次执行ant eclipse
[ivy:cachepath] found org.hamcrest#hamcrest-all;1.3 in maven2 [ivy:cachepath] :: resolution report :: resolve 38493ms :: artifacts dl 18ms --------------------------------------------------------------------- | | modules || artifacts | | conf | number| search|dwnlded|evicted|| number|dwnlded| --------------------------------------------------------------------- | test | 49 | 1 | 0 | 0 || 49 | 0 | --------------------------------------------------------------------- [eclipse] Writing the preferences for "org.eclipse.jdt.core". [eclipse] Writing the preferences for "org.eclipse.core.resources". [eclipse] Writing the project definition in the mode "java". [eclipse] Writing the classpath definition. BUILD SUCCESSFUL
6.IDEA 安装lombok插件 设置Enable Annotation Processing后编译依然报错 解决方法;idea===》plugins===>安装lombok插件
7.zk源码导入idea 刚开始idea不能自动识别哪些是java文件,需要手动Mark directory as...... 这点不是很智能
8.导入完成后,可能会有写依赖没载入,这时可以用project-structure-->module--->dependency 加入即可