Platform: Intel i7, Windows 7 professional,
          eclipse Neon 4.6.0
          m2e 1.7.0.20160603-1933 (ie. the version bundled with eclipse Neon)
          Java SDK 1.8.0_91
          Pax web 4.2.7
          Pax exam 4.9.1
          Apache myfaces 2.2.6
          primefaces 5.1

I was trying to change the controller bean of my application to do its
setup in a @PostConstruct, instead of (as now) in the constructor:
  
https://github.com/steinarb/ukelonn/blob/using-primefaces/ukelonn.bundle/src/main/java/no/priv/bang/ukelonn/impl/UkelonnController.java
(Note: The bean currently only contains hardcoded data for testing)

So I created a public void init() method, and tried annotating it with
a @PostConstruct annotation, ie. like so:
    @PostConstruct
    public void init() {
        transactionTypes = new ArrayList<TransactionType>();
        transactionTypes.add(new TransactionType(1, "Støvsuging 1. etasje", 
45.0, true, false));
        transactionTypes.add(new TransactionType(2, "Støvsuging kjeller", 45.0, 
true, false));
        transactionTypes.add(new TransactionType(3, "Gå med resirk", 35.0, 
true, false));
        transactionTypes.add(new TransactionType(4, "Inn på konto", null, 
false, true));

        transactions = new ArrayList<Transaction>();
        transactions.add(new Transaction(transactionTypes.get(0), new Date(), 
45.0));
        transactions.add(new Transaction(transactionTypes.get(1), new Date(), 
45.0));
        transactions.add(new Transaction(transactionTypes.get(2), new Date(), 
35.0));
        transactions.add(new Transaction(transactionTypes.get(3), new Date(), 
-125.0));
    }


However that gave me problems in eclipse:
 1. Typing Ctrl-SPC in eclipse didn't offer to expand @PostConstruct
 2. Typing @PostConstruct made @PostConstruct be underlined in red, and
    typing Ctrl-1 on top of the highlighted text, didn't give me import
    of javax.annotations as an alternative
 3. Manually adding "using javax.annotation.PostConstruct" made both the
    "using" line and the @PostConstruct be highlighted with yellow
    underlining (i.e. as a warning).
    The warning was:
     Access restriction: The type 'PostConstruct' is not API (restriction on 
required library 'C:\Program Files\Java\jre1.8.0_91\lib\rt.jar')


Trying to test the bundle in a pax exam test, that uses equinox as the
OSGi runtime, I get the following error message:
org.osgi.framework.BundleException:
Could not resolve module: no.priv.bang.ukelonn [61]
  Bundle was not resolved because of a uses contraint violation.
  org.osgi.service.resolver.ResolutionException: Uses constraint violation. 
Unable to resolve resource no.priv.bang.ukelonn [osgi.identity; 
osgi.identity="no.priv.bang.ukelonn"; type="osgi.bundle"; 
version:Version="1.0.0.SNAPSHOT"] because it is exposed to package 
'javax.annotation' from resources org.apache.servicemix.specs.jsr250-1.0 
[osgi.identity; osgi.identity="org.apache.servicemix.specs.jsr250-1.0"; 
type="osgi.bundle"; version:Version="2.0.0"] and org.eclipse.osgi 
[osgi.identity; osgi.identity="org.eclipse.osgi"; type="osgi.bundle"; 
version:Version="3.11.0.v20160603-1336"; singleton:="true"] via two dependency 
chains.

Chain 1:
  no.priv.bang.ukelonn [osgi.identity; osgi.identity="no.priv.bang.ukelonn"; 
type="osgi.bundle"; version:Version="1.0.0.SNAPSHOT"]
    import: (osgi.wiring.package=javax.annotation)
     |
    export: osgi.wiring.package: javax.annotation
  org.apache.servicemix.specs.jsr250-1.0 [osgi.identity; 
osgi.identity="org.apache.servicemix.specs.jsr250-1.0"; type="osgi.bundle"; 
version:Version="2.0.0"]

Chain 2:
  no.priv.bang.ukelonn [osgi.identity; osgi.identity="no.priv.bang.ukelonn"; 
type="osgi.bundle"; version:Version="1.0.0.SNAPSHOT"]
    require: (osgi.wiring.bundle=org.primefaces)
     |
    provide: osgi.wiring.bundle; bundle-version:Version="5.1.0"; 
osgi.wiring.bundle="org.primefaces"
  org.primefaces [osgi.identity; osgi.identity="org.primefaces"; 
type="osgi.bundle"; version:Version="5.1.0"]
    import: (osgi.wiring.package=javax.annotation)
     |
    export: osgi.wiring.package: javax.annotation
  org.eclipse.osgi [osgi.identity; osgi.identity="org.eclipse.osgi"; 
type="osgi.bundle"; version:Version="3.11.0.v20160603-1336"; singleton:="true"]
        at 
no.priv.bang.ukelonn.tests.UkelonnServiceIntegrationTest.setup(UkelonnServiceIntegrationTest.java:143)


Note: When I start the gogoshell with
 cd ukelonn.gogoshell
 mvn clean install pax:provision
I get no bundle resolution error. However, the gogoshell uses felix as
the OSGi runtime, so that may be a different environment in this
context...?

Does anyone know what to do with this?  Is it fixable, both for the pax
exam test and for eclipse?  Does it have something to do with me using
Java 8?

I have googled and found some interesting matches
 [1] http://njbartlett.name/2011/09/02/uses-constraints.html
 [2] http://spring.io/blog/2008/10/20/understanding-the-osgi-uses-directive/

Article [1] is a bit old (2011), but it still is the most promising
google has found me (the problem package in the article is actually
javax.annotation as well).

What I understand article [1] to say, is that the javax.* packages are
all bundled into the Java Runtime, and exported from there by the OSGi
system bundle (this matches what I see in the error messages above), and
since there is no documentation on what versions of an API a particular
version of the RT includes, they packages are all exported versionless,
and this is what creates the conflict.

Article [1] lists three possible cures, and recommends the second in the
list, which is to create an osgi.java.profile setting which lists all
exported packages with version numbers.

The problem with that is that is that:
 1. I have no idea what such a profile looks like (and google hasn't
    been able to tell me yet)
 2. I think I will need to create a profile that lists all exported
    packages with their versions, and I have no more idea where to find
    those, than the authors of the OSGi system bundle...

Also, I have no idea if using this profile on eclipse itself is
possible, and if so, if this will lose me the warnings on @PostConstruct
in eclipse.

Perhaps the simplest approach would be to not try to use @PostConsruct,
and continue to do things in the bean constructor...? :-)

Thanks!


- Steinar

-- 
-- 
------------------
OPS4J - http://www.ops4j.org - [email protected]

--- 
You received this message because you are subscribed to the Google Groups 
"OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to