Feed on Posts or Comments 10 March 2010

Monthly ArchiveJuly 2008



Java Wytze on 31 Jul 2008

Generating sql database schema with maven2 for hibernate3

I’m using maven with hibernate3 plugin to generate the sql code for my database schema/tables. I do so with the following configuration.
Also make sure you declare your driver in the plugin dependencies to be sure the driver can be loaded in the plugin. Otherwise you might get some JDBC exceptions.

Command line example:
mvn clean compile hibernate3:hbm2ddl
			<!-- 
				Hibernate 3 Plugin, used for schema creation
				Usage example: mvn clean compile hibernate3:hbm2ddl
			 -->
			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>hibernate3-maven-plugin</artifactId>
				<version>2.0-alpha-2</version>
				<configuration>
					<components>
						<component>
							<name>hbm2ddl</name>
							<implementation>annotationconfiguration</implementation>																									
						</component>							
					</components>
					<componentProperties>		
						<!-- Create Drop Statements -->					
						<drop>false</drop>
						<!-- Enable Annotations -->
						<jdk5>true</jdk5>
						<!-- Define Database Properties to Use -->
						<propertyfile>target/classes/database.properties</propertyfile>
						<!-- Pretty Format SQL Code -->
						<format>true</format>
						<!-- Create tables automatically? -->
						<export>false</export>
						<!-- Output filename -->
						<outputfilename>schema.sql</outputfilename>
					</componentProperties>
				</configuration>						
				<dependencies>
					<dependency>
						<groupId>com.oracle</groupId>
						<artifactId>ojdbc14</artifactId>
						<version>${oracle-driver.version}</version>
					</dependency>
				</dependencies>

Java Wytze on 31 Jul 2008

Using the maven exec plugin to launch hsqldb

Below is a short snippet I use to launch hsqldb automatically for unit testing in my java projects.
Biggest limitation to the exec-maven-plugin is that it can’t run processes asynchronous. This way a running application is blocking the maven process flow. A big limitation. I think they should add an option to be able to run the process in a separate process without blocking the flow if needed.

Below is the snippet, I tried to use the windows start command. But it didn’t really work.

					<!-- Execute plugin to launch hsqldb -->
					<plugin>
						<groupId>org.codehaus.mojo</groupId>
						<artifactId>exec-maven-plugin</artifactId>
						<version>1.1</version>
						<executions>
							<execution>								
								<phase>compile</phase>							
								<goals>
									<goal>exec</goal>
								</goals>
							</execution>
						</executions>
						<configuration>	
						 <!--
								start java 
									-cp "c:/Documents and Settings/%USERNAME%/.m2/repository/hsqldb/hsqldb/1.8.0.7/hsqldb-1.8.0.7.jar" 
									org.hsqldb.Server 
									-database.0 mydb 
									-dbname.0 xdb							-->
							<!-- use start to execute in separate thread -->
							<executable>start</executable>
							<!-- optional -->
							<workingDirectory>/hsqldb</workingDirectory>
							<arguments>
								<argument>java</argument>
								<argument>-cp</argument>
								<argument>"C:/Documents and Settings/%USERNAME%/.m2/repository/hsqldb/hsqldb/1.8.0.7/hsqldb-1.8.0.7.jar"</argument>
								<argument>org.hsqldb.Server</argument>
								<argument>-database.0</argument>
								<argument>mydb</argument>
								<argument>-dbname.0</argument>
								<argument>xdb</argument>
							</arguments>
						</configuration>
						<dependencies>
							<dependency>
				    			<groupId>hsqldb</groupId>
				    			<artifactId>hsqldb</artifactId>
				    			<version>1.8.0.7</version>
 							</dependency>
						</dependencies>
					</plugin>

Debian Wytze on 25 Jul 2008

Debian modifying permissions for files or directories

Sometimes you want to change specific settings to either files or directories on your debian machine. To be able to do this I use the find command combined with the xargs command. Have a look at some possible commands:

find /share/ -type f -print0 | xargs -0 chmod 664
find /share/ -type d -print0 | xargs -0 chmod 775

The first line tries to find files only with -type f. And prints them to the stream with -print0 so xargs can process them with the -0 command. -print0 will put a NUL value between pathnames. This way paths that contain spaces can be parsed correctly by xargs.
I think it is pretty nifty and once again shows the power of the console!