Archive for the ‘Java (IT)’ Category

Maven. Using dependency from test scope

May 18, 2011

If you have module A where you have some test classes, and module B where you wish to use this test classes. You need to use some plugin with configured goal, some scope and some type to resolve this.

So, in module A


And in module B:


tomcat for hosting

January 25, 2011

According to this link, if you want to use tomcat for hosting several sites, and you don’t want to restart whole server every time when you want to change something in one of these apps, you should make ‘server-reloading’-tests for your apps before upload new code for particular application which is hosted there, because you risk to get OutOfMemoryError error due to Classloader leaks.

jboss remote debugging, turn on

January 17, 2011

to remember:
in order to set jboss app server to be be running in debugging mode while you debugging it remotely, you should uncomment line in:


line like this:

# Sample JPDA settings for remote socket debuggingJAVA_OPTS=”$JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=8787,serve

Eclipse + Maven + OSGI + Spring DM Server – Settings and tips.

November 30, 2009

Recently I have watched SptringSource University video tutorial that describes how to work with OSGI using Spring Framework. And, taking into consideration that being familiar with IntelliJ IDEA I had a set of problems related to how to set up the Eclipse environment to be able to use it to implement this tutorial as well as other code that I’m going to make soon using the set of technologies like Java + Spring + SpringSource DM + OSGI(Spring DM) + Maven. So this short article might be interested for people who want to fulfil similar issue.

I could not find that video I mentioned above any more. But i’ve got some related to this video in you-tube.

Here we are considering settings which related to two projects where one project depends on other one and there is main project that is responsible for these two projects and holds them both. Those two projects have maven package = jar, but main project have package type = pom.

Step 1 – Creating two maven projects (let say: “client”, “server” projects)

Use Eclipse menu to so it – New->Project->Maven project->Creating simple project->Typing name of the project → Finish

Step 2 – Adding OSGI nature for the projects

We assume that we use SpringSource Suite Tool (based on Eclipse), so:
Using context menu clicking on particular project using right mouse button, selecting “Spring Tools” menu, select the “Enable OSGI bundle project nature”. Doing this for our two projects (but not for main one). When you added OSGI project nature it will add Spring nature (if it not so, you may add it by your own – in any case suing Spring Tools context menu you may check or add this nature).

Step 3 – Create some classes. Internal package

Create some classes in our projects (but not in main one). The best practices if to add an implementation of the classes to the sub-packages called “internal” but interfaces which this classes are implemented to put to above.
So, the hierarchy should be like this:

some interfaces for osgi services
some classes that implement osgi services

Step 4 – Adding META-INF and ‘spring’ folder

For every projects (but not for main one) select src/main/java node and add there new folder named as ‘META-INF’, then create there ‘spring‘ folder (as sub-folder of META-INF). Here we are going to add spring context files – it ‘s best practices to put them here.

Step 5 – Add to ‘spring’ folder two xml files

Select ‘spring’ directory, then select ‘New->Spring Bean Configuration File

  1. file name: module-context.xml
    xsd namespace declaration: beans
  2. file name: osgi-context.xml
    xsd namespace declaration: beans, osgi

It is also the best practices to divide pure spring beans from osgi ones. Names of the files it are the best practices also.

Step 6 – Make Spring config visible to each other and make them named

After this, when spring context files were created, we should make some extra settings related to them in our IDE. For this purpose clicking to the project’s top node, selecting the properties of a project. Select Spring->Spring support item there. Then go to Config Files tab and select check-box to enabled “Enable support of <import />‘ element…”. Then click to ‘Set config tab‘, pressing to ‘New‘ button to select our files grouping it and naming as somehow.
In other case if we didn’t do it then we would not refer from one file to another (suing context tips, context drop-downs, auto-filling etc.). So if we wish to be able us it – we must let Eclipse know about this.
So we should prepare two groups for our projects:
group one: module-context.xml, osgi-context.xml for/in “cleint module”
group two: module-context.xml, osgi-context.xml for/in “server module”


Selecting ‘META-INF’ folder (or select the top node of the current project where we are working on) that we have created recently and using context menu “Spring Tools->Run generation of MANIFEST.MF file“. After this it will be created in the /src/main/resource directory because we it havs to do with maven-nature project and maven supposes that MANIFEST.MF it is a resource.

Step 8 – Spring dependencies

Let’s say that we want to add Client class that use Spring framework like this:

