Recent Notes
Displaying keyword search results 111 - 120
Created by Dr. Xi on November 19, 2008 00:22:27
Last update: January 07, 2010 23:00:36
There is a open source project named [ini4j] for processing Windows .ini configuration files. However, I found it an overkill for my purposes. So here is my simple implementation of a .ini parser. It mimics the standard java.util.Properties class with enhancements to get and set properties by section name. There are only a few simple rules: Leading and trailing spaces are trimmed from section names, property names and property values. Section names are enclosed between [ and ] . Properties following a section header belong to that section Properties defined before the appearance of any section headers are considered global properties and should be set and get with no section names. You can use either equal sign ( = ) or colon ( : )...
Created by Fang on September 07, 2009 16:39:37
Last update: September 07, 2009 18:43:04
It's easiest to use the archetype plugin to start a new Maven project. I'll use struts 1 as example since it's not in the built-in archetypes for archetype:generate . Generate a simple webapp with archetype:generate :
C:\work\maven>mvn archetype:generate -DarchetypeAr... It generates a directory structure like this: struts1app struts1app/pom.xml struts1app/src... with a simple POM: <project xmlns="http://maven.apache.org/POM/4.0.0"... Create settings.xml in $HOME/.m2 , add Java.net repository for Java EE dependencies: <?xml version="1.0" encoding="UTF-8"?> <setting... Add Java EE and Struts dependencies in pom.xml . Note that the Java EE dependency has scope provided , meaning that the web app container provides the jars, therefore we don't need to bundle them with our war fie. <project xmlns="http://maven.apache.org/POM/4.0.0"... Create a directory named java under main , create the Struts form and...
Created by Dr. Xi on May 05, 2009 20:06:16
Last update: May 05, 2009 20:06:38
Write to a file, overwrite if it exists:
f = open ('test.txt', 'w')
f.write ('li...
Append to a file:
f = open ('test.txt', 'a')
f.write ('li...
Created by Dr. Xi on February 09, 2009 23:14:15
Last update: February 09, 2009 23:14:15
This example demonstrates the general steps in creating a custom Java class loader. Normally a class loader would consult its parent class loader when asked to load a class. If it's not loaded by the parent class loader, then the class loader would try to load the class on its own. This class loader tries to load the requested class on its own first, and delegates to the parent only when a java.lang.SecurityException is thrown (which happens when it tries to load core Java classes such as java.lang.String ). The classes are loaded from CLASSPATH through the getResourceAsStream call. It's important to note that when a class is loaded with a certain class loader, all classes referenced from that class are also loaded through the...
Created by Dr. Xi on January 29, 2009 17:11:34
Last update: January 29, 2009 17:11:34
import java.awt.Color;
import java.awt.Font;
...
Created by Dr. Xi on October 16, 2008 23:09:28
Last update: October 17, 2008 03:30:38
import java.io.*;
public class TestMSOffice...
Created by Dr. Xi on August 21, 2008 22:35:24
Last update: October 16, 2008 02:27:59
import java.net.*;
import java.io.*;
pub...
An example for POSTing from Java is available from here: http://www.javaworld.com/javaworld/javatips/jw-javatip34.html
Created by Dr. Xi on October 14, 2008 23:02:29
Last update: October 14, 2008 23:03:50
Wrap JWhich in a servlet:
Implement the servlet:
package com.example;
import java.io.*;
...
Add this to web.xml :
<servlet>
<servlet-name>jwhich</servlet...
Request the path for a class or properties file:
http://mydomain.com/jwhich/com.example.SomeCla...
Created by Dr. Xi on October 02, 2008 22:22:59
Last update: October 02, 2008 22:24:26
Use File::new with error handling.
counter = 1
begin
file = File.new("ftp.sh...
Use File::open without error handling.
File.open("ftp.sh") do |file|
file.each_line...
Created by Dr. Xi on September 25, 2008 02:53:57
Last update: September 25, 2008 02:53:57
import java.io.*;
public InputStream st...