|
1 | 1 |
|
2 |
| -FastDFS java client SDK |
| 2 | +# FastDFS java client SDK |
3 | 3 |
|
| 4 | +FastDFS Java Client API may be copied only under the terms of the BSD license. |
| 5 | + |
| 6 | +## 使用ant从源码构建 |
| 7 | + |
| 8 | +``` |
| 9 | +ant clean package |
| 10 | +``` |
| 11 | + |
| 12 | +## 使用maven从源码安装 |
| 13 | + |
| 14 | +``` |
| 15 | +mvn clean install |
| 16 | +``` |
| 17 | + |
| 18 | +## 使用maven从jar文件安装 |
| 19 | +``` |
| 20 | +mvn install:install-file -DgroupId=org.csource -DartifactId=fastdfs-client-java -Dversion=${version} -Dpackaging=jar -Dfile=fastdfs-client-java-${version}.jar |
| 21 | +``` |
| 22 | + |
| 23 | +## 在您的maven项目pom.xml中添加依赖 |
| 24 | + |
| 25 | +```xml |
| 26 | +<dependency> |
| 27 | + <groupId>org.csource</groupId> |
| 28 | + <artifactId>fastdfs-client-java</artifactId> |
| 29 | + <version>1.27-SNAPSHOT</version> |
| 30 | +</dependency> |
| 31 | +``` |
| 32 | + |
| 33 | +## .conf 配置文件、所在目录、加载优先顺序 |
| 34 | + |
| 35 | + 配置文件名fdfs_client.conf(或使用其它文件名xxx_yyy.conf) |
| 36 | + |
| 37 | + 文件所在位置可以是项目classpath(或OS文件系统目录比如/opt/): |
| 38 | + /opt/fdfs_client.conf |
| 39 | + C:\Users\James\config\fdfs_client.conf |
| 40 | + |
| 41 | + 优先按OS文件系统路径读取,没有找到才查找项目classpath,尤其针对linux环境下的相对路径比如: |
| 42 | + fdfs_client.conf |
| 43 | + config/fdfs_client.conf |
| 44 | + |
| 45 | +``` |
| 46 | +connect_timeout = 2 |
| 47 | +network_timeout = 30 |
| 48 | +charset = UTF-8 |
| 49 | +http.tracker_http_port = 80 |
| 50 | +http.anti_steal_token = no |
| 51 | +http.secret_key = FastDFS1234567890 |
| 52 | +
|
| 53 | +tracker_server = 10.0.11.247:22122 |
| 54 | +tracker_server = 10.0.11.248:22122 |
| 55 | +tracker_server = 10.0.11.249:22122 |
| 56 | +``` |
| 57 | + |
| 58 | + 注1:tracker_server指向您自己IP地址和端口,1-n个 |
| 59 | + 注2:除了tracker_server,其它配置项都是可选的 |
| 60 | + |
| 61 | + |
| 62 | +## .properties 配置文件、所在目录、加载优先顺序 |
| 63 | + |
| 64 | + 配置文件名 fastdfs-client.properties(或使用其它文件名 xxx-yyy.properties) |
| 65 | + |
| 66 | + 文件所在位置可以是项目classpath(或OS文件系统目录比如/opt/): |
| 67 | + /opt/fastdfs-client.properties |
| 68 | + C:\Users\James\config\fastdfs-client.properties |
| 69 | + |
| 70 | + 优先按OS文件系统路径读取,没有找到才查找项目classpath,尤其针对linux环境下的相对路径比如: |
| 71 | + fastdfs-client.properties |
| 72 | + config/fastdfs-client.properties |
| 73 | + |
| 74 | +``` |
| 75 | +fastdfs.connect_timeout_in_seconds = 5 |
| 76 | +fastdfs.network_timeout_in_seconds = 30 |
| 77 | +fastdfs.charset = UTF-8 |
| 78 | +fastdfs.http_anti_steal_token = false |
| 79 | +fastdfs.http_secret_key = FastDFS1234567890 |
| 80 | +fastdfs.http_tracker_http_port = 80 |
| 81 | +
|
| 82 | +fastdfs.tracker_servers = 10.0.11.201:22122,10.0.11.202:22122,10.0.11.203:22122 |
| 83 | +``` |
| 84 | + |
| 85 | + 注1:properties 配置文件中属性名跟 conf 配置文件不尽相同,并且统一加前缀"fastdfs.",便于整合到用户项目配置文件 |
| 86 | + 注2:fastdfs.tracker_servers 配置项不能重复属性名,多个 tracker_server 用逗号","隔开 |
| 87 | + 注3:除了fastdfs.tracker_servers,其它配置项都是可选的 |
| 88 | + |
| 89 | + |
| 90 | +## 加载配置示例 |
| 91 | + |
| 92 | + 加载原 conf 格式文件配置: |
| 93 | + ClientGlobal.init("fdfs_client.conf"); |
| 94 | + ClientGlobal.init("config/fdfs_client.conf"); |
| 95 | + ClientGlobal.init("/opt/fdfs_client.conf"); |
| 96 | + ClientGlobal.init("C:\\Users\\James\\config\\fdfs_client.conf"); |
| 97 | + |
| 98 | + 加载 properties 格式文件配置: |
| 99 | + ClientGlobal.initByProperties("fastdfs-client.properties"); |
| 100 | + ClientGlobal.initByProperties("config/fastdfs-client.properties"); |
| 101 | + ClientGlobal.initByProperties("/opt/fastdfs-client.properties"); |
| 102 | + ClientGlobal.initByProperties("C:\\Users\\James\\config\\fastdfs-client.properties"); |
| 103 | + |
| 104 | + 加载 Properties 对象配置: |
| 105 | + Properties props = new Properties(); |
| 106 | + props.put(ClientGlobal.PROP_KEY_TRACKER_SERVERS, "10.0.11.101:22122,10.0.11.102:22122"); |
| 107 | + ClientGlobal.initByProperties(props); |
| 108 | + |
| 109 | + 加载 trackerServers 字符串配置: |
| 110 | + String trackerServers = "10.0.11.101:22122,10.0.11.102:22122"; |
| 111 | + ClientGlobal.initByTrackers(trackerServers); |
| 112 | + |
| 113 | + |
| 114 | +## 检查加载配置结果: |
| 115 | + |
| 116 | + System.out.println("ClientGlobal.configInfo(): " + ClientGlobal.configInfo()); |
| 117 | +``` |
| 118 | +ClientGlobal.configInfo(): { |
| 119 | + g_connect_timeout(ms) = 5000 |
| 120 | + g_network_timeout(ms) = 30000 |
| 121 | + g_charset = UTF-8 |
| 122 | + g_anti_steal_token = false |
| 123 | + g_secret_key = FastDFS1234567890 |
| 124 | + g_tracker_http_port = 80 |
| 125 | + trackerServers = 10.0.11.101:22122,10.0.11.102:22122 |
| 126 | +} |
| 127 | +``` |
0 commit comments