如果找到了对您有用的资料,烦请点击右手边的Google广告支持我继续共享知识,谢谢! http://dengpeng.spaces.live.com/

2007年4月15日星期日

被点名暴露隐私~

游戏规则:

1.由某个blog发起,出一个题目。

2.在自己的blog中完成题目 (同时以回帖的方式回复在本贴下面),然后点名另外5blog完成同样的题目

3.另外的5blog完成题目以后再分别点名,依次类推。

4.被点名的blog在完成题目时要注明被哪个blog点名。

5.点名者要去被点名者的blog里留言,告知他(她)已被点名。

6.不可回传,加一条自己出的题。

1.传下去的五个人

Michael

Kurt

Fedrara

Steve

MZD

2.你的名字

Paul

3.多大

22

4.职业是

计算机的奴隶

5.兴趣是

计算机, 摄影,游泳

6.喜欢的异性类型

不好意思,回答这个问题的时候内存溢出了

7、专长/特技是什么?

睡觉,吃饭

8.有沒有什么证书

小学毕业证,中学毕业证,……没了

9.有烦恼的事情吗

太多了,都忘了

10.喜欢和讨厌的食物

喜欢:都,尤其怀念我妈做的菜,三只耳和溜洋狗

讨厌:肥肉 (出来了,开始吃了

11.对你爱的人说一句话

12.请介紹一下你要传下去的那5个人

我是被逼的~~J

13.选一种颜色來比喻传问卷給你的人

红色

14.用一种动物來比喻传问卷給你的人

猎豹

15.用喜欢的角色來比喻传问卷給你的人角色

相当有特色,还没有符合其特色的角色

16.用食物來比喻传问卷給你的人

烧烤

17.用颜色來比喻將接棒的五人

黄色,浅蓝,银色,matrix绿,白色

18.怎么看《东京爱情故事》

没看过

19.你心中最简单卻又最难做到的事情是什么

成功人士

20.有哪三個地方是觉得不去的话就枉度此生的

美国,GoogleIBM

21.今天晚上吃什么

方便面

22.如果现在有一碗孟婆汤在你面前 你会喝么?

不喝,我喜欢喝可乐(无糖的那种)

23. 用一款香水或者一种味道來比喻传问卷給你的人

芥末,绝对够劲

24、你最近的一个目标是什么呢?

考试得高分

25、你自己最爱的收藏是什么?

照片,软件

26、现在最想去旅游的地方?(箫扬添加)

悉尼

27、如果有下辈子,你愿意是什么性别?(六弦添加)

美女

28、没有朋友,真正的朋友,你会怎样?(TT添加)

垮掉

29、你知道怎样是爱上一个人吗?(yy+)

不知道

30、喜欢什么样的异性?(day+)

不太清楚,反正走在街上眼睛就没停过

31、圣诞节会送偶一张贺卡不?(Vivi+

请把电子邮件留下,给你eCard

32,能不能稍稍多关注一下国家队?……(羞愧的飘过)

有难度

33。什么时候能真正富裕起来啊?(曹添加+

前途渺茫,走一步算一步

34.最想什么时候组建自己的家庭?(靓茹+

我还是青少年

35.最怕的事情(Annie+)

一直是穷人

36.不开心的时候干什么(Judy+

喝酒,睡觉

37你最介意自己的男友(女友)什么 (杨磊添加)

38 你会为对方改变自己么?(徐佳+

最开始,我尝试调教她。结果失败,我反而被调教了

39 里面, 最喜欢哪个人物? (Wei Ren +)

周围的人都在看,就我不看

40. 找两三个词形容一下传问卷这个人 (朱学敏 +

聪明,活力,魅力

41.你能立马写出洛仑兹变换的公式吗? (李爽 +

最近弄的是矩阵运算和数论初高中数学40/150分的人,现在天天和数学打交道

42.上次回家看父母是什么时候?(Paul +

快一年了,但愿明年春节能够回家


被李爽点名

2007年4月2日星期一

Double Click to Run JAR File

Digested from Java Tip 127: See JAR run

The manifest file and the Main-Class entry

Inside most JARs, a file called MANIFEST.MF is stored in a directory called META-INF. Inside that file, a special entry called Main-Class tells the java -jar command which class to execute.

The problem is that you must properly add this special entry to the manifest file yourself—it must go in a certain place and must have a certain format. However, some of us don't like editing configuration files.


Let the API do it for you

Since Java 1.2, a package called java.util.jar has let you work with jar files. (Note: It builds on the java.util.zip package.) Specifically, the jar package lets you easily manipulate that special manifest file via the Manifest class.

Let's write a program that uses this API. First, this program must know about three things:

1. The JAR we wish to make runnable
2. The main class we wish to execute (this class must exist inside the JAR)
3. The name of a new JAR for our output, because we shouldn't simply overwrite files

Write the program

The above list will constitute our program's  arguments. At this point, let's choose a suitable name for this application. How does MakeJarRunnable sound?
Check the arguments to main

Assume our main entry point is a standard main(String[]) method. We should first check the program arguments here:

    if (args.length != 3) {
System.out.println("Usage: MakeJarRunnable "+ "<jar file> <Main-Class><output>");
System.exit(0);
}

Please pay attention to how the argument list is interpreted, as it is important for the following code. The argument order and contents are not set in stone; however, remember to modify the other code appropriately if you change them.



Access the JAR and its manifest file


First, we must create some objects that know about JAR and manifest files:

    //Create the JarInputStream object, and get its manifest
JarInputStream jarIn = new JarInputStream(new FileInputStream(args[0]));
Manifest manifest = jarIn.getManifest();
if (manifest == null) {
//This will happen if no manifest exists
manifest = new Manifest();
}

Set the Main-Class attribute

We put the Main-Class entry in the manifest file's main attributes section. Once we obtain this attribute set from the manifest object, we can set the appropriate main class. However, what if a Main-Class attribute already exists in the original JAR? This program simply prints a warning and exits. Perhaps we could add a command-line argument that tells the program to use the new value instead of the pre-existing one:

    Attributes a = manifest.getMainAttributes();
String oldMainClass = a.putValue("Main-Class", args[1]);
//If an old value exists, tell the user and exit
if (oldMainClass != null) {
System.out.println("Warning: old Main-Class value is: "
+ oldMainClass);
System.exit(1);
}

Output the new JAR

We need to create a new jar file, so we must use the JarOutputStream class. Note: We must ensure we don't use the same file for output as we do for input. Alternatively, perhaps the program should consider the case where the two jar files are the same and prompt the user if he wishes to overwrite the original. However, I reserve this as an exercise for the reader. On with the code!

    System.out.println("Writing to " + args[2] + "...");
JarOutputStream jarOut = new JarOutputStream(new FileOutputStream(args[2]),manifest);
We must write every entry from the input JAR to the output JAR, so iterate over the entries:
    //Create a read buffer to transfer data from the input
byte[] buf = new byte[4096];
//Iterate the entries
JarEntry entry;
while ((entry = jarIn.getNextJarEntry()) != null) {
//Exclude the manifest file from the old JAR
if ("META-INF/MANIFEST.MF".equals(entry.getName())) continue;
//Write the entry to the output JAR
jarOut.putNextEntry(entry);
int read;
while ((read = jarIn.read(buf)) != -1) {
jarOut.write(buf, 0, read);
}
jarOut.closeEntry();
}
//Flush and close all the streams
jarOut.flush();
jarOut.close();
jarIn.close();

Complete program

Of course, we must place this code inside a main method, inside a class, and with a suitable set of import statements. The Resources section provides the complete program.



Usage example


Let's put this program to use with an example. Suppose you have an application whose main entry point is in a class called HelloRunnableWorld. (This is the full class name.) Also assume that you've created a JAR called myjar.jar, containing the entire application. Run MakeJarRunnable on this jar file like so:

java MakeJarRunnable myjar.jar HelloRunnableWorld myjar_r.jar

Again, as mentioned earlier, notice how I order the argument list. If you forget the order, just run this program with no arguments and it will respond with a usage message.

Try to run the java -jar command on myjar.jar and then on myjar_r.jar. Note the difference! After you've done that, explore the manifest files (META-INF/MANIFEST.MF) in each JAR. (You can find both JARs in the source code.)

Here's a suggestion: Try to make the MakeJarRunnable program into a runnable JAR!



Run with it


Running a JAR by double-clicking it or using a simple command is always more convenient than having to include it in your classpath and running a specific main class. To help you do this, the JAR specification provides a Main-Class attribute for the JAR's manifest file. The program I present here lets you utilize Java's JAR API to easily manipulate this attribute and make your JARs runnable.

source code and JARs for this tip