Java

pom.xml报错:

  • ArtifactTransferException: Failure to transfer... from.... cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced.

解决:

Go directly to the local warehouse, put the 1.1.1 directory deleted (since packet not download), again refresh your project on to, or on your project right click, select maven---> update can be, let Maven to download.

  •  Description Resource Path Location Type The container 'Maven Dependencies' references non existing library

          Missing artifact org.xerial.snappy:snappy-java:jar:1.1.1.6 pom.xml /realtimeanalyser line 1 Maven Dependency Problem

解决:pom.xml文件某一处(内容)写错了

 

log4j配置:

  • rollingfile

log4j.rootCategory=INFO,rollingfile

log4j.appender.rollingfile=org.apache.log4j.RollingFileAppender

log4j.appender.rollingfile.file=logs/app.log

log4j.appender.rollingfile.layout=org.apache.log4j.PatternLayout

log4j.appender.rollingfile.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{1}: %m%n

  • console

log4j.rootCategory=INFO, console

log4j.appender.console=org.apache.log4j.ConsoleAppender

log4j.appender.console.target=System.err

后面的layout和layout.ConversionPattern相同

 

  • The literal of int xxxxx is out of range
1 //Otherwise, the compiler will try to parse the literal as an int
2 long value = 9223372036854775807L;

 

  • Time

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,S");

try {
Date date = sdf.parse(dateStr);
long d = date.getTime();//dateString to long
} catch (Exception e) {
e.printStackTrace();
}

SimpleDateFormat函数语法:
         G 年代标志符
         y 年
         M 月
         d 日
         h 时 在上午或下午 (1~12)
         H 时 在一天中 (0~23)
         m 分
         s 秒
         S 毫秒
         E 星期
         D 一年中的第几天
         F 一月中第几个星期几
         w 一年中第几个星期
         W 一月中第几个星期
         a 上午 / 下午 标记符
         k 时 在一天中 (1~24)
         K 时 在上午或下午 (0~11)
         z 时区

Optional

http://www.importnew.com/6675.html

程序中模块划分:

main主类启动程序,工具类utils,配置文件config,IO/DB

类名不能太长(两层),太长用包名提供一层划分

包名/类名不能限定死,利于以后扩展

handle类时具体的业务逻辑

通过包名/类名/方法名就可以知道包/类/方法的作用

参考类似的开源代码:netty,voldemort

 

eclipse tab改为4空格:(如XML文件)

preference->XML Source

Indent using tabs,space设为4

ctl+shift+f更新文件中的格式

 

File/Stream close:

close应该放在finally,但是需要捕获异常--->IOUtils

 

  • 写入hdfs时异常:

spark写入hdfs时异常“AccessControlException: Permission denied: user=cloud, access=WRITE, inode="/test/checkpoint/6f6bdf24-93c7-48c1-a20e-04c9c850b882":hduser:supergroup:drwxr-xr-x.....”

权限错误:hdfs中的文件权限是hduser(启动hadoop的用户),应用写入时默认使用调用java的用户名

解决:修改java的环境--export HADOOP_USER_NAME=hdfs_user_name

原因:跟spark没有关系,应该是设置了java,使访问hdfs时以‘hdfs_user_name’访问了hdfs

参考:

http://stackoverflow.com/questions/11041253/set-hadoop-system-user-for-client-embedded-in-java-webapp

http://stackoverflow.com/questions/27427042/spark-unable-to-save-in-hadoop-permission-denied-for-user

  • maven

插件在私服没有,手动下载(http://mvnrepository.com/),执行

mvn install:install-file -DgroupId=org.apache.maven.plugins -DartifactId=maven-javadoc-plugin -Dversion=2.8.1 -Dpackaging=maven-plugin -Dfile=/path/to/file

 成功后,会在.m2中添加该jar及相关文件

或添加到私服

mvn deploy:deploy-file -DgroupId=org.apache.maven.plugins -DartifactId=maven-javadoc-plugin -Dversion=2.8.1 -Dpackaging=maven-plugin -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

 shade 2.X需要maven3,shade 1.X使用maven2

 

map遍历:

/**
 *Set<Map.Entry<K, V>> entrySet();
 */
/**
 *interface Entry<K,V> {
 *    K getKey();
 *    V getValue();
* ....
*}
*/ Map map = new HashMap();   Iterator iter = map.entrySet().iterator();   while (iter.hasNext()) {   Map.Entry entry = (Map.Entry) iter.next();   Object key = entry.getKey();   Object val = entry.getValue();

这种遍历Map的方法可以让我们在从Map中取得关键字之后,我们不用每次重复返回到Map中取得相对的值,效率高

posted @ 2015-12-11 18:34  Firewalls  阅读(490)  评论(0编辑  收藏  举报