Thursday, July 28, 2011

Adding JAXB / jxc support in maven

Put your schemas (*.xsd) and bindings (*.xjb) into the src/main/resources folder.
Correct pom.xml as you add:
<build>
 <plugins>
  <plugin>
   <groupId>org.jvnet.jaxb2.maven2</groupId>
   <artifactId>maven-jaxb2-plugin</artifactId>
   <executions>
    <execution>
     <goals>
      <goal>generate</goal>
     </goals>
     <configuration>
      <args>
       <arg>-nv</arg><!-- this disable strict schema validation -->
      </args>
     </configuration>
    </execution>
   </executions>
  </plugin>
  <plugin>
   <inherited>true</inherited>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   <configuration>
    <source>1.5</source>
    <target>1.5</target>
   </configuration>
  </plugin>
 </plugins>
</build>

First steps in maven - empty project

First way - iteractive
Go to the directory, where you want to place the folder of the new project (d:\projects)
mvn archetype:generate
Some output from maven show. We run the interaction version. Here are my answers to it:
Choose a number: 112:
Choose version:
1: 1.0-alpha-1
2: 1.0-alpha-2
3: 1.0-alpha-3
4: 1.0-alpha-4
5: 1.0
6: 1.1
Choose a number: 6: 5
Define value for property 'groupId': : com.YOUR_COMPANY.YOUR_PROJECT_PACKAGE
Define value for property 'artifactId': : PROJECT_NAME
Define value for property 'version':  1.0-SNAPSHOT: : PROJECT_VERSION
Define value for property 'package':  com.YOUR_COMPANY.YOUR_PROJECT_PACKAGE: :
Confirm properties configuration:
groupId: com.YOUR_COMPANY.YOUR_PROJECT_PACKAGE
artifactId: PROJECT_NAME
version: PROJECT_VERSION
package: com.sepbulgaria.eshop.messages
You are ready!

Second way - non-interactive

mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -Dversion=1.0-SNAPSHOT -DinteractiveMode=false

Wednesday, July 27, 2011

Extending enums in Java

public enum DataStatus
{
    DECLINED_BY_USER("DECLINED-BY-USER"),
    SUCCESSFUL("SUCCESSFUL"),
    SPAM("SPAM");

    private String code;
    
    private DataStatus(String code) {
         this.code = code;
    }
    
    public String getCode() { return code; }
    
    public String toString(){ return code; } // if you want it so
    
    public static DataStatus parse( String s ){
        s = s.toUpperCase();
        if( s.equals( "SUCCESSFUL" ) )
            return SUCCESSFUL;
        if( s.equals( "DECLINED-BY-USER" ) )
            return DECLINED_BY_USER;
        if( s.equals( "SPAM" ) )
            return SPAM;
        return null;
    }
}    

Monday, July 18, 2011

kickstart commands for mysql (create database & user)

mysql -u root -p --port=3306

CREATE DATABASE database_name;

CREATE USER 'user1'@'localhost' IDENTIFIED BY 'pass1';

GRANT SELECT,INSERT,UPDATE,DELETE,DROP,CREATE       ON database_name.* TO 'user1'@'localhost';
GRANT SELECT,INSERT,UPDATE,DELETE,DROP,CREATE,ALTER,INDEX ON database_name.* TO 'user1'@'localhost';

FLUSH PRIVILEGES;


(mysql database) UPDATE user SET Password=PASSWORD('new_pass') WHERE User='username';

(mysql database) UPDATE user SET User='username_new' WHERE User='username_old';


For everyone host use '%' instead of 'localhost'

Wednesday, July 13, 2011

svn.exe for Windows

The problem is that tortoise svn comes without svn.exe, no command utility exists... Bad for all black screen fans.

The solution is to download svn-win32-1.6.6.zip from here, or newer version, if available. Point PATH variable to bin folder and you are done. All needed DLL are inside the archive.