Recently I used JRebel to do hot deployment of a complicated Web application on BEA WebLogic 12. I found it is very easy to setup and give me a great improvement in web development. I can see the result of my Java or xhtml code changes on the website in a flash. Here is a summary of what I did to enable JRebel with WebLogic and Eclipse:
1. Download JRebel plugin for Eclipse, validate with a license.
2. Enable the Eclipse projects with JRebel by "Add JRebel Nature".
3. Check the auto generated rebel.xml file for each java project to make sure the monitored target directories are correct. Only thing I needed to change is the Web directory since we didn't put our web stuff under default WebContent directory.
4. Build the war file as usual to the deployment directory.
5. Add jrebel.jar to the weblogic domain home directory. Add this to the startWebLogic.cmd file:
Add -javaagent:%DOMAIN_HOME%\jrebel.jar -Drebel.remoting_plugin=false to the `set SAVE_JAVA_OPTIONS=` line.
6. Start the Weblogic server and you should see the projects' target directories are monitored by JRebel for changes now.
Here is how it works behind the scene:
JRebel will monitor and detect changes in the target directories for compiled Java files or copied over web based files. Eclipse is moving the changes from source to target directories (compile or copy). Weblogic will allow JRebel to hot swap the files whether it is a Java class, or Xhtml or a properties file.
Combining JReble with Eclipse remote debugging, the Web development and debugging just becomes really easy!
Tuesday, May 27, 2014
Tuesday, May 13, 2014
Q&A for Activemq JMX connection issue (permission exception) using AnyConnect VPN
I found the root cause is the JMX stub can not be reached
when the service is bound to the IP address assigned by VPN. This IP is
behind the NAT and permission exception is thrown when trying to be
reached. The workaround is to force bind the JMX server to the
public/accessible IP address. When running services locally, adding JVM
option ”-Djava.rmi.server.hostname=127.0.0.1” to the startup scripts
will solve the issue.
|
Labels:
activemq,
any connect,
JMX,
permission exception,
vpn
Wednesday, November 20, 2013
Conflicting classes in multiple dependent jars
Working in Teradata, I discovered an issue related to multiple versions of Spring dependent jars. The problem is that we use Ivy to add project jar dependence. Each jar/project can have different versions of Spring jars in its library. For a master project which depends on several other base projects and having its own Ivy library, as a whole, its library will have different version of Spring jar files. These jars can contain same class with different contents. Some earlier versions might not have the implementation for certain methods added later. This problem is mostly applicable in Eclipse when all the library
files are loaded in CLASSPATH, including the library files for dependent projects. A standalone jar invocation can avoid this issue by providing a precise Manifest file containing only needed jars!
One error I got when running the project in Eclipse is as below:
Invalid property 'maxConcurrentConsumers' of bean class [org.springframework.jms.listener.DefaultMessageListenerContainer]
Notice due to the usage of Spring injection, the above error is not discovered at compilation time. In the example DefaultMessageListenerContainer.setMaxConcurrentConsumers is provided in Spring 2.0.6 but not in Spring 2.0. Other issues are also found including Spring's support for Circular references.
I found it is hard to remove the dependence of the old versions of Spring jars from dependent projects. Even using "transitive = 'false'" tag on the Ivy configuration does not work. I have to live with multiple versions of jars containing the same class. To make sure using the latest version of the jar, I have to depend on the JVM class loader order. Fortunately I found this is doable within eclipse. Eclipse's JVM will load the jars in the order of your specification in the "Java Build Path" --> "Order and Export". As long as the correct version of the jar (or ivy.xml) is before the obsolete jar (or dependent project), the issue can be avoided.
One error I got when running the project in Eclipse is as below:
Invalid property 'maxConcurrentConsumers' of bean class [org.springframework.jms.listener.DefaultMessageListenerContainer]
Notice due to the usage of Spring injection, the above error is not discovered at compilation time. In the example DefaultMessageListenerContainer.setMaxConcurrentConsumers is provided in Spring 2.0.6 but not in Spring 2.0. Other issues are also found including Spring's support for Circular references.
I found it is hard to remove the dependence of the old versions of Spring jars from dependent projects. Even using "transitive = 'false'" tag on the Ivy configuration does not work. I have to live with multiple versions of jars containing the same class. To make sure using the latest version of the jar, I have to depend on the JVM class loader order. Fortunately I found this is doable within eclipse. Eclipse's JVM will load the jars in the order of your specification in the "Java Build Path" --> "Order and Export". As long as the correct version of the jar (or ivy.xml) is before the obsolete jar (or dependent project), the issue can be avoided.
Wednesday, March 12, 2008
Configure MQ on iSeries
To run MQ on iSeries, one must start the MQ subsystem with command:
strsbs sbsd(qmqm/qmqm)
Then we can access the queue manager with "wrkmqm" command.
strsbs sbsd(qmqm/qmqm)
Then we can access the queue manager with "wrkmqm" command.
Europa catch
Europa is the name for Eclipse 3.3 EE version. I recently began to Europa for JEE5 development. Found a big catch. I used Europa with JBoss4.2.2. For some reason I found I can not deploy a class named "TestServlet" as a web service class. No matter what the package name I gave. It always result in error "Allocate exception for servlet TestServlet". Very strange.
Wednesday, February 20, 2008
import signature files from iSeries
Here is how I imported the company's digital certificate (key pair) from iSeries machine:
1. get the KDB file from the iSeries file structure and move it to a windows box
2. Use a java-based tool named iKeyMan.bat to open the key db file. The tool is shipped with Websphere product.
3. export the key pair to an existing "jks" format file which is java keystore. The file will server as the keystore, and can be used to sign jar files.
1. get the KDB file from the iSeries file structure and move it to a windows box
2. Use a java-based tool named iKeyMan.bat to open the key db file. The tool is shipped with Websphere product.
3. export the key pair to an existing "jks" format file which is java keystore. The file will server as the keystore, and can be used to sign jar files.
Thursday, February 07, 2008
DB connection error in websphere + iSeries
Recently we have a stale connections problems in a WebSphere App server running on iSeries database. I realized the problem might be the getConnection() method is not synchronized(serialized) at the JDBC driver implementation. So two threads can potentially get the same connection and step on each other. It sounds like a bug to me. The solution is easy, just synchronize the code that call getConnection() method, of course, I am assuming the calling class is already in a Singleton mode.
Friday, January 18, 2008
Some more tips
1. I found a cookie problem recently, basically the cookie can not be set from a web app on a linux server. It turned out the server had a very off time. And the cookie expiration time is calculated by current server time + cookie life time. If the server is behind the time too much, it will no set the cookie to the browser any more.
2. Always use varchar instead of char in DB column design to save space if the column's String length is unknown. In DB2 use varchar type directly, in Oracle we should use varchar2 type since varchar is reserved for other purpose according to one article.
2. Always use varchar instead of char in DB column design to save space if the column's String length is unknown. In DB2 use varchar type directly, in Oracle we should use varchar2 type since varchar is reserved for other purpose according to one article.
Thursday, March 08, 2007
Load a resource file in ear environment
Three issues
1. the properties files must be in the class path of the application module trying to read it
2. you have to use the correct class loader (Thread.currentThread().getContextClassLoader()).
3. call classloader's getResource(String propResource) method.
It will not work by simply using ClassLoader.getSystemResource() method.
1. the properties files must be in the class path of the application module trying to read it
2. you have to use the correct class loader (Thread.currentThread().getContextClassLoader()).
3. call classloader's getResource(String propResource) method.
It will not work by simply using ClassLoader.getSystemResource() method.
Thursday, March 01, 2007
two tips
Regular Expressions:
using $1, $2.. to match find result. use () to group characters. * + are applied after the searching characters. using \w for all alphanumeric char.
How to throw business exception in web service calls.
The best way is to define some serializable fields when creating the exception class which will be returned by a web service method call. Otherwise when calling wsdl2java, it will automatically create a message field and getMessage() for you, which will cause problem in RAD tool. The reason for all this I guess is because the Exception class itself is not Serializable, and its fields can not be transfered. So it requires developer to create a subclass of Exception with its own fields to hold the exception code and message. Which can be shown within the fault segment.
using $1, $2.. to match find result. use () to group characters. * + are applied after the searching characters. using \w for all alphanumeric char.
How to throw business exception in web service calls.
The best way is to define some serializable fields when creating the exception class which will be returned by a web service method call. Otherwise when calling wsdl2java, it will automatically create a message field and getMessage() for you, which will cause problem in RAD tool. The reason for all this I guess is because the Exception class itself is not Serializable, and its fields can not be transfered. So it requires developer to create a subclass of Exception with its own fields to hold the exception code and message. Which can be shown within the fault segment.
Tuesday, February 20, 2007
jsf newbie problem
javax.servlet.jsp.JspException: Cannot find FacesContext is often the error you got when you run a jsf enabled page for the first time. For example if you invoke a page using http://localhost:8080/yourJSFpage.jsp
Actually you should use http://localhost:8080/faces/yourJSFpage.jsp when calling the page.This is required because FacesContext is initialized when the JSF servlet controller is invoked. Or you can do http://localhost:8080/yourJSFpage.faces .
Actually you should use http://localhost:8080/faces/yourJSFpage.jsp when calling the page.This is required because FacesContext is initialized when the JSF servlet controller is invoked. Or you can do http://localhost:8080/yourJSFpage.faces .
Websphere server v6 + Websphere MQ v6 setup
I spent 3 whole working days trying to setup Websphere MQ (v6) and Websphere Server (v6). Finally got the sender (session bean) and the receiver (MDB) working.
Here are the things I learned.
1. MQ needs upgrade to v6.0.2 to be connectable from WAS. (must do for donwload trial version)
2. Need to specify the MQ_ROOT_DIR in WAS to synchronize the client jars.
3. Some previous failure deployment file can be stuck in the "profiles/default" temp and wstemp directories. Need to remove them to have a clean startup on WAS.
4. If you want to use websphere default JMS queue (not MQ) , a bus need to be setup.
See
http://www-128.ibm.com/developerworks/websphere/library/techarticles/0504_barcia/0504_barcia.html5. 5. If you want to use websphere MQ on the same server as WAS, a good tutorial (but for MQ 5.3) is
http://www-128.ibm.com/developerworks/websphere/techjournal/0505_woolf/0505_woolf.html
The code might need change though in the finally block of sender. (Don't close a resource if it is null, thus avoid noise exceptions)
Here are the things I learned.
1. MQ needs upgrade to v6.0.2 to be connectable from WAS. (must do for donwload trial version)
2. Need to specify the MQ_ROOT_DIR in WAS to synchronize the client jars.
3. Some previous failure deployment file can be stuck in the "profiles/default" temp and wstemp directories. Need to remove them to have a clean startup on WAS.
4. If you want to use websphere default JMS queue (not MQ) , a bus need to be setup.
See
http://www-128.ibm.com/developerworks/websphere/library/techarticles/0504_barcia/0504_barcia.html5. 5. If you want to use websphere MQ on the same server as WAS, a good tutorial (but for MQ 5.3) is
http://www-128.ibm.com/developerworks/websphere/techjournal/0505_woolf/0505_woolf.html
The code might need change though in the finally block of sender. (Don't close a resource if it is null, thus avoid noise exceptions)
Wednesday, January 31, 2007
Java Serialization Review
Java Serialization is always a tricky place and a hot spot for java job interview. Two important things:
1. If the Super class is not serializable and the sub class is. Then one important requirement is that the Superclass must have a non-arg constructor accessible by the sub class. Otherwise run time exception. Also all the fields in the super class will not be restored through serialization. ( The Default value or values set in the super class constructor will be used for these fields)
2. If the serializable contains a member variable which is not Serializable. Runtime exception will throw. The easy workaround is to mark the non-serializable object as a static memeber. Static member will not be serialized and default value is used. This also reflect why we should use POJO as much as possible and avoid complex non-serializable objects. Normally these objects are Unit object and should not be included in a transfer object at all.
1. If the Super class is not serializable and the sub class is. Then one important requirement is that the Superclass must have a non-arg constructor accessible by the sub class. Otherwise run time exception. Also all the fields in the super class will not be restored through serialization. ( The Default value or values set in the super class constructor will be used for these fields)
2. If the serializable contains a member variable which is not Serializable. Runtime exception will throw. The easy workaround is to mark the non-serializable object as a static memeber. Static member will not be serialized and default value is used. This also reflect why we should use POJO as much as possible and avoid complex non-serializable objects. Normally these objects are Unit object and should not be included in a transfer object at all.
Websphere session bean remote invokation tips
Here is how to access remote session bean in Websphere 6.0 server.
For remote session bean lookup, use the following code:
public class RemoteTest {
public static void main(String[] args) {
try {
Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
prop.put(Context.PROVIDER_URL, "corbaloc:iiop:localhost:2809");
Context initContext = new InitialContext(prop);
EchoHome echoHome = (EchoHome) PortableRemoteObject.narrow(
initContext.lookup("ejb/com/yuan/EchoHome"), EchoHome.class);
Echo echo = (Echo) PortableRemoteObject.narrow(
echoHome.create(), Echo.class);
System.out.println("AAA" + echo.print());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Two Technical points:
1. All client side library must be in the classpath to avoid exception.
The easy way is to include all jars under the server/lib dir.
2. The lookup address should be the raw name of the session bean (including full class name).
It is different from the lookup in the container environment (java:comp/env/ejb/Echo).
For remote session bean lookup, use the following code:
public class RemoteTest {
public static void main(String[] args) {
try {
Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
prop.put(Context.PROVIDER_URL, "corbaloc:iiop:localhost:2809");
Context initContext = new InitialContext(prop);
EchoHome echoHome = (EchoHome) PortableRemoteObject.narrow(
initContext.lookup("ejb/com/yuan/EchoHome"), EchoHome.class);
Echo echo = (Echo) PortableRemoteObject.narrow(
echoHome.create(), Echo.class);
System.out.println("AAA" + echo.print());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Two Technical points:
1. All client side library must be in the classpath to avoid exception.
The easy way is to include all jars under the server/lib dir.
2. The lookup address should be the raw name of the session bean (including full class name).
It is different from the lookup in the container environment (java:comp/env/ejb/Echo).
Tuesday, September 19, 2006
Hibernate session.
Hibernate session management is a little tricky for new users.
There are two ways to obtain a session:
sessionFactory.getCurrentSession(); and
sessionFactory.openSession();
The first way requires the following line in the hibernate.cfg.xml:
<property name="current_session_context_class">thread</property>
Seems if you use the first method, when you commit a transaction by calling tx.commit(), the session will be closed automatically. This can introduce error if you try to close the session again.
Whereas if you use the second method, a transaction will not close the session after commit, you will have the chance to manually close the session.
The above comments applies for hibernate 3.1, I used it with Tomcat5.5 datasource on Java1.4
There are two ways to obtain a session:
sessionFactory.getCurrentSession(); and
sessionFactory.openSession();
The first way requires the following line in the hibernate.cfg.xml:
<property name="current_session_context_class">thread</property>
Seems if you use the first method, when you commit a transaction by calling tx.commit(), the session will be closed automatically. This can introduce error if you try to close the session again.
Whereas if you use the second method, a transaction will not close the session after commit, you will have the chance to manually close the session.
The above comments applies for hibernate 3.1, I used it with Tomcat5.5 datasource on Java1.4
Friday, August 25, 2006
why need to synchonize on an object before calling wait method
A very nice answer I found online:
To me, I think the reason of requiring the synchonization is to ensure the atomicity of "checking the status and wait" operations. So that no other thread can change the status in the middle.
Just to reinforce things. The reason to call wait() is because you are waiting for a particular state to be achieved - which will be signified by someone calling notify or notifyAll. That state has to be, by definition, shared mutable state (it is shared between you and the notifier thread and it must be mutable or you will be waiting a very very very long time). As you know access to shared mutable state must always be performed while holding a suitable lock (AtomicXXX and lock-free concurrent collections not-withstanding). So you have to hold the lock to check the state you are going to wait() upon. The wait() atomically releases the lock and suspends the thread. The notification thread then acquires the lock, modifies the state and calls notify()/notifyAll(). At that point the wait()ing thread is removed from the wait-set and is now waiting to reacquire the lock that the notifying thread may not have yet released. When the waiting thread returns from wait() it owns the lock again and should then re-check the state to see if the new state is what it is waiting for. If it is then, generally, while still holding the lock the thread performs some action that relied on the object being in the state it waited for.
Note that wait() must always be called in a loop testing the condition being waited upon. Spurious wakeups are permitted and do occur.
To me, I think the reason of requiring the synchonization is to ensure the atomicity of "checking the status and wait" operations. So that no other thread can change the status in the middle.
Tuesday, August 08, 2006
xsd:all tag
I am using xsd schema to validate xml files and using xsd:all tag to group elements. Based on w3 documents, the default minOccurs of an element in xsd:all should be zero. (meaning it can just not show up without explicitly set its minOccurs to zero). But I found this is not true for any xsd validators I tested (XML spy, xerces SAXParser). I have to set the minOccurs to zero for each element if I want it to be optional.
What makes thing worse is the misleading parsing error message when I am using xerces packages in java. I started testing adding minOccurs attributes to some elements to see if this will solve the problem. However the error message does not change, i.e. the element I just added 'minOccurs=0' still seems mandatory based on the error message. I guess this is a bug in the xerces package. Only utill I fixed all the elements, the error message is gone. Whereas in XML spy, it's much better. Whenever I added minOccurs for an element, I can see it is no longer required when I try to validate the xml. This is how I figured the default value of minOccurs for elements in xsd:all group is one.
What makes thing worse is the misleading parsing error message when I am using xerces packages in java. I started testing adding minOccurs attributes to some elements to see if this will solve the problem. However the error message does not change, i.e. the element I just added 'minOccurs=0' still seems mandatory based on the error message. I guess this is a bug in the xerces package. Only utill I fixed all the elements, the error message is gone. Whereas in XML spy, it's much better. Whenever I added minOccurs for an element, I can see it is no longer required when I try to validate the xml. This is how I figured the default value of minOccurs for elements in xsd:all group is one.
Tuesday, August 01, 2006
Install PHP5 with Apache2 and mysql on windows
Today I installed php5 on my working desktop to edit my baby's website: www.qqvivian.com.
Here is my experience:
Windows + Apache 2 + PHP 5 installation (This only applies to Apache 2.0.x, for 2.2.x, the dll doesn't work)
1. Install Apache.
2. Unzip PHP to a directory, add it to path and PHP_HOME
3. Copy php\php.ini-recommended to windows\php.ini
4. Edit php.ini, set doc_root to apache htdocs directory
5. Edit php.ini, set extension_dir, uncomment extension=php_bz2.dll.
6. Install php as Apache module: Add the following lines to "httpd.conf" file under apache conf directory.
LoadModule php5_module "php/php5apache2.dll"
AddType application/x-httpd-php .php
7. Add test page phpinfo.php, restart Apache to see.
Everything is easy, except one tricky point. The above steps work only for Apache version 2.0.x, it will not work for latest 2.2.x. Obviously the php dll files are not fresh for 2.2.x.
After that, I try to configure php working with existing mysql database:
Still everything is clear, two steps involved: uncomment php_mysql.dll ext in php.ini and expose "libmysql.dll" file in "path". However this will not work, I am getting the error of: "PHP Warning: PHP Startup: Unable to load dynamic library 'C:\\php\\ext\\php_mysql.dll' - The specified module could not be found.\r\n in Unknown on line 0"
After google for a while I found an excellent solution:
http://www.codecomments.com/PHP_Language/message274647.html
You have to copy "libmysql.dll" file to "windows\system32" directory. Yes, I know, it is already in the Path, you still have to do it. I believe it is related to windows security issue set by MS. Seems this is a very common problem, but the answer is not so obvious from php or mysql website. I update a wiki to post the solution:
http://www.cementhorizon.com/wiki/index.php/
Solution_:_Unable_to_load_dynamic_library_C:phpextphp_mysql.dll_-_the_specified_module_could_not_be_found.
Here is my experience:
Windows + Apache 2 + PHP 5 installation (This only applies to Apache 2.0.x, for 2.2.x, the dll doesn't work)
1. Install Apache.
2. Unzip PHP to a directory, add it to path and PHP_HOME
3. Copy php\php.ini-recommended to windows\php.ini
4. Edit php.ini, set doc_root to apache htdocs directory
5. Edit php.ini, set extension_dir, uncomment extension=php_bz2.dll.
6. Install php as Apache module: Add the following lines to "httpd.conf" file under apache conf directory.
LoadModule php5_module "php/php5apache2.dll"
AddType application/x-httpd-php .php
7. Add test page phpinfo.php, restart Apache to see.
Everything is easy, except one tricky point. The above steps work only for Apache version 2.0.x, it will not work for latest 2.2.x. Obviously the php dll files are not fresh for 2.2.x.
After that, I try to configure php working with existing mysql database:
Still everything is clear, two steps involved: uncomment php_mysql.dll ext in php.ini and expose "libmysql.dll" file in "path". However this will not work, I am getting the error of: "PHP Warning: PHP Startup: Unable to load dynamic library 'C:\\php\\ext\\php_mysql.dll' - The specified module could not be found.\r\n in Unknown on line 0"
After google for a while I found an excellent solution:
http://www.codecomments.com/PHP_Language/message274647.html
You have to copy "libmysql.dll" file to "windows\system32" directory. Yes, I know, it is already in the Path, you still have to do it. I believe it is related to windows security issue set by MS. Seems this is a very common problem, but the answer is not so obvious from php or mysql website. I update a wiki to post the solution:
http://www.cementhorizon.com/wiki/index.php/
Solution_:_Unable_to_load_dynamic_library_C:phpextphp_mysql.dll_-_the_specified_module_could_not_be_found.
Wednesday, July 26, 2006
XML special character
XML understand only thress special characters "& lt;", "& gt;" and "& amp;"
While copying data from html to xml, must be very careful.
Most common error happens for "& nbsp;" which is not allowed in xml/xsl without a declaration.
Fix: change "& nbsp; " to " & #160; " before push it to xml doc.
Also we should change "<" to "& lt;", ">" to "& gt;" before push.
Also note "&" is not allowed for xml doc, however in most HTML pages it has already been changed to "& amp;", which will be valid in XML, so we don't need to take care of this case generally.
While copying data from html to xml, must be very careful.
Most common error happens for "& nbsp;" which is not allowed in xml/xsl without a declaration.
Fix: change "& nbsp; " to " & #160; " before push it to xml doc.
Also we should change "<" to "& lt;", ">" to "& gt;" before push.
Also note "&" is not allowed for xml doc, however in most HTML pages it has already been changed to "& amp;", which will be valid in XML, so we don't need to take care of this case generally.
Monday, April 17, 2006
A great tip ^M
Today I spent a while fixing the famous ^M problem when copying file from DOS to Unix.
Find two solutions:
1. Use dos2unix command can convert a dos file to unix format (removing annoying ^M)
2. Since originally the dos files are introduced through CVS checkin. If I change the the file type from "binary" to "ASCII" in eclipse. CVS will figure out the file format and automatically remove ^M for me.
One note:
If you open a dos file using vi in Unix environment. vi won't show ^M for you since vi will open the file as dos format. I didn't know this initially.
Find two solutions:
1. Use dos2unix command can convert a dos file to unix format (removing annoying ^M)
2. Since originally the dos files are introduced through CVS checkin. If I change the the file type from "binary" to "ASCII" in eclipse. CVS will figure out the file format and automatically remove ^M for me.
One note:
If you open a dos file using vi in Unix environment. vi won't show ^M for you since vi will open the file as dos format. I didn't know this initially.
Subscribe to:
Posts (Atom)