软件是对质量的不懈追求

2010年7月28日 #

linux du 查看文件夹占用空间


du -sh *

posted @ 2011-04-15 08:39 BlakeSu 阅读(274) | 评论 (0)编辑 收藏

Building Standalone Application with Maven2

If you are building standalone application in Java, Maven is your friend when packing your application,
There are two way to let Maven package your application, either as a single jar with all your dependencies jar.


 <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-assembly-plugin</artifactId>
  <configuration>
   <descriptorRefs>
    <descriptorRef>jar-with-dependencies</descriptorRef>
   </descriptorRefs>
  </configuration>
 </plugin>



One advantage if you choose to do this way is if you need to sign your application jar.
This is needed if you are building a Java Web Start client and you need more access than connecting back to the server.
To read more about have Maven signing your jar read http://maven.apache.org/plugins/maven-jar-plugin/usage.html.
But if you choose to go this way, make sure that all license agreement are shipped with your one single jar.

Another way is to let Maven package your source code only and then referring the dependent jar file from the MANIFEST file.


 <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  <configuration>
   <archive>
    <manifest>
     <addClasspath>true</addClasspath>
     <mainClass>se.msc.adapter.Main</mainClass>
     <classpathPrefix>lib/</classpathPrefix>
    </manifest>
   </archive>
  </configuration>
 </plugin>

posted @ 2011-02-24 13:03 BlakeSu 阅读(318) | 评论 (0)编辑 收藏

eclipse 终于有了列编辑功能

eclipse 3.5之后终于有了列编辑,快捷键是alt+shift+a,再次按此快捷键返回常规编辑状态。


posted @ 2010-10-15 11:33 BlakeSu 阅读(1472) | 评论 (0)编辑 收藏

LineNumberReader 指定文件编码


import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;


public class Main {
    
    
public static void main(String[] args) throws IOException {

        InputStreamReader isr 
= new InputStreamReader(new FileInputStream("15370720.pdf4"), "utf-16");
        LineNumberReader lnr
=new LineNumberReader(isr);
        String line 
= null;
        
while((line=lnr.readLine())!=null){  
           System.out.println(lnr.getLineNumber()
+"\t"+line);
        }
   }
}

posted @ 2010-08-05 09:13 BlakeSu 阅读(1037) | 评论 (0)编辑 收藏

Class.getResourceAsStream 和 ClassLoader.getResourceAsStream

两个方法的区别是资源的定义不同, 一个主要用于相对与一个object取资源,而另一个用于取相对于classpath的
资源,用的是绝对路径。

在使用Class.getResourceAsStream 时, 资源路径有两种方式, 一种以 / 开头,则这样的路径是指定绝对
路径, 如果不以 / 开头, 则路径是相对与这个class所在的包的。

在使用ClassLoader.getResourceAsStream时, 路径直接使用相对于classpath的绝对路径。

举例,下面的三个语句,实际结果是一样的:
   com.explorers.Test.class.getResourceAsStream("abc.jpg")
= com.explorers.Test.class.getResourceAsStream("/com/explorers/abc.jpg")
= ClassLoader.getResourceAsStream("com/explorers/abc.jpg")

posted @ 2010-07-28 16:31 BlakeSu 阅读(284) | 评论 (0)编辑 收藏