Showing posts with label Netbeans. Show all posts
Showing posts with label Netbeans. Show all posts

Tuesday, November 23, 2010

Netbeans : Providing command line arguments inside Netbeans

I write a lot of command line Netbeans (6.9) Java programs. A lot of them take command line arguments e.g.


java Program Option1 Option2


and you access them from "String[] args".

When you are running inside Netbeans, you need to provide the arguments by:

Right click the project / Properties / Run / Arguments

If you right click the Java file you are testing (the Main class) and select "Run File" the program runs but ignores the configured arguments.

To get around this, you have to right click the project and select "Run".

Enjoy!

Friday, November 19, 2010

Netbeans : SOAPUI plugin

Using Netbeans 6.9.

I wanted to download the SOAPUI plugin from soapUI NetBeans Plugin.

Although the description says "com-eviware-soapui-netbeans-module.nbm", when you actually download the file, you'll find it's a zip file.

Netbeans doesn't like loading zip files. A little research at Mr. Google shows that a .nbm file is essentially just a zip file with a different extension.

So I simply simply renamed

com-eviware-soapui-netbeans-module.zip to com-eviware-soapui-netbeans-module.nbm

and the plugin installed no problems at all.

It does warn you that the plugin is not signed but just ignore that and continue.

Enjoy!

Thursday, November 18, 2010

CXF : Deploying the java_first_jaxws sample direct to Tomcat

Decided I wanted to learn a bit about CXF so downloaded the development kit and has a look at the java_first_jaxws project in the \samples directory.

Before you try and do anything, ensure you have the environment set up correctly.

I created a bat file (as per README) which looks like:


set CXF_HOME=x:\apache-cxf-2.3.0
set JAVA_HOME=x:\Program Files\Java\jdk1.6.0_22
set ANT_HOME=C:\apache-ant-1.8.1

set PATH=%JAVA_HOME%\bin;%ANT_HOME%\bin;%CXF_HOME%\bin;%PATH%
set CLASSPATH=.;%CXF_HOME%\lib\cxf-manifest.jar;.\build\classes

set CATALINA_HOME=x:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.26


which also serves as a useful list of the file versions I have.

One level up from the project you will find a useful file i.e.

common_build.xml

which is worth looking through.

In the actual project directory you will find a build.xml which calls the above.

ant -p


shows:


Main targets:

build build demo client and server
client run demo client
client-servlet run demo client hitting servlet
deploy deploy the application into the container
server run demo server
undeploy undeploy the application from the container
Default target: build


so we first do:

ant build

which builds both the client and the server.

Then we run:

ant server


and

ant client


Note that the client and server run in two separate command prompts.

The client then sends some canned messages to the server:


client:
[java] Hello World
[java] Hello World
[java] Hello Galaxy
[java] Hello Universe
[java]
[java] Users:
[java] 1: World
[java] 2: Galaxy
[java] 3: Universe


and the server receives:


server:
[java] Starting Server
[java] Server ready...
[java] sayHi called
[java] sayHiToUser called
[java] sayHiToUser called
[java] sayHiToUser called
[java] getUsers called


Note that this is running is a "built-in" Jetty server and the URL the client calls is:

http://localhost:9000/helloWorld

OK, that sets the scene for the main thrust of this article which is how to deploy this client to a real instance of Tomcat.

So start up the Tomcat server as usual by running "startup.bat" in the \bin directory.

My installation of Tomcat runs on port 8080 so we need to change Client.java as follows:


//String endpointAddress = "http://localhost:9000/helloWorld";
String endpointAddress = "http://localhost:8080/helloworld/services/hello_world";


Now we run the normal "ant build" and then we run "ant deploy".

This builds the war file and then deploys it to Tomcat (which is where the CATALINA_HOME environment variable comes in.)

Then we run the normal "ant client" and this time, the server output messages will appear in the Tomcat window.

Note that the WSDL can be found at:

http://localhost:8080/helloworld/services/hello_world?wsdl

Where on earth does this URL come from?

As per Creating a WSDL-first web service with Apache CXF or GlassFish Metro, scroll down to Point 2 in the "Additional notes".

Adapting for our project, we get:

http://localhost:8080/helloworld/services/hello_world?wsdl

