Skip to main content

Posts

Change default JAVA_OPTS in JBoss 7

To change JVM memory options in JBOSS 7 for standalone server, find the file standalone.conf.bat in bin directory and edit the file like below. rem # JVM memory allocation pool parameters - modify as appropriate. set "JAVA_OPTS=-Xms3072M -Xmx3072M -XX:MaxPermSize=1024M"

JBAS015052: Did not receive a response to the deployment operation within the allowed timeout period [60 seconds]

To resolve this error, edit the below in \jboss-as-7.1.1.Final\standalone\configurationstandalone.xml find the below lines and add deployment-timeout. <subsystem xmlns="urn:jboss:domain:deployment-scanner:1.1">             <deployment-scanner path="deployments" relative-to="jboss.server.base.dir" scan-interval="5000"/>         </subsystem> <subsystem xmlns="urn:jboss:domain:deployment-scanner:1.1">             <deployment-scanner path="deployments" relative-to="jboss.server.base.dir" scan-interval="5000" deployment-timeout="1200" />         </subsystem>

Rest Client addon on Firefox/Chrome to test restful services & web pages

https://addons.mozilla.org/en-us/firefox/addon/restclient/ Using this browser extension we can test our restful services as well as web pages by proving some request headers.  I am testing my application (java code) by providing cookie, this will be fast for debugging, no need enter values every time in browser. Just capture the request data from chrome developer console/ firebug once and hit the server with same data or modified one. it is easy & very helpful.

SQLQuery.executeUpdate() will invalidate hibernate's second level cache

when SQLQuery.executeUpdate() called all second level cache will be invalidated.  Example: SQLQuery query = session.createSQLQuery("UPDATE TABLE ....."); query.setInteger("status", 1); query.executeUpdate(); To avoid: SQLQuery query = session.createSQLQuery("UPDATE TABLE ....."); query.setInteger("status", 1); query.addsynchronizedqueryspace("TABLE");  query.executeUpdate(); details here: http://www.link-intersystems.com/bin/view/Blog/Hibernate's+second+level+cache+and+native+queries

Disable hibernate Optimistic Lock for specific scenario

Optimistic Lock gives more control on concurrent modification on data. That can be achieved very easily in hibernate using @Version column. But in some cases we may have to avoid concurrency check, example background process. To disable Optimistic lock set OptimisticLockMode as NONE for entity class while hibernate is initiating. We can't remove version column that needs Database changes and ORM changes. In this way we can disable Optimistic Lock by code. implement "org.hibernate.event.Initializable" interface override the below method.     @Override     public void initialize(Configuration cfg) {         Iterator<?> persistentClassIterator = cfg.getClassMappings();         while (persistentClassIterator.hasNext()) {             PersistentClass persistentClass = PersistentClass.class.cast(persistentClassIterato...

HIbernate @version for existing data, cannot be null

Hibernate have option to check concurrent modification of a same data. Which will be easy when we add a version column in the table and hibernate entity. If existing row has version as NULL then hibernate will throw the NullPointerException while updating the existing data. To avoid this exception   @version column  should be NOT NULL and should have a default value. if it number 1.

remove(unset) property in a property file using ANT PropertyFile task

Using PropertyFile task we can edit the property file during ANT build. Edit property value are very easy and can find here details. http://ant.apache.org/manual/Tasks/propertyfile.html but delete a property or comment a property is the tricky one. If we are using latest ant version (1.8.1 or later), we can delete a property like below. <propertyfile file="my.properties" comment="My properties">   < entry  key="propertykey" operation="del"/> < /propertyfile> but the older version that is before 1.8.1 don't have operation called " del ", if we run the command in lower version ant, we will get a error says undefined operation "del".      there is workaround instead deleting a property we can comment that property using ant's replace command. < replace file="sample.properties">                      < replacefilter token="propertykey" value="#propert...

Online HTML & CSS editor, MOZILLA THIMBLE

Very nice HTML & css editor for learners. https://thimble.webmaker.org/en-US/

Hibernate primaryKey (ID) auto generate using Database sequence

    @Id     @GeneratedValue(strategy = GenerationType.AUTO, generator ="CUSTOMER_SEQ_G")     @SequenceGenerator( name = "CUSTOMER_SEQ_G", sequenceName = "CUSTOMER_SEQ")     @Column(name = "CUSTOMER_ID")     private Long customerId; generator in @GeneratedValue should same as name in @SequenceGenerator sequenceName is Database Sequence object.

Deploy ear in exploded in Jboss using maven plugin

There is a option to deploy EAR/WAR as exploded folder in JBoss using jboss-maven-plugin. setting unpack "true" will do everything.... <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>jboss-maven-plugin</artifactId> <version>1.5.0</version> <configuration> <jbossHome>C:/jboss-6.1.0.Final</jbossHome> <serverName>all</serverName> <fileName>target/MyEar.ear</fileName> <unpack>true</unpack> </configuration> <executions> <execution> <id>harddelpoy</id> <phase>install</phase> <goals> <goal>harddeploy</goal> </goals> </execution> </executions> </plugin>

WARN [org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker] Unexpected error in pingDatabase: java.lang.IllegalArgumentException: object is not an instance of declaring class {SOLVED}

When we use Oracle driver in application which is deployed JBossAS, We have to place the Oracle driver jar in server/lib directory. If we keep the jar in our Ear or War file also will get this warning message. 15:56:40,098 WARN  [org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker] Unexpected error in pingDatabase: java.lang.IllegalArgumentException: object is not an instance of declaring class To solve this, just remove the Oracle lib from your Ear or War.

start JBoss 6 server in different port

<<Jboss-HOME>>/bin run.bat -c <<servername> -Djboss.service.binding.set=ports-01   <<servername>>  - could be server directory name (all or minimal). default value is "default"  -Djboss.service.binding.set=ports-01 - this option will increase all port numbers by 100. Example: HA-JNDI port default is 1099 and after using option 1199 There are 4 options available in Jboss6, to view those login into AdminConsole ( http://localhost:8080/admin-console/ ) Service Binding Manager Service Binding Sets ports-01 ports-02 ports-03 ports-default ports-default - 8080 and others ports-01 - +100 ports-02 -  +200 ports-03 -  +300

contains() and indexOf() in Java will return true for Empty String("")

In Java we will use String.contains(String2) to check a String contains another String. This Contains() method will return true if we String2 is empty that means "". Also String.indexOf(String2) and String2 is empty "", this also will return 0. If we check return index is greater than -1 or not equal to -1, this will return true. So to avoid this, we have to check the given string is not empty.                 String s = ""; String b = "test"; System.out.println("b contains s?:"+b.contains(s)); //true System.out.println("b indexOf s?:"+b.indexOf(s)); //0 System.out.println("b indexof 't'?:"+b.indexOf("t")); //0 System.out.println("s contains b?:"+s.contains(b)); //false Do not check index or contains for empty String at any time. 

Skip build while launching remote debug in eclipse

While debugging remote server like jboss, tomcat etc.. eclipse will try to build whole workspace which already build, that will take time finish of. To skip build while launching remote debug, There is option eclipse  * goto preferences --> Run/Debug --> Launching * uncheck Build (If required ) before launching

Maven skip test and skip test compile

In maven there are two ways to skip test. mvn install - DskipTests this will skip the tests but classes will compile. mvn install - Dmaven . test . skip = true this will skip the test and also will skip compilation of test classes Whenever we need to skip compilation of test classes we can use second one.