Missing requirement package in OSGI Bundle - spring

I'm trying to connect oracle database using org.springframework.jdbc.core.JdbcTemplate in OSGI bundle. When deploying bundle in servicemix , it shows error
org.osgi.framework.BundleException: Unresolved constraint in bundle My Second Service [376]: Unable to resolve 376.0: missing requirement [376.0] package; (package=org.springframework.jdbc.core)
And here is my pom file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.my.service</groupId>
<artifactId>my-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../my-service/pom.xml</relativePath>
</parent>
<groupId>com.brodos.osgi</groupId>
<artifactId>my-second-service</artifactId>
<packaging>bundle</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>My Second Service</name>
<url>http://example.net</url>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.3.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring</artifactId>
<version>2.8.0-fuse-01-13</version>
</dependency>
<dependency>
<groupId>springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>1.2.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<version>1.4.3</version>
<configuration>
<instructions>
<Bundle-SymbolicName>My Second Service</Bundle-SymbolicName>
<Bundle-Description>My Second Service</Bundle-Description>
<Import-Package>
org.apache.servicemix.camel.nmr,
org.apache.servicemix.nmr.api,
org.apache.servicemix.nmr.api.event,
org.apache.servicemix.nmr.api.internal,
*
</Import-Package>
<Private-Package>com.test.osgi.*</Private-Package>
<Include-Resource>src/main/resources</Include-Resource>
<DynamicImport-Package>*</DynamicImport-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>

You need to install the bundle that exports the org.springframework.jdbc.core package.

Jignesh, this may be worth looking at:
Download this jar from ebr.springsource.com:
Since you are in an OSGi environment, you will also require other bundles like org.springframework.osgi.core org.springframework.osgi.io and org.springframework.osgi.extender. These will also require some additional bundles like org.apache.commons. You may have to fiddle a bit with MANIFEST.MF to match versions to make it run.
Take a look at this tutorial to get an idea: I was able to import and run this.
Note* As of now I am doing this integration manually...I hope to use maven as things get clear for me.

Related

Liferay 6.2 is not deploying my jar files

