• Maven’s common problems and solutions

    1. No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

    As the error message display,perhaps you used JRE for maven, but it needs JDK(in fact, javac) as compiler. JRE is just the Java runtime environment, while JDK is the Java development kit containing the the compiler javac for java code. In fact, Eclipse uses JRE as its default environment, and used its own compiler JDT. So when using maven to compile, the operation fails.

    Solution: go into  Windows -> Perferences -> Java -> Installed JREs. Note the underlined part is jdk not jre.

    .jres

     

    2. Could not resolve dependencies for project XXX:jar:0.1: Failure to find XXX:jar:0.0.1 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced.

    There are some files with the names ending in the .lastUplated suffix in your local repository, so maven will not compile again.

    Solution:

    1) for maven command: mvn clean install -U

    2) for Eclipse:

    mvn

     

    3. error reading C:\Users\Administrator\.m2\repository\XXX.jar; invalid LOC header (bad signature)

    That is because there are some incomplete in maven local repository. May be you can see some files with names ending in -in-progress suffix.

    123
    Solution: delete the whole folder which contains the incomplete jar file, and compile again.
  • 网站异常发送异常代码到邮箱

    为了对用户的请求作统一处理,所以把Struct的Action封装成了一个AbstractAction。

    其中AbstractAction重写了Action类的execute方法,其中一个统一处理就是异常的处理。

    刚好最近想到了代码抛异常时就发邮件通知,这样既能立刻接收到异常的信息,也能对异常归档。

    刚开始打算直接用Exception的getCause()内容作为邮件内容发送,不过只有异常的原因,没有异常

    出现的定位信息:

    e.getCause()
    (java.lang.NullPointerException) java.lang.NullPointerException

    最后用到Exception的printStackTrace(PrintStream s)方法,并且采用了可变尺寸的线程池来发送邮件,主要是在以前构造的线程可用时将重用它们,代码如下:

    try {

    // code

    } catch (Exception e) {

    e.printStackTrace();

    logger.error(e.getCause());

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    e.printStackTrace(new PrintStream(baos));

    String url = request.getRequestURL().toString() ;

    if(request.getQueryString()!=null){

    url+=”?” + request.getQueryString();

    }

    exception = “请求地址为:”+url+ “<br>” ;

    exception += “请求IP为:”+IPUtil.getIpAddr(request)+ “<br>” ;

    exception += baos.toString();

    //ex为AbstractAction类的属性

    //private ExecutorService ex = Executors.newCachedThreadPool();

    ex.execute(new Runnable() {

    @Override

    public void run() {

    // sendEmail(String addr, String title, String content)

    eMailService.sendEmail(“XXX@gmail.com”, “后台异常”,exception);

    }

    });

    }

    通过获取这些异常信息也可以发现某些对网站的异常访问,例如这次访问产生的异常:(下面代码用*取代了真实IP)

    请求地址为:http://******/front/indexNotLogin.do?action=viewAgreement&id=../../../../../../../../../../../../../sbin/../etc/./rc.d/../rc.d/.././passwd%00.htm 请求IP为:203.130.**.*** java.lang.reflect.InvocationTargetException at sun.reflect.GeneratedMethodAccessor239.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at

    这样就可以把203.130.**.***这个IP添加到黑名单了!

  • Ibatis列名无效

    最近在用ibatis连接Oracle,出现了几种列名无效的情况:

    — The error occurred in com/kingdee/youshang/basedata/mapper/ProductOnSale.xml.
    — The error occurred while applying a result map.
    — Check the ProductOnSale.ProductOnSaleResult.
    — Check the result mapping for the ‘id’ property.
    — Cause: java.sql.SQLException: 列名无效]; SQL was [] for task [SqlMapClient operation]

    将一些可能的原因列出来:

    一、SQL语句映射文件:

    1.查询语句返回的结果字段集不是所对应resultMap里面映射字段集的父集或相等,例如:

    resultMap 映射为:

    <resultMap class=”ProductOnSale” id=”ProductOnSaleResult”>
    <result column=”FID” javaType=”long” jdbcType=”BIGINT” property=”id”/>
    <result column=”FFUNDNAME” javaType=”string” jdbcType=”VARCHAR” property=”fundname”/>
    </resultMap>

     

    而SQL返回只有FFUNDNAME(没有FID):

    <select id=”findProducts” resultMap=”ProductOnSaleResult”>/*dialect*/
    SELECT FFUNDNAME FROM T_BS_PRODUCT_ON_SALE POS
    </select>

    2.resultMap配置里面的字段名前面加了表名:

    <resultMap id=”ProductOnSaleResult”>
    <result column=”POS.FID” javaType=”long” jdbcType=”BIGINT” property=”id”/>
    <result column=”POS.FFUNDNAME” javaType=”string” jdbcType=”VARCHAR” property=”fundname”/>
    </resultMap>