xiaoxing tech

January 21, 2009

run Groovy’s groovyConsole.bat, got SecurityException: Prohibited package name: java.lang

Filed under: groovy, Java — xiaoxing @ 12:38 pm

java groovy

Solution:
My system’s CLASSPATH variable contains this entry: C:\midp2.0fcs\classes
Delete it then groovyConsole.bat will work.
Other entries in the CLASSPATH don’t matter.

Advertisements

January 16, 2009

use Mail Server Pro to send email to myself, on localhost

Filed under: app, email, Java, server — xiaoxing @ 12:47 pm

email, java, server, app

1. Install Mail Server Pro (one month trial). A windows service (SMTP Server Service) will be installed.
    Change settings: Authentication is not required.
                               IP Range Lists, add “1×2.1x.6.×9” local ip address.
                               Local Domains add chao.com
                               Domain Users add “richie” and “xing”
2. Outlook add account: richie@zhao.com; POP3 incoming server “1×2.1x.6.×9”; SMTP localhost; user name “richie@zhao.com”
3. In java code (-context.xml): sender (JavaMailSenderImpl)’s host property: localhost

November 21, 2008

Failed to load or instantiate TagLibraryValidator class

Filed under: Java, JSP, Spring — xiaoxing @ 9:52 am

running the springMVC-petclinic-hibernate sample app,
got this:
SEVERE: Exception Processing ErrorPage[exceptionType=java.lang.Exception, location=/WEB-INF/jsp/uncaughtException.jsp]
org.apache.jasper.JasperException: /WEB-INF/jsp/uncaughtException.jsp(1,1) Failed to load or instantiate TagLibraryValidator class: org.apache.taglibs.standard.tlv.JstlCoreTLV
        at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)

solution: create a folder springMVC-petclinic-hibernate\web\WEB-INF\lib, then put jstl.jar and standard.jar inside it.
reason: even though the jstl.jar is already in classpath, it’s ignored by the servlet container; have to put the jar along with jsp pages manually.

November 19, 2008

hibernate-validator-3.1.0.GA not compatible with Core_hibernate-distribution-3.3.1.GA

Filed under: hibernate, Java, JSP — xiaoxing @ 4:04 pm

Use hibernate-validator-3.1.0.GA with Core_hibernate-distribution-3.3.1.GA,
got this error:
java.lang.NoSuchMethodError: org.hibernate.event.PreUpdateEvent.getSource()Lorg/hibernate/engine/SessionImplementor;
at org.hibernate.validator.event.ValidateEventListener.onPreUpdate(ValidateEventListener.java:177)
at org.hibernate.action.EntityUpdateAction.preUpdate(EntityUpdateAction.java:237)

solution: download hibernate-distribution-3.3.0.SP1, use the old hibernate3.jar to replace the new one in distribution-3.3.1.GA.

http://opensource.atlassian.com/projects/hibernate/browse/HV-66

