Showing posts with label Eclipse. Show all posts
Showing posts with label Eclipse. Show all posts

Thursday, July 09, 2009

Eclipse : Problems with web.xml

If you use Eclipse with the Sysdeo plugin you sometimes get problems with web.xml when you add more servlet mappings. The message is:

The content of element type "web-app" must match "(icon?,display-
name?,description?,distributable?,context-param*,filter*,filter-mapping*,listener*,servlet*,servlet-
mapping*,session-config?,mime-mapping*,welcome-file-list?,error-page*,taglib*,resource-env-
ref*,resource-ref*,security-constraint*,login-config?,security-role*,env-entry*,ejb-ref*,ejb-local-
ref*)".


e.g. you may have


web-app
servlet A
servlet-name
servlet-class
/servlet

servlet-mapping A
servlet-name
url-pattern
/servlet-mapping

servlet B
servlet-name
servlet-class
/servlet

servlet-mapping B
servlet-name
url-pattern
/servlet-mapping

/web-app


The problem is in the order. You can't intermix servlet and servlet-mapping. All the servlets have to come first followed by all the servlet-mappings. So the above would look like:


web-app
servlet A
servlet-name
servlet-class
/servlet

servlet B
servlet-name
servlet-class
/servlet

servlet-mapping A
servlet-name
url-pattern
/servlet-mapping

servlet-mapping B
servlet-name
url-pattern
/servlet-mapping

/web-app


You can check this by : Right click inside the xml window - Validate.

Enjoy!

Wednesday, June 17, 2009

Eclipse : Preview html / jsp pages

When you view some kinds of files in Eclipse e.g. wsdl files the "wizard" shows you two tabs at the bottom right viz. "Design" and "Source".

This doesn't automatically happen with html or jsp files.

Right-click on the html or jsp file in the "Package Explorer" window and either "Open with - "

"Web Browser" (which just shows you the preview - note the the "Refresh" button at the top) or

"Web Page Editor" (which enables "Design / Preview" tabs). It also splits the screen in half so you can see both at the same time.

Ensure that "Windows / Preferences / General / Web Browser" option is set to "Use internal web browser".

Very neat.

Enjoy!

Eclipse : Debugging web services and servlets

Been playing with this kind of stuff (Eclipse / Tomcat / Axis2 / jsp / servlets) and came across two good links that explain how to do it all!

How to Debug a Web Service?

and

Debugging a servlet with tomcat and Eclipse tutorial.

Enjoy!

Thursday, December 04, 2008

Java : Axis2 client and Log4J

I was busy testing a client developed using the Eclipse plug-ins in the previous post.

This came up with the following error message.

log4j:WARN No appenders could be found for logger (org.apache.axis2.description.AxisService).
log4j:WARN Please initialize the log4j system properly.

To set this up inside an Eclipse project:

* Create a new folder in the project called e.g. "log4j".
* Add a file to that folder called log4j.properties which contains something like:


# Set root category priority to INFO and set its only appender to A1
log4j.rootCategory=INFO, A1

# A1 is set to be a ConsoleAppender (writes to system console).
log4j.appender.A1=org.apache.log4j.ConsoleAppender

# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n


* In the project's "Run Dialog", click on the "Classpath" tab / "Advanced" / "Add folder" and then browse to the "log4j" folder previously created.
* That's it

Enjoy!

Java : Tomcat / Eclipse and Axis2

I needed to develop a Java web service that ran inside Tomcat and used Axis2 as the web server component.

I use Eclipse as my Java IDE and was looking around for plug-ins that would automate and simplify the whole process.

Came across this excellent tutorial - Developing Web Services Using Apache Axis2 Eclipse Plugins - Part 1

This uses two Eclipse plug-ins:

Apache Axis2 Service Archive Generator Wizard and
Apache Axis2 Code Generator Wizard

which generate the proxies and then wrap everything up for deployment to Tomcat.

I highly recommend working through the tutorial and then using that knowledge to develop and deploy your own.

Enjoy!

Monday, July 07, 2008

Eclipse : Compiling JVM 1.4 with Eclipse Europa

Eclipse Europa won't work with anything less than JVM 1.5.

But what happens if your client needs a Java 1.4 program? Do you have to download an earlier version of Eclipse?

Actually - no!

You can compile 1.4 programs inside the Europa 1.5 workspace.

Under "Windows - Preferences - Java - Installed JREs", you need to add the path to the 1.4 JVM.

Right click on the 1.4 project.

Under "Properties - Java Build Path - Libraries", ensure that the JRE System Library points to the 1.4 version.

Under "Properties - Java Compiler", click "Enable project specific settings". Set "Compiler compliance level" to 1.4.

That's it.

Enjoy!

Tuesday, June 24, 2008

Eclipse : Starting with a different VM

For various reasons, a PC I use has Java 1.4 installed and the latest Eclipse Europa requires 1.5. I am unable to update the classpath, environment etc. so although 1.5 was installed, Eclipse would not find it.

The solution was to use the command line option:

C:\eclipse\eclipse.exe -vm "C:\Program Files\Java\jdk1.5.0_15\jre\bin\java.exe"

This forces Eclipse to load with the 1.5 VM.

I placed the command above in a shortcut so it's easily accessible from the desktop.

Enjoy!

Wednesday, August 15, 2007

Eclipse : Matching brackets