"localhost:8080" is the host and port of the servlet container.
"helloworld" is the name of the war file.
"services" comes from the url-pattern element in the web.xml file.
"hello_world" comes from the address attribute in the cxf-servlet.xml file (for CXF).

If we look into the web.xml file (you'll need to look at the war file in the ...\samples\java_first_jaxws\build\war directory), we find:

servlet-name = cxf
url-pattern = /services/*

If we look into the cxf-servlet.xml file (in the wsdl directory), we find:


jaxws:server id="jaxwsService" serviceClass="demo.hw.server.HelloWorld" address="/hello_world"


Enjoy!

Tuesday, November 16, 2010

Metro : Jax WS incompatibilities with Netbeans

Using Netbeans 6.9 and Tomcat 6 with JAX WS via Metro and Java JDK 6 on Windows.

The Tomcat installation is the one that is loaded as part of Netbeans.

When you try and invoke the web service, you get a string of errors e.g.

java.lang.NoSuchMethodError: javax.xml.ws.WebFault.messageName()Ljava/lang/String


The basic problem seems to be that the versions of JAX WS bundled with Netbeans / Java / Tomcat are incompatible.

(Metro provides JAX-WS 2.2 while Java SE includes JAX-WS 2.1. If you want to run Metro applications outside Tomcat, you will need to use the endorsed standards override mechanism. For more details see:

http://java.sun.com/javase/6/docs/technotes/guides/standards/index.html)

There are literally hundreds of articles etc. all over the web about how to fix this problem with tips about installing file x into the endorsed directory, the common/endorsed directory, updating Tomcat, updating Java etc. etc.

I tried a heap of them and none of the ones I tried fixed the problem. This is Google search at it's worst - tons of articles, all different, none of which appeared to work and utter frustration.

To complicate the issue, it you don't back out the failed change, you run the risk that the next change won't work because you didn't start from a known point.

To complicate things further, some of these changes partly work which means that next time you simply get a different error message and you have to start the process all over again.

Eventually, I went back to the source i.e. Metro and JAX WS.

I came across this article:

Creating a WSDL-first web service with Apache CXF or GlassFish Metro

which pointed me to:

Using JAX-WS 2.x / Metro 1.x/2.0 with Java SE 6

So, download Metro 2 - refer Metro 2.0

Ensure Netbeans and Tomcat are shut down.

Sort the zip file by path.

You do not need to extract all the files. You only need:

metro-on-tomcat.xml and all the jar files under /metro/lib and /metro/osgi.

Extract these to a directory.

Ensure you have ant installed.

Open a command prompt and navigate to the directory that you have just extracted the files to.

Type:

...\metro>set CATALINA_HOME=x:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.26

i.e. the path where Tomcat 6 is installed

where ... is the directory that the files were extracted to.

Then run:

ant -f metro-on-tomcat.xml install


which produces:


Buildfile: metro-on-tomcat.xml

catalinahome-test:

init:

uninstall:

update-catalina-props:

test-api:

check-api:

install-api-tomcat5:

install-api-tomcat6:
[mkdir] Created dir: x:\Program Files\Apache Software Foundation\Apache Tomc
at 6.0.26\endorsed
[copy] Copying 2 files to x:\Program Files\Apache Software Foundation\Apach
e Tomcat 6.0.26\endorsed

install-api-tomcat:

install:
[echo] Installing Metro 2.0 FCS for x:\Program Files\Apache Software Founda
tion\Apache Tomcat 6.0.26 ...
[mkdir] Created dir: x:\Program Files\Apache Software Foundation\Apache Tomc
at 6.0.26\shared\lib
[copy] Copying 4 files to x:\Program Files\Apache Software Foundation\Apach
e Tomcat 6.0.26\shared\lib
[echo] ... installation complete.

BUILD SUCCESSFUL


The two files copied to the \endorsed directory are :

jsr173_api.jar and webservices-api.jar


The four files copied to the \shared\lib directory are:

webservices-extra.jar, webservices-extra-api.jar, webservices-rt.jar and webservices-tools.jar


In addition, the script updates catalina.properties in the \conf directory. It changes:

shared.loader=


to

shared.loader=${catalina.home}/shared/lib/*.jar


And that, believe it or not, is that!

Problem solved!

If you want to back the change out, run:

ant -f metro-on-tomcat.xml uninstall


For completeness, if you want to enable JAX-WS 2.2 for all applications running under Java SE 6, you may run the command:

ant install-api


That command will copy the file webservices-api.jar to ${java.home}/lib/endorsed.

(The command needs to be run by a user that has the permissions to copy files into ${java.home}/lib/endorsed.)

Note that I didn't need to do this.

Enjoy!

Thursday, November 11, 2010

Netbeans : Can't login to Tomcat as Admin or Manager

Using Netbeans 6.9 and Tomcat 6 - integrated with Netbeans.

When I go to the Tomcat server home page i.e. http://localhost:8084/

and then click on the Manager link, I am asked to login. But my login is not accepted! WTF?

The usual course of action is to go to the Tomcat installation which is usually something like:

...\Program Files\Apache Software Foundation\Apache Tomcat 6.0.26\conf

and edit the tomcat-users.xml file adding the lines:






but this login is not accepted.

Looked through the logs and noticed:

Using CATALINA_BASE: "...\Tmp\.netbeans\6.9\apache-tomcat-6.0.26_base"
Using CATALINA_HOME: "...\Program Files\Apache Software Foundation\Apache Tomcat 6.0.26"


where the Tmp directory is my Netbeans work directory.

You have to edit the xml file in that directory NOT the one in the "Program Files" tree.

Then found an easier way.

Click on the Server tab in Netbeans, then right click Tomcat and click Properties.

Click the Connection tab.

The credentials in that tab are what you have to use. It's normally ide and some random password which you can change.

Note that the CATALINA_BASE and CATALINA_HOME settings appear in this tab as well.





Enjoy!

Thursday, October 21, 2010

Netbeans : jQuery code complete / auto complete

Need to do some jQuery work and it's a lot easier with auto complete / code complete.

See my SO answer here.

Enjoy!

Tuesday, October 20, 2009

Netbeans : Generating getters and setters for a Java class

Using Netbeans 6.5.

Unlike Eclipse (where the link to do this is obvious), in Netbeans you will find this under:

Refactor / Encapsulate Fields

Enjoy!

Metro : JAX WS catalogue

One of the problems with using Netbeans to generate web services using Glassfish / Metro is that when you want to create a new Web service client, you are asked to select the web service which is normally on your local machine.

This means that the web service has an address like http://localhost:8080 and it then becomes a problem when you deploy to other environments.

One way around this is to use a catalog to resolve the addresses at run time. The file is called jax-ws-catalog.xml and it's placed in the META-INF directory.

It looks like e.g.

 
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="system">
<rewriteSystem
systemIdStartString="http://localhost:8080/"
rewritePrefix="http://some url:some port/"/>
<rewriteURI
uriStartString="http://localhost:8080/"
rewritePrefix="http://some url:some port/" />
</catalog>


This searches for any URL that starts with "http://localhost:8080/" and replaces this with "http://some url:some port/" e.g.

http://localhost:8080/webserver/WebService

becomes

http://some url:some port/webserver/WebService

The ant build files in Netbeans use the -catalog option to point to a file called catalog.xml in the project root directory. You can apply the same principles to this file to resolve addresses at compile time.

Some useful links:

Using a JAX-WS Catalog

How to write an XML catalog file

Global URI re-writing with jax-ws-catalog

Enjoy!

Friday, August 07, 2009

Netbeans : New Web Service client error

I use Netbeans 6.7.

In the web applications project where you are trying to add a web service call to e.g. a servlet, click "New / Web Service Client" and select the project where the actual web service lives. When you click Finish, you get the error.

"wsimport doesn't support the "xnocompile" attribute"

To get round this:

In the project where you are trying to add the web service client, right-click the web service under the "Web Service Reference" sub-tree.

Select "Edit Web Service Attributes".

Click "WsImport Options" tab.

Select the xnocompile line and Remove then OK.

Right-click again on the web service under the "Web Service Reference" sub-tree.

Select "Refresh Client"

The client should now be created.

These a good tutorial about Netbeans web services
here

Enjoy!

Netbeans : Display Web Service Designer and Axis2

This is displayed (I use Netbeans 6.7) when you right click on a web applications project and select "New / Web Service".

You then get two tabs - Source and Design.

However, you do NOT see these tabs if you have previously loaded the Axis2 support plugin.

Enjoy!