I need to modify and deploy some liferay modules that I didn't write. The original developer is not with the company anymore and there's almost no documentation on the code. The project is structured differently to the liferay projects I'm familiar with, so I'm struggling with the deployment.
It's a maven project with a number of modules, and when I build it generates multiple jar files. When I copy one of those jar files to my local deployment folder Liferay prints something like:
13:07:23,201 INFO [com.liferay.portal.kernel.deploy.auto.AutoDeployScanner][ModuleAutoDeployListener:70] Module for /Users/ali/LIFERAY/liferay-portal-6.2-ee-sp14/deploy/com.monator.ehp.routes.servicemix.moci-1.6.1.jar copied successfully. Deployment will start in a few seconds.
... and then nothing. If I check the liferay/data/osgi/modules/ directory I do see the jar file is present there, however when I test the behaviour I do not see my changes reflected, even after restarting the tomcat server.
We're running Liferay 6.2 ee sp14 with tomcat and postgres. I believe the modules in question are osgi modules, but I don't think that changes the deployment method?
EDIT: This is the main project pom file, running "mvn install" in the same directory does not create a war file, but does create multiple individual jar files in the various child module folders:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.monator.tools</groupId>
<artifactId>monator-parent</artifactId>
<version>0.7.0</version>
</parent>
<groupId>com.monator.clients.moh</groupId>
<artifactId>camel-routes</artifactId>
<version>1.6.1</version>
<packaging>pom</packaging>
<name>Camel Route Project Parent</name>
<scm>
<url>https://bitbucket.org/monator/ehealth-portal-camel-routes.git</url>
<connection>scm:git:ssh://git#bitbucket.org/monator/ehealth-portal-camel-routes.git</connection>
<developerConnection>scm:git:ssh://git#bitbucket.org/monator/ehealth-portal-camel-routes.git</developerConnection>
</scm>
<modules>
<module>servicemix.routes.parent</module>
<module>liferay.routes.parent</module>
</modules>
<properties>
<camel.version>2.13.2</camel.version>
<osgi.export.package></osgi.export.package>
<osgi.import.package>*</osgi.import.package>
<osgi.bundle.symbolic.name>${project.groupId}.${project.artifactId}</osgi.bundle.symbolic.name>
</properties>
<build>
<finalName>${osgi.bundle.symbolic.name}-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.4.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${osgi.bundle.symbolic.name}</Bundle-SymbolicName>
<Export-Package>${osgi.export.package}</Export-Package>
<Import-Package>${osgi.import.package}</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<!-- Dependencies only declared for IDE support -->
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-blueprint</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.aries.blueprint</groupId>
<artifactId>org.apache.aries.blueprint.cm</artifactId>
<version>1.0.5</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-osgi</artifactId>
<version>5.10.0</version>
<!-- Since we're using Maven 3, this is necessary. -->
<exclusions>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>```
Liferay 6.x can deploy war files, not jars!
Maybe your maven projects builds many jars for then build a war file?
Better if you post the pom.xml and the internet crew try to understand the mistery..
EDIT:
This project build osgi jars for Apache Camel to create some custom routes! https://camel.apache.org/ , there are not Liferay modules!
(Maybe Liferay plays as Camel consumer/producer?)

"Cannot access com.google.common.base.Predicate" in Selenide

I am new to Selenide and I tried to follow this video: https://vimeo.com/107647158 at 8:05 - part
$("#ires li.g").shouldHave
is underlined with "Cannot access com.google.common.base.Predicate" error.
I tried some Google and found this: What is the fix for class file for com.google.common.base.predicate not found? which pointed to https://github.com/google/guava page.
I added dependency to pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company.myFirstSelenideTest</groupId>
<artifactId>myFirstSelenideTest</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>metadataTestonDPU</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>selenide</artifactId>
<version>4.12.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>25.1-jre</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<fork>true</fork>
<executable>C:\Program Files\Java\jdk1.8.0_131\bin\javac</executable>
</configuration>
</plugin>
</plugins>
</build>
</project>
But it didn't resolve my issue.
I also checked %JAVA_HOME% and path to JDK/JRE and seems to be fine. What I missed?
Oh, duck method...
I added import com.google.common.base.Predicate; on the top and IntelliJ IDEA posted on red Predicate part with a tip to add it to a classpath
Sorry for dumb question
I faced same issue for Predicate & Collect, then added below and it worked
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-base</artifactId>
<version>r03</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-collections</artifactId>
<version>r03</version>
</dependency>
Springfox 3.x removes dependencies on guava and other 3rd party libraries (not zero dep yet! depends on spring plugin and open api libraries for annotations and models) so if you used guava predicates/functions those will need to transition to java 8 function interfaces

Complete pom.xml for stormpath Web App with Java Servlet, JSP

There is a tutorial for stormpath (online user management). The pom.xml that is provided at https://stormpath.com/blog/java-webapp-instant-user-management#maven is a bit confusing.
pom.xml
4.0.0
com.stormpath.samples
stormpath-webapp-tutorial
0.1.0
war
com.stormpath.sdk
stormpath-servlet-plugin
1.0.RC3.1
javax.servlet
javax.servlet-api
3.0.1
provided
javax.servlet
jstl
1.2
ch.qos.logback
logback-classic
1.0.13
runtime
org.apache.tomcat.maven
tomcat7-maven-plugin
2.2
/
What kind of pom structure should this be? How would the complete and working pom.xml look like?
I am Stormpath's Java Developer Evangelist.
This section is in error in the blog. We are currently fixing it. I'll let you know when it's updated.
In the meantime, if you clone the Stormpath Java SDK at https://github.com/stormpath/stormpath-sdk-java.git, there's a fully functional servlet example in the examples/servlet folder. This has the proper pom.xml in it.
To build, you should be able to run:
mvn clean install
in the root folder of the project.
You can then drop examples/servlet/target/stormpath-sdk-examples-servlet-1.0.0.RC-SNAPSHOT.war into the container (like Tomcat) of your choice.
Feel free to drop us a line at: support#stormpath.com if you run into any trouble with this.
I ended up using this in my tutorial example. It works for me. Just add the <dependencies> part to the already existing default pom.xml of your project. Save the pom.xml and it will automatically download a bunch of .jar to your Libraries/Maven Dependencies.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>storm</groupId>
<artifactId>storm</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.stormpath.sdk</groupId>
<artifactId>stormpath-servlet-plugin</artifactId>
<version>1.0.RC9.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>

Maven compile error [package org.testng.asserts does not exist]

When I try to build project via console by [mvn clean install -DskipTests] I get error. I use in my tests testNG SoftAssert and in a test class I just added an import import org.testng.asserts.SoftAssert but looks like maven does not see that package.
Error from console:
package org.testng.asserts does not exist
My pom.xml looks like
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.atlassian</groupId>
<artifactId>tests</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>confluence</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.48.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
Such errors occur when corresponding dependency version do not have the classes you are trying to use. In this case the TestNG version 6.1.1 you are using, does not have package org.testng.asserts. Try using below version,
Also, it will not give error for SoftAsserts import, if you have asked IDE to include TestNG library. This TestNG library surely is of higher version than the one you are referring from pom.xml. Try to keep same versions both in pom.xml & your IDE's testNG plugin to avoid such varying behavior.
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.8</version>
</dependency>
Above version is surely working. Give it a try.
I found out that removing scope inside testng dependency worked. I tried running with scope added to the same dependency but failed. Strange but it just worked by removing testng scope dependency.
Tried different versions, but it did not help. Removing a scope from dependency indeed solved the issue.

Grizzly 2.3.11 - CLStaticHttpHandler - cannot read index.html under resource folder when packed in a jar

I want to host static web pages in a jar. So I used Maven to pack the java project containing a folder having a index.html web page. My code:
server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig, start);
server.getServerConfiguration().addHttpHandler();new CLStaticHttpHandler(Server.class.getClassLoader(), myfolder/), /mysite)
When I access http://localhost:8080/mysite/ in IDE, the handler is able to read index.html. But if I use mvn package and run the jar file, http://localhost:8080/mysite/ doesn't work, unless I specify http://localhost:8080/mysite/index.html in a browser to make it work. The web page folder is under src/main/resources, and it is under the root path when opening the jar.
Thank you so much!
Added: To reproduce this, you can create a Maven project by writing a pom.xml and put something like
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>simple-service</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>simple-service</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-servlet</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-jersey2-jaxrs_2.10</artifactId>
<scope>compile</scope>
<version>1.3.4</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>${jersey.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<jersey.version>2.6</jersey.version>
<grizzly.version>2.3.11</grizzly.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
and create a server like:
final ResourceConfig rc = new ResourceConfig();
rc.register(new LoggingFilter(Logger.getLogger(Main.class.getName()), true));
return GrizzlyHttpServerFactory.createHttpServer(new URI(BASE_URI), rc);
server.getServerConfiguration()
.addHttpHandler(new CLStaticHttpHandler(ServletSimple.class.getClassLoader(), "statichtmlfolder/"), "/ui/" );
System.out.println(String.format("Jersey app started with WADL available at " + "%sapplication.wadl\nHit enter to stop it...", BASE_URI));
System.in.read();
server.shutdown();
statichtmlfolder is a folder containing all the index.html file under /src/main/resources/. we are using Jersey2 here. And use mvn package to package the code to a jar file, go to target folder, then run java -cp dependency/*:api-server-1.0.26-SNAPSHOT.jar com.example.Main. We can see the statichtmlfolder is under the root directory in the jar file.
The bug is fixed in Grizzly 2.3.13
https://java.net/jira/browse/GRIZZLY-1687

Resources