I use the copy line / copy selection under cursor in NetBeans a lot. So I created this macro for use in Visual Studio that provides this functionality. If no line is selected the current line where the cursor is placed will be copied.
When a selection is made the selection will be copied and pasted below the selection. Afterwards the selection will be remade so you can repeat the action immediately.
Below is the VB snippet.
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Public Module Famvdploeg
' Copy the current line or selection
Sub CopySelection()
Dim selection As String
Dim lines As Array
' Select current line if nothing is selected
If String.IsNullOrEmpty(DTE.ActiveDocument.Selection.Text) Then
DTE.ActiveDocument.Selection.StartOfLine(0)
DTE.ActiveDocument.Selection.EndOfLine(True)
End If
' Store some variables
selection = DTE.ActiveDocument.Selection.Text
lines = Split(selection, vbCrLf)
' Perform the copy+paste action depending on how selection is made
If String.IsNullOrEmpty(lines(lines.Length - 1)) Then
DTE.ActiveDocument.Selection.Copy()
DTE.ActiveDocument.Selection.EndOfLine(0)
DTE.ActiveDocument.Selection.StartOfLine(0)
DTE.ActiveDocument.Selection.Paste()
Else
DTE.ActiveDocument.Selection.Copy()
DTE.ActiveDocument.Selection.EndOfLine()
DTE.ActiveDocument.Selection.NewLine()
' Sanitize any auto text insertion
DTE.ActiveDocument.Selection.StartOfLine(0)
DTE.ActiveDocument.Selection.EndOfLine(True)
If Not String.IsNullOrEmpty(DTE.ActiveDocument.Selection.Text()) Then
DTE.ActiveDocument.Selection.Delete()
End If
DTE.ActiveDocument.Selection.StartOfLine(0)
DTE.ActiveDocument.Selection.Paste()
End If
If lines.Length > 1 Then
' ReSelect the text so we can repeat the action immediately
DTE.ActiveDocument.Selection.LineUp(False, lines.Length - 1)
DTE.ActiveDocument.Selection.StartOfLine(0)
DTE.ActiveDocument.Selection.LineDown(True, lines.Length - 1)
If Not String.IsNullOrEmpty(lines(lines.Length - 1)) Then
DTE.ActiveDocument.Selection.EndOfLine(True)
End If
Else
DTE.ActiveDocument.Selection.StartOfLine(0)
End If
End Sub
End Module
I ran out of brain capacity. So here is a list of commands to do some basic glassfish stuff.
| Updating: |
pkg image-update |
| Start domain: |
asadmin start-domain |
| Stop domain: |
asadmin stop-domain |
| Deploy item: |
asadmin deploy <path to file> |
| List JNDI entries: |
asadmin list-jndi-entries |
Having multiple jvm’s on your linux machine can be a pain in the ass. To select which jvm to use you can use the update-alternatives command. A small example of how to add a jvm to the alternatives here:
update-alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_11/bin/java 16011
This will add an entry for your jdk into the alternatives. The last number assigns the priority to this alternative. Which is the version and build number of the relase.
After adding you can use the following command to select the java version you want to use:
update-alternatives --config java
If you switch the java update-alternatives to auto it will automatically pick the java alternative with the highest priority.
I was going to write a whole lot of howto here. But why do that when you can just link to the Tomcat Wiki?
The wiki that shows you how to enable remote debugging is found here.
Here is a guide to building ejb3 applications with maven2 (from scratch). We will not be using any maven archetypes/templates but do it by hand to get a project that is as clean as possible.
First create a directory that will contain all the modules the ear file consists of. It will contain all the basic info the other projects/modules need to inherit from.
Create the pom.xml file in the directory and update it with something like the following:
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>your.group.id</groupId>
<artifactId>your-artifact-name</artifactId>
<packaging>pom</packaging>
<name />
<version>0.0.1-SNAPSHOT</version>
<description />
<modules>
<module>ear</module>
<module>war</module>
<module>ejb-jar</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Then create the subdirectories ( I named them ear, war and ejb-jar in this case ) for the modules.
ejb-jar pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>ejb-sample</artifactId>
<groupId>your.group.id</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>your.group.id</groupId>
<artifactId>ejb-jar</artifactId>
<name />
<version>0.0.1-SNAPSHOT</version>
<packaging>ejb</packaging>
<description />
<dependencies>
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>5.7</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<configuration>
<ejbVersion>3.0</ejbVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
war pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>ejb-sample</artifactId>
<groupId>your.group.id</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>your.group.id</groupId>
<artifactId>war</artifactId>
<packaging>war</packaging>
<name />
<version>0.0.1-SNAPSHOT</version>
<description />
<dependencies>
<dependency>
<groupId>your.group.id</groupId>
<artifactId>ejb-jar</artifactId>
<type>ejb</type>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<finalName>yourWarName</finalName>
</build>
</project>
ear pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>ejb-sample</artifactId>
<groupId>your.group.id</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>your.group.id</groupId>
<artifactId>ear</artifactId>
<packaging>ear</packaging>
<name />
<version>0.0.1-SNAPSHOT</version>
<description />
<dependencies>
<dependency>
<groupId>your.group.id</groupId>
<artifactId>ejb-jar</artifactId>
<type>ejb</type>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>your.group.id</groupId>
<artifactId>war</artifactId>
<type>war</type>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<pluginRepositories>
<pluginRepository>
<id>codehaus snapshot repository</id>
<url>http://snapshots.repository.codehaus.org/</url>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
<build>
<finalName>your-ear-name</finalName>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<modules>
<ejbModule>
<groupId>your.group.id</groupId>
<artifactId>ejb-jar</artifactId>
</ejbModule>
<webModule>
<groupId>your.group.id</groupId>
<artifactId>war</artifactId>
</webModule>
</modules>
<jboss>
<version>4</version>
<loader-repository>your.group:archive=your-ear-name.ear</loader-repository>
</jboss>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>0.3-SNAPSHOT</version>
<configuration>
<container>
<containerId>jboss4x</containerId>
<type>remote</type>
</container>
</configuration>
</plugin>
</plugins>
</build>
</project>
This is basically the project structure. I hope to create a downloadable archetype of this structure so you can start with this by running the mvn archetype plugin for easy use.
In our project we are using BlazeDS in conjunction with Spring 2 and Hibernate 3. When we send Hibernate objects accross we sometimes get that proxied objects get sent as ‘ClassName$$EnhancerByCGLIB’.
This results in coercion errors on the flex end when the sent objects are being converted into the bound flex objects. To fix this I found the solution on the following page:
Adobe Forums
We use the first solution there:
package com.famvdploeg.util.blazeds;
import flex.messaging.io.BeanProxy;
import flex.messaging.io.PropertyProxyRegistry;
import org.hibernate.proxy.HibernateProxy;
/**
* This class makes BlazeDS uses the real entity classname instead of the hibernate proxy classname,
* this is needed so the entity can be used as a value object (RemoteClass) in flex,
* else flex will give a type coercion error because the classname mismatches.
*
* See the following thread on the BlazeDS forum for more information:
* http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=72&catid=667&threadid=1335887&enterthread=y
*
* @author Steven De Kock
*/
public class HibernatePropertyProxy extends BeanProxy{
private static final long serialVersionUID = 1612371743382649972L;
/**
* Registers this class with BlazeDS to handle HibernateProxy instances
*/
public HibernatePropertyProxy() {
super();
PropertyProxyRegistry.getRegistry().register(HibernateProxy.class, this);
}
/**
* Get actual name instead of cglib class name with $$enhancerByCglib in it.
*/
protected String getClassName(Object o) {
if (o instanceof HibernateProxy) {
HibernateProxy object = (HibernateProxy) o;
return object.getHibernateLazyInitializer().getEntityName();
}
else {
return super.getClassName(o);
}
}
}
Although the referenced site states that we should be wary of any lazy initialization exceptions I don’t think that is a problem. This is because the serialization process is taking place behind an opened Hibernate session in our current setup and the proxied objects are still attached to the session. So using this fix works for us.
Oh yeah, don’t forget to load the bean from your spring context. 
Put in the following line of xml in your spring context xml.
<!-- Initialize the hibernatePropertyProxy handler so flex gets actual class name instead of $$enhancerbycglib -->
<bean id="hibernatePropertyProxy" class="com.famvdploeg.util.blazeds.HibernatePropertyProxy"/>
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>
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>
When building some Java projects with maven you might run into some missing Sun jars/artifacts.
[INFO] Failed to resolve artifact.
Missing:----------
1) javax.transaction:jta:jar:1.0.1B
Luckily you can fix this.
Go to the Java site and grab the jta-1_0_1B-classes.zip file.
Then manually import the file into your local maven repository by running the following command:
mvn install:install-file -Dfile=jta-1_0_1B-classes.zip -DgroupId=javax.transaction -DartifactId=jta -Dversion=1.0.1B -Dpackaging=jar
Now you have it. If you wish you can add this dependency to your pom.xml manually now also.
<dependency>
<groupid>javax.transaction</groupid>
<artifactid>jta</artifactid>
<version>1.0.1B</version>
</dependency>
For more information look at maven’s mini-howto.
I created the following function for oracle with pl/sql so Strings/varchar items can be split and put into a varray.
CREATE OR REPLACE TYPE my_array IS varray(1000) OF VARCHAR2(255);
CREATE OR REPLACE FUNCTION my_split(p_string IN VARCHAR2, p_delim IN VARCHAR2)
RETURN my_array
AS
p_last_index NUMBER := 1;
p_current_index NUMBER := 1;
p_array_pointer NUMBER := 1;
p_items my_array := my_array();
p_item VARCHAR2(255);
BEGIN
-- get index of split character
p_last_index := INSTR(p_string,p_delim,p_current_index,1);
-- while split characters are found
-- add it to the varray
WHILE( p_last_index > 0 ) LOOP
-- get first item
p_item := SUBSTR(p_string, p_current_index, (p_last_index - p_current_index));
-- put item in varray
p_items.extend;
p_items(p_array_pointer) := p_item;
p_array_pointer := p_array_pointer + 1;
-- update indexes
p_current_index := p_last_index + LENGTH(p_delim);
p_last_index := INSTR(p_string,p_delim,p_current_index,1);
END LOOP;
-- get last item
p_item := SUBSTR(p_string, p_current_index);
-- put item in varray
p_items.extend;
p_items(p_array_pointer) := p_item;
--dbms_output.put_line(substr('Value of p_receiver='||p_receiver,1,255));
/*
Example of how to loop through the items:
for a_index in 1..p_items.count loop
dbms_output.put_line(substr('Value of array('||a_index||'):'||p_items(a_index),1,255));
end loop;
*/
RETURN p_items;
END;
Small example how you can use this now:
DECLARE
test my_array;
input VARCHAR2(255) := 'a;b;c';
delim VARCHAR2(1) := ';';
BEGIN
test := my_split(input,delim);
FOR a_index IN 1..test.COUNT LOOP
DBMS_OUTPUT.put_line(SUBSTR('Value of array('||a_index||'):'||test(a_index),1,255));
END LOOP;
END;