public class TestClient {

private Server theService;

public TestClient(Server server) {
theService = server;

public void init() {
String name = theService.getServerName();
System.out.println(“The Server name: ” + name);

we must add dependencies to the pom.xml for “client” projects. To do this we may add use drop-down context menu that appears when we are clicking on the red marks near spring annotations. Selecting ‘find a dependencies’ and adding new spring dependency. It may look like this:


Here we use “provided” scope because we assume that we are going to use SpringSource DM server that already has (provides) spring bundles in itself. It would be nice (of course) if you use the same version of Spring framework that SpringSources DM sever uses.

After this you might find that it still marked with red, using the tip you set your project “to be in compliance with java5” – just do it.

Step 9 – Be sure you added maven-dependencies that says that a client-side depends on server one

Step 10 – Maven settings

If one module doesn’t see another module (or it can see but it shouldn’t see, because there are no dependencies that make a project visible for others), or if you want to be sure that Eclipse works well with your project using only maven plugin, i.e. without using some extra settings (like adding class paths from one to other like we are using when work with ant-based projects) that lead to be far from the production version of an application (that why it’s bad having not maven setting related to visibilities and scopes). To resolve this problem or be sure you are on the right way you must select context menu of particular maven project and select the menu Maven->Update project configuration clicking on it. This action will lead to removing all unnecessary configurations that might be took place before you doing this action and will add maven oriented configuration (only) to your projects. Yo may do it periodically with every project you have (or do it if you suspect that something might be wrong with your project’s settings).

11. Deployment

In order to deploy the application, or bundle (in our calse “client“, “server” bundles) it takes you only to drop the application to your application server that is located somewhere in our ide’s tab (depending on how you have configured your IDE). It’s very easy in fact. Also you may configure console output that comes from the server to be able to see a result of the deployment.

12. OSGI console

In order to use the OSGI console – to be able to call OSGI commands like ss, bundle, diag etc. you may use the telnet typing in a console window like this: telnet localhost 2401. I.e. when we start SpringSource DM server from our IDE it opens 2401 port that telnet can use to show OSGI console.

13. Server logs

In order to be able to look at the logs of SpringSource DM server you should go to the path <ourserver_unstall_path>/serviceability/trace and to find there some folders which named like your bundles. Inside every of this folder you can find a log file named as trance.log, there you can find detail information about activities of particular bundle.

Roo and IDE

November 23, 2009

Recently I’ve added the issue about OSGI and IDE. There is one more about new Spring technology called Spring Roo and IDEs. This technology helps to create Java enterprise level applications very quickly (it supposed). It has rich console ui that provides some useful hints that makes it to be rich… where a developer can type special commands which lead to the creation of an application structure, using maven (optionally) structure, creating configs, adding other popular frameworks and so on. It seems like like Ruby On Rails only for Java people (other comparisons are possible as well – for example it similar to PAX Construct, but it can do more), it even seems more flexible as for me. Now this project existent only as beta version, but it works in spite of this. So a programmer can use command line to generate some code as well as write a code by hand. Also Roo able to scan file system where a project lives to react somehow to an user actions.

There is only one problem, it requires IDE support as well. So, for now only one IDE can provide this – Spring Source Suite Tool (based on Eclipse).  I have investigated this question and found that IntelliJ idea will able to provide this support only beginning from v 9.x (bot not even with 9.0 that now is beta).

So, as for me I will plan to play with it using Eclipse, but actually I prefer IDEA (actually I know that many guys from SpringSource like IDEA also)… I think for many people who want to try Roo it might be the problem if they are not familiar with Eclipse.


November 22, 2009

Recently I’ve tried to develop same samples with OGI. I used to work with IntelliJ IDEA to develop something that is not related to standalone GUI, but actually now I’ve got a problem because it seems that, it is not very comfortable to work with OSGI using IDEA. I used IDEA and PAX Construct utilities for this, it supposed that PAX Construct may help to deal with OSGI, but in fact I would rather prefer to feel support from IDE (or to feel support from IDE also). Moreover there were situations when  IDEA marked something by red (to show that something not resolved) even if it’s ready to compile and every problems are resolved in fact. So it’s boring be. That why I was switched to use Eclipse based Spring Suite Tool. It seems it is more appropriate for OSGI development. It has real rich support to work with this.

In fact I wanted to use Spring DM, but first – to start from plain OSGI. Maybe after this try I will switch to IDEA back again (it has Spring DM support).

%d bloggers like this: