2

Short introduction:

My task is to create a multi-module project (for which I chosen Maven) with modules for JavaME and Android. More specifically: I'm creating application for phones and my boss obliged me to make a project with shared common code (BTW: I think he puts too much pressure on sharing code between JavaME and Android - these two being based on Java language doesn't mean that sharing code between them is easy).

Problem:

I have three modules:

  • common - this is written against JavaSE 1.1 so it doesn't need emulator to test it and also JavaME would be able to use that module,
  • jme - this is written against JavaME 2,
  • android - this is (yet to be) written against Android,

I want to have three different loggers, one for each module, which share common interface and maybe the logger for common module could be a base (class) for the two other loggers. The common classes should use the same logger that the module that incorporates them or a third version of logger for purposes of compiling and testing that common module separately.

Question:

How to configure Maven so that it would include different versions of logger class when compiling & testing different modules? Or maybe you have different proposals?

Update:

Right now I have my own logger for JavaME which uses RecordStore to store logs and has easy way to retrieve a specified continuous range of logs, convert them to JSON, HTML and text and then send them in batch by email. Additionally it periodically removes old records from RecordStore. I would want to keep such functionality, ie. easy way to retrieve and transform log records.

Wibowit
  • 371
  • 2
  • 11
  • Really different logging frameworks or just logging configuration? – khmarbaise Mar 26 '12 at 15:50
  • I have updated the question. Sorry for not writing it in the first place: I want easy way to retrieve logs and transform them into easy to parse format like JSON. – Wibowit Mar 26 '12 at 16:30
  • did you consider using `Class.forName` to instantiate appropriate implementation of that _common interface_ depending on particular module? that worked for me when I needed something similar to what you describe. In two different modules, I had two different instances of `com.company.project.WhateverImpl` class, both implementing common interface, just in very different ways. Worked like a charm – gnat Mar 26 '12 at 20:20

1 Answers1

1

For the testing you can simply achieve that using the appropriate src/test/resources folder to put the configuration for the logging system into and in your pom you could define different logging system in the different areas

   +-- pom.xml
        +--- common (pom.xml)
        +--- jme (pom.xml)
        +--- android (pom.xml)

and you can define in common (pom.xml) a different logging system than in jme (pom.xml) as dependency (scope: test). I'm not sure if this will help you but the problem with different logging frameworks has already been solved by slf4j.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • I cannot find anything like slf4j-j2me. Does such thing exist? And what about storing and retrieving logs? – Wibowit Mar 26 '12 at 16:33
  • I'm not sure if slf4j fit's your needs ...What do you mean by storing ? (they will be written to the file system...or with an appender you can store them into a database etc.). What do you mean by retrieving logs? – khmarbaise Mar 26 '12 at 16:47
  • Read the update in question. Basically everything boils down to the fact that logging should be simple, should not require too much device resources and I want the fresh logs sent back to company (as an e-mail composed of JSON representation of log records for example) when needed, on user request. – Wibowit Mar 26 '12 at 17:10
  • @Wibowit you might be interested in [this answer to another question about J2ME logging](http://stackoverflow.com/a/120913/839601). It suggests _Microlog_ library; comments also mention _J4me_ for the case if you are required to support CLDC 1.0. Actually, if your boss suggests something like _shared common code_ for CLDC 1.0 and Android, consider changing a job - there's not much fun in being micromanaged, and especially micromanaged by an idiot – gnat Mar 26 '12 at 19:21