java.lang.NoSuchFieldError: name org.slf4j.impl.Log4jLoggerAdapter.(Log4jLoggerAdapter.java

Filed under: hibernate, Java, JSP — xiaoxing @ 11:53 am

problem: AnnotationConfiguration cfg = new AnnotationConfiguration(); fails
and javax.servlet.ServletException: Servlet.init() for servlet PersistentController threw exception
java.lang.NoSuchFieldError: name
    org.slf4j.impl.Log4jLoggerAdapter.<init>(Log4jLoggerAdapter.java:75)

   
solution: download a new http://www.slf4j.org/dist/slf4j-1.5.2.tar.gz
(having multiple javassist.jar doesn’t matter)
http://groups.google.com/group/comp.lang.java.programmer/browse_thread/thread/c6d647699b02fb5e/becc5c738902506b?tvc=2#becc5c738902506b

November 17, 2008

servlet problem: hibernate-validator (requestValidator.getInvalidValues(data) fails)

Filed under: hibernate, Java, JSP — xiaoxing @ 4:38 pm

This section of code fails (data is the bean object):

InvalidValue[] validationMessages;
ClassValidator requestValidator = new ClassValidator(data.getClass());
validationMessages = requestValidator.getInvalidValues(data);
//fails here!

Don’t know why but this works (“hobby” is one of the fields of the data bean):
requestValidator.getInvalidValues(data, “hobby”)

So, I modified the whole section to use request’s getParameterMap to traverse each bean property:
    InvalidValue[] validationMessages;
    List<InvalidValue[]> validationMsgList = new ArrayList<InvalidValue[]>();
    ClassValidator requestValidator = new ClassValidator(data.getClass());
    Map pMap = request.getParameterMap();
    Iterator ParIt = pMap.entrySet().iterator();
    while (ParIt.hasNext()) {
            Map.Entry pairs = (Map.Entry) ParIt.next();
            String key = “” + pairs.getKey();
            validationMessages = requestValidator.getInvalidValues(data, key);
            validationMsgList.add(validationMessages);
    }

App finally runs.

November 14, 2008

Java regex (Regular expression)

Filed under: Java, regex — xiaoxing @ 12:41 pm

regex java

US Zip Code: \d{5}(?:-\d{4})?
A zip code has two formats: five digits OR five digits, a hyphen and four more digits.
\d{5}: the pattern starts with five digits. The 5 within the braces indicates that the previous pattern should match five times.
(?:-\d{4})?: It’s a non-capturing parenthesis, starts with (?:. Question mark at the end means optional.
-\d{4}: a hyphen followed by four digits

US SSN(social security number): \d{3}([-]?)\d{2}\1\d{4}
the digits are written in two different ways: as nine digits or as three digits, a hyphen, two digits, another hyphen and four more digits.
\d{3}: The pattern starts with three digits
([-]?): is a capturing group. Inside the group is an optional hyphen. Whatever matches inside the parentheses will be remembered and can be recalled later in the pattern as \1.
\d{2}: two more digits.
\1: the symbol for the grouped pattern from earlier in the regular expression. If a hyphen was used earlier in the expression, then a hyphen must be used here. If a hyphen was not matched earlier, then a hyphen cannot be entered here.
\d{4}: four more digits.

User ID: [a-zA-Z]{3,5}[a-zA-Z0-9]?\d{2}
might be from three to five letters followed by three digits or three to six letters followed by two digits.

Note: When writing regular expressions in Java, each \ character must be written as double backslashes, \\.

1. Square brackets define a character class. [xyz] will match x, y or z, but only one of them.
2. If the class starts with ^, then it will match all characters that are not listed inside the brackets: [^abc] any character except a, b or c (negation)
3. A hyphen can be used to include a range of characters: [a-z] will match any lowercase letter. [a-zA-Z] a through z or A through Z, inclusive (range)

Character Class Meaning
. Any character, except line terminators
\d A digit: [0-9]
\D A non-digit: [^0-9]
\s A whitespace character: [ \t\n\x0B\f\r]
\S A non-whitespace character: [^\s]
\w A word character: [a-zA-Z_0-9]
\W A non-word character: [^\w]

November 13, 2008

using local Subversion server with Netbeans

Filed under: subversion, tool — xiaoxing @ 10:38 am

tool subversion

1. download CollabNet Subversion Server and Client v1.5.4 (for Windows) and install (Apache mod is not necessary)
2. make local repository from command line c:\: svnadmin create svn_repository
3. (folder c:\svn_repository will be created with some svn contents)
4. (from server point of view) import a project into the repository, from Netbeans: right click the project……, repository url: file:///svn_repository

also, to delete a repository, just do it through windows explorer. no this command from svnadmin.

November 5, 2008

access Google Data APIs, behind proxy

Filed under: google, intranet, Java — xiaoxing @ 9:58 am

google, java

(libraries needed: gdata, JavaMail, servlet2.4)
In Eclipse, under application’s context menu “run as, run configurations”:
program arguments: xxzhao@gmail.com xxzhaospsw
VM arguments: -Dhttp.proxyHost=proxysrv007-zhengxian -Dhttp.proxyPort=8080 -Dhttps.proxyHost=proxysrv007-zhengxian -Dhttps.proxyPort=8080 -Dhttp.proxyUser=liezi.info\xxing -Dhttp.proxyPassword=e*********

October 31, 2008

start the HSQLDB server

Filed under: database — xiaoxing @ 1:15 pm

1. To start the HSQLDB server, open up a command line, change into your WORKDIR(C:\jee_workplace\test), and run the command: java -classpath lib/hsqldb.jar org.hsqldb.Server
2. gui tool: java -cp lib/hsqldb.jar org.hsqldb.util.DatabaseManager        Type: HSQL Database Engine Server    jdbc:hsqldb:hsql://localhost (from democal.properties)    sa    ??    )
3. (You?ll also find some new files in your WORKDIR, starting with test?these are the files used by HSQLDB to store your data. If you want to start with a fresh database, delete the files between restarts of the server.)
4. Exporting the database schema (automatic generation): (prerequisites: domain model classes and mapping-metadata-in-XML or Annotations-in-Java)    using an ant task: taskdef name=”hibernatetool” and target name=”schemaexport”.
5. database browser: ant task: target name=”dbmanager”

Older Posts »

Create a free website or blog at WordPress.com.