Clicking to the right of a bracket shows the matching one in a "box".

To toggle between the two, use Cntl / Shift / P.

Enjoy!

Eclipse : Running command line to EJB inside Eclipse

I'm running Eclipse Europa (the J2EE package).

See the previous post about running a command line Java program inside a DOS box and the million paths etc. you have to set up.

It's a lot easier to run it inside Eclipse by right clicking the application in the Package Explorer and selecting "Run As" / "Java Application".

(Note : JBoss needs to be started first by selecting the Server view inside the J2EE perspective , right click, "Start".)

You get this error in the console:

Need to specify class name in environment or system property, or as an
applet parameter, or in an application resource file: java.naming.factory.initial


As per the previous post, the solution then was to add a path to the jndi.properties file:

set CLASSPATH=C:\JBoss-4.0.5.GA\server\default\conf;%CLASSPATH%

In Eclipse, however, go "Project Properties" / "Run/Debug Settings" / select the launch configuration / "Edit" / click on the "Classpath" tab / "Advanced: / "Add External Folder" and then browse to the jndi.properties folder as above and "OK" out.

That's it - Eclipse takes care of all the other stuff!

Enjoy!

Tuesday, August 14, 2007

EJB : Running a command line client to a JBoss EJB

The EJB example running on JBoss is taken from the WTP (Web Tools Project) tutorials here plus XDoclet - all inside Eclipse.

Call the package ejbs.

We have an EJBTestBean:


/**
*
*
* @ejb.interface-method view-type="remote"
*
* @generated
*
* //TODO: Must provide implementation for bean method stub
*/
public String greet(String param) {
return "Hi dude " + param;
}


XDoclet creates all the Home and Util stubs.

Now we want to test this from a Java command line client.

So we create a Java class with a main() method (called CLTestClient):


try
{
EJBTestHome home = ejbs.EJBTestUtil.getHome();
EJBTest service = home.create();
String result = service.greet("Tom");
System.out.println();
System.out.println("Result is " + result);
}

catch (Exception e)
{
System.out.println();
System.out.println("Exception " + e.getMessage());
}


and we want to test from the command line:

java CLTestClient

and we get ClassNotDefined all over the place.

So we add the EJB files to the CLASSPATH:

set CLASSPATH=C:\JBoss-4.0.5.GA\
server\default\lib\jboss-j2ee.jar;C:\your path\EJBTestClient\build\classes;C:\your path\EJBTestClient\build\classes\ejbs;%CLASSPATH%

Then we get this error:

Need to specify class name in environment or system property, or as an
applet parameter, or in an application resource file: java.naming.factory.initial


The solution is to add a path to the jndi.properties file:

set CLASSPATH=C:\JBoss-4.0.5.GA\server\default\conf;%CLASSPATH%

More ClassNotDefined errors:

set CLASSPATH=C:\JBoss-4.0.5.GA\client\jbossall-client.jar;C:\JBoss-4.0.5.GA\lib\jboss-common.jar;C:\JBoss-4.0.5.GA\server\default\lib\jboss.jar;C:\JBoss-4.0.5.GA\client\jnp-client.jar;C:\JBoss-4.0.5.GA\client\jboss-client.jar;%CLASSPATH%

and finally:

java CLTestClient

returns:

Result is Hi dude Tom

By the way, if you wanted to do this from a browser inside a jsp page:


LT%@page import="ejbs.EJBTestUtil"%GT
LThtmlGT
LTheadGT
LTtitleGTEJBWebTestLT/titleGT
LT/headGT
LTbodyGT
LT%
ejbs.EJBTest tb = null;

try
{
ejbs.EJBTestHome home = EJBTestUtil.getHome();
tb = home.create();
}

catch(Exception exception)
{

}

%GT

LTbGTLT%= tb.greet("Tom") %GTLT/bGT

LT/bodyGT
LT/htmlGT




Where LT = "less than" and GT = "greater than".

Enjoy!

Friday, November 25, 2005

Eclipse : Writing java snippets in a scratchpad

For web server development, especially when the code is in a jar file, you need to write some code, stop the application inside the server, deploy the new one, start it all up etc. That takes time - and then you find that the code doesn't work so you try something else which takes more time and so on ...

It's much easier to write the snippet inside an Eclipse scrapbook first and test it.

"File / New / Other / Java / Java Run/Debug / Scrapbook Page

Then just write some code in the editor e.g.

System.out.println("Hello");

Then highlight the snippet, right click, "Display"

Bingo!

Enjoy!

Friday, November 18, 2005

Eclipse : Where's my console output?

Debugging my Java program inside Eclipse 3.1, I noticed that the console output which had tons of debugging statements was missing a large swathe of the initial output.

A bit of digging around found the option under Window / Preferences / Run/Debug / Console.

Uncheck "Limit console output" and you'll get the output you were expecting!

Enjoy!

Thursday, September 22, 2005

Misc : WTP installed finally on Eclipse

Been battling for a while getting Eclipse WST (Web Standard Tools) and WTP (Web Tools Platform) to run on Eclipse 3.0. Eventually gave up on it and installed 3.1. It's a monster download and you need to add the optional WTP plugin.

The software updates feature under Help makes it a snap. Remember to click the “Select Required” button to enable the features required by WTP which are not already installed. Got it all installed and now can right-click on a WSDL file and select “Validate WSDL”.

Enjoy!