Tuesday, July 7, 2009

WAS 6 Server does not start because of service error.

"Because server1 is registered to run as a Windows Service, the request to start this server will be completed by starting the associated Windows Service"

Hi guys, I came across this annoying error which would not go away no matter how many I restart the websphere 6 server. Finally after some research I found a very simple solution - delete the server*.pid files in server log folder. If you are not sure where your log files are here is where

C:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\profiles\MyServer\logs\server1

After deleting the pid files, restart the server and the error should go away. Good luck.

Wednesday, June 3, 2009

Websphere server not starting but shows "Started" in Console?

So this error is in my case is caused because the workbench is not able to connect to the actual server. See in Rad 7 (perhaps in RAD6 also, not sure) the server does not come totally embedded in the RAD tool.

When we start the server through the RAD server view, the server is started but there is a need for the workbench (working files in RAD) to connect to the server - this is where it uses the RMI or SOAP ports to connect and sync with the actual server.

This error where the console says that server is started but the actual server does not publish our app and says starting... can be fixed in this case (could be any other reason) by using the right RMI or SOAP ports. Look for these ports in the console view right above where it says the server is started. Now right click the server in server view and update the RMI and SOAP ports to the previous values. Restart the server, hopefully this should fix your problem.

In my case (RAD on Centos) the correct ports were:
RMI - 2809
SOAP - 8880

--

Java interview with an Antivirus company.

I had written this an year ago but not published yet so I decided to publish it today.

A while back I interviewed with a company for a Java programmer contract. Here is how it went and questions he asked:


1) Servlet life cycle: I said init(), execute() and destroy().
I had totally forgotten that the execute() method does not exist in a http based servlet. So it is rather:

init() - where we initialize connections etc.
service() - from where it calls either doGet() or doPost() methods.
destroy() method - where we free any resources used etc.

2) How do multiple application servers obtain a lock on file (say for writing) - that is synchronization between two application servers - I wasn;t sure of this! I told him that we could get access to the System class and then get access to the particular file handler and perhaps call a sysnchronize or lock method on the file handler! He wasn't really impressed with this. Another way I came accross was to rename the file just before the code starts to write to the file and handle FileNotFoundException - basically hide the file from others while writing to that file.

3) How do you compare two files? I told him either using comparable interface to comparator interface. When using comparable interface we have to write comprareTo() and in comparator we have to write compare() method.

4) Threads in servlets - can you use them? I told him yes we could use them, but it is not a good idea to have threads in servlets. My reasonsing is that Once the servlet spawns the threads and dies, what would happen to the spawened thread? There is no definite way to track the threads that were spawned.

Also I came accross ServletContextListener() interface which gives a handle to the ServletContainer (one for the whole application) using which we could start and handle threads, initialize connection to databases, handle init parameters etc. The two methods in ServletContextListener - contextInitialized and contextDestroyed are called upon initialization of the application and upon its closing respectively. There is only one servletContext for all the servlets.

Tuesday, June 2, 2009

Deployment descriptor Module cannot be loaded?

Alright this one is not your problem, but rathers RADs inability to synch up all the projects in your main EAR project.

This happened to me because the component file of RAD was missing the entry for the Module it was complaining about. The component file is under .settings called org.eclipse.wst.common.component.

Check the component file and add the wed or jar or EJB module with the correct handle. The handle for the module can be found in .modulemaps under META-INF/ibmconfig folder.

Once you do this refresh and build the project to see if the issue is taken care of.

Running Editplus in Linux, using Wine

Ok, I happened to spend a lot of time on this issue which bugged me. Editplus is one of favourite editors in windows. The main reason I use it not just for text editing purpose but for its file search capabilities.

Installing editplus on CentOs seemed like an huge uphill task. But luckily editplus does not have an executable for linux...whaat how is it lucky then? Its lucky because now we do not install Editplus but instead we emulate it as if it were running on Windows inside Linux (CentOS in my case!). But installing the emulator itself required some work.


I used YUM to install the emulator. To install the emulator called wine (WINdows emulator) we need to do the following:

1) Update your repository information that is used by YUM installer. Put the repository information in /etc/repos.d/ folder. I have the rpmforge respository with the follwing info in rpmforge.repo
-----
#baseurl = http://apt.sw.be/redhat/el4/en/$basearch/dag
mirrorlist = http://apt.sw.be/redhat/el4/en/mirrors-rpmforge
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge
enabled = 1
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1
priority=1

----
2) use yum -install wine command to get the software.
3) Download Editplus.exe and run it with wine. I even created a shortcut to run it from the linux desktop:
env WINEPREFIX="/root/.wine" wine "C:\Program Files\EditPlus 3\editplus.exe"

---
3) Enjoy Editplus!!

Method cannot be Resolved / Reflected to a type?

In Rad 7 I have seen this problem for EJB projects which use .class files. Apparently RAD7 does not like .class files and if your project happens to refer to .class files, putting them in the classpath also will not work.

One workaround for this is to create a jar file out of the .class files and refer to the new jar file from the project. To create the jar file use the command from the appropriate directory:

jar -cvf newJar.jar /your/package/*.class

Once the jar is created simply put it at some lib folder or someplace and refer to it from the build path.

The other thing (perhaps easier too) is to add the folder containing the .class files to the RAD build path. Do this by clicking the build path, click the libraries tab and then click on 'Add class folder'. If you have package that should be considered add the parent folder where the package name starts. Now build again and see if the error goes away!

This should solve the probelm.

Getting Eclipse / RAD to recognize WEB PROJECT

To do this we have to get RAD have Project faces setup properly. Right clickt he project, goto faces and add JAVA and Dynamic Web project to it.

If you cannot see the project faces option upon right click, then we need to add the following (depending on what support you may need) to the .project file for RAD to pick up the web capabilities of your would be web project which is basically set of builders and type / nature description:

This is XML format (I am unable to post XML in here!)

org.eclipse.wst.common.project.facet.core.builder

com.ibm.etools.webtools.LibDirBuilder

org.eclipse.jdt.core.javabuilder

com.ibm.etools.j2ee.validationbuilder

com.ibm.etools.ctc.serviceprojectbuilder

com.ibm.etools.links.management.linksbuilder

com.ibm.etools.validation.validationbuilder

com.ibm.etools.j2ee.LibCopyBuilder

com.ibm.etools.struts.StrutsBuilder

org.eclipse.wst.validation.validationbuilder

org.eclipse.jst.j2ee.LibCopyBuilder

com.ibm.etools.webtools.validation.jsp.jspcompilationbuilder

com.ibm.etools.j2ee.WebNature
org.eclipse.jdt.core.javanature
com.ibm.etools.ctc.javaprojectnature
com.ibm.etools.struts.StrutsNature
org.eclipse.wst.common.modulecore.ModuleCoreNature
org.eclipse.wst.common.project.facet.core.nature
org.eclipse.wst.common.modulecore.ModuleCoreNature
org.eclipse.jem.workbench.JavaEMFNature


-----------------------------------------
Enjoy!
Comments welcome.