karaf 3 with OSGi , how install a bundle - java

How create a bundle using Apache karaf 3? Someone know ?
I have try in Eclipse:
I export a jar with a manifest file ... and why I have this error:
karaf#root(dev)> feature:repo-add file:///C:/Users/xx/Downloads/apache-kara
f-3.0.1/apache-karaf-3.0.1/deploy/features.xml
Adding feature url file:///C:/Users/xx/Downloads/apache-karaf-3.0.1/apache-
karaf-3.0.1/deploy/features.xml
karaf#root(dev)> feature:install greeter_server
Error executing command: Jar is not a bundle, no Bundle-SymbolicName file:///C:/
Users/xx/Downloads/apache-karaf-3.0.1/apache-karaf-3.0.1/deploy/nebula_cdat
etime_VF4.jar
karaf#root(dev)>
This is my features.xml:
<features>
<feature name='greeter_server' version='1.0'>
<bundle>file:///C:/Users/xx/Downloads/apache-karaf-3.0.1/apache-karaf-3.0.1/deploy/nebula_cdatetime_VF4.jar</bundle>
</feature>
</features>

When you want to export a bundle or a declarative service from eclipse rcp you must use the file -> export -> plugin development-> deployable plugins and fragments as explained here.
Obviously the project you want to export as a bundle must have a sound manifest file. To have an idea of a correct osgi-friendly structure your project should have, you could create a test plugin project in eclipse rcp using the File → New → Other... → Plug-in Development → Plug-in Project menu. In the wizard you can choose to create a simple osgi bundle with an activator. The outcome is a skeleton for your new osgi bundle.

I think an easier and cleaner way is to use Maven. This way you can produce a correct OSGI ready JAR which may be loaded quickly into Karaf.
In this case pom.xml file should be like this:
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>your.group
<artifactId>artifact-123</artifactId>
<name>Karaf OSGI Module</name>
<packaging>bundle</packaging>
....
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.4.0</version>
<extensions>true</extensions>
<configuration>
<instructions />
</configuration>
</plugin>
...
</plugins>
</build>
...
</project>
This kind of POM file will produce a JAR which is OSGI compatible and you don't have to mess up with absolute file names. In your feature.xml we can declare the module like this:
<bundle>mvn:your.group/artifact-123/${pom.version}</bundle>

Related

How can I get the resource directory in maven to work?

I have a Java Maven web app project that I'm trying to clean up. In the <build> section of my pom.xml, I have the following:
<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
</resource>
</resources>
<filters>
<filter>profiles/${build.profile.id}.profile.properties</filter>
</filters>
[...other properties...]
</build>
In my project, which on my Mac is /Users/anthony/workspace/my-project/, i src/main/resources/profiles/I have local.profile.properties and qa.profile.properties.
Then, in my maven profiles in my pom, I define ${build.profile.id} as the following:
<profile>
<id>local</id>
[...stuff...]
<properties>
<build.profile.id>local</build.profile.id> <!-- or qa -->
[...stuff...]
</properties>
</properties>
When I am in my console and run $ mvn clean install -Plocal, I get the following error:
Failed to execute goal ... on project my-project: Error loading property file '/Users/anthony/workspace/my-project/profiles/local.profile.properties'.
It seems like Maven is not recognizing the resource directory for my filtering profile properties file. This only works when I explicitly put the entire path of my properties file, like so:
<filters>
<filter>src/main/resources/profiles/${build.profile.id}.profile.properties</filter>
</filters>
Is there a way for me to not have to explicitly state src/main/resources? I thought that the point of me declaring a resources directory was that I could use it, especially for declaring filtering.
The resource directory only has a meaning as "resources" for the Java artifact being built, but not for Maven itself. For Maven, the "resources" directory has a special meaning in the sense that Maven knows where to copy those files to in the resulting jar-file. But for Maven working with files or filtering files, you have to tell Maven the exact path, as Maven does not know if the filtered file is a resource, a source file, or something else. Also, you could have multiple source or resource directory defined, and Maven would not know, in which one to filter. Thus you always need to specify the full path for Maven.
So, in short:
Is there a way for me to not have to explicitly state src/main/resources?
No.

How to deploy a module in an Alfresco deployed in Tomcat

I have successfully deployed alfresco community 4.2.f in a Tomcat 7.0.59 with a database MySQL5.6 and jdk1.8.0_141
No problems thus far, now, I got a module developed by our company which I need to be deployed in alfresco. This module invokes a WS which will send a PDF to some place.
I got this module in a jar compiled with jdk1.8.0_141
I tried to put it inside the alfresco.war before deployment in Tomcat in WEB-INF/lib but when I do that and deploy with startup.bat from Tomcat it pops in the console
instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/codehaus/xfire/XFireRuntimeException
I understand this exception is caused by putting the jar inside the war.
I was told that the jar was compiled also in jdk8.
Also, tell you that if instead of this jar I put inside the alfresco.war in WEB-INF/classes a properties file to get our database in deployment it works fine.
The problem is when I try to deploy the module.
I saw there are quite tutorials pointing to do something like:
java -jar bin/alfresco-mmt.jar
I can't do that because this is done installing alfresco with its wizard I assume. I did it deploying alfresco in a fresh tomcat installation.
Does anyone know how to deploy our module with the way we deployed alfresco? Thank you.
You have two ways to install your amp :
The first traditional one :
This is the one installed with the apply amp procédure (alfresco-mmt).
To me, this is not true that it is not compatible with your installation. You can easily find the bin folder (containing the alfresco-mmt.jar file) here in the alfresco packaging : https://download.alfresco.com/release/community/4.2.f-build-00012/alfresco-community-4.2.f.zip
When you have it, you can follow the documentation : http://docs.alfresco.com/4.2/tasks/amp-install.html
And apply your amp for example following this way :
java -jar alfresco-mmt.jar install <AMPFileLocation> <WARFileLocation>
The second one :
You can recreate the war with the alfresco sdk and include in the build the module you created.
If you follow this documentation : http://docs.alfresco.com/4.2/tasks/dev-extensions-maven-sdk-tutorials-all-in-one-archetype.html
the war produced in the target folder of the repo part will contain your module, since the pom of this module will contains a dependency to the amp module :
...
<dependencies>
<dependency>
<groupId>${alfresco.groupId}</groupId>
<artifactId>alfresco</artifactId>
<type>war</type>
</dependency>
<!-- Demonstrating the dependency on the repo AMP developed in the 'amp'
module -->
<dependency>
<groupId>x.y.z</groupId>
<artifactId>my-amp</artifactId>
<version>${my-amp.version}</version>
<type>amp</type>
</dependency>
</dependencies>
...
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<!-- Here is can control the order of overlay of your (WAR, AMP, etc.)
dependencies | NOTE: At least one WAR dependency must be uncompressed first
| NOTE: In order to have a dependency effectively added to the WAR you need
to | explicitly mention it in the overlay section. | NOTE: First-win resource
strategy is used by the WAR plugin -->
<overlays>
<!-- Current project customizations -->
<overlay />
<!-- The Alfresco WAR -->
<overlay>
<groupId>${alfresco.groupId}</groupId>
<artifactId>alfresco</artifactId>
<type>war</type>
<!-- To allow inclusion of META-INF -->
<excludes />
</overlay>
<!-- Add / order your AMPs here -
<overlay>
<groupId>x.y.z</groupId>
<artifactId>my-amp</artifactId>
<type>amp</type>
</overlay>
</overlays>
</configuration>
</plugin>
</plugins>
</build>

Similar solutions for java.lang.NoClassDefFoundError: org/joda/time/DateTime not working

I have seen this question posted here before and I have looked at the solutions however I cannot fix the problem I'm having. I created a very simple Maven project in Eclipse for Java and I want to run the output jar file e.g. java -jar jarfilename.jar
I can run the program by right clicking on the project in eclipse and indicating run as Java application. I can build the project to a jar file with mvn package. Running the jar file I get the output of NoClassDefFoundError for the joda time. The joda jar files are in the configured repository e.g. .m2/repository/joda-time/joda-time/2.8.2. There are no errors indicated for the project in Eclipse. I'm using jdk1.8.0_92 Maven version 3.3.9 and eclipse Java EE Neon release 4.6.0. Java home is configured in the environment variables and so too is the class path as: ...\Java\jdk1.8.0_92\jre\lib;C:\Users\username.m2\repository
Some additional information the classpath is correct in terms of not having typos in it. I also looked at a solution from another similar question wherein the suggestion was to add the external jar to the bootstrap entries under run configuratotion. I have also made an entry in the Java build path for joda time which points corretly to the .m2/repository.../joda-time/2.8.2 What this seems like is that when this runs from eclipse the path to the joda time jar file is (for lack of a better term) known. When the jar file is built however that path is not known. I opened the jar file and looked at the MANIFEST.MF file and I see:
Manifest-Version: 1.0
Built-By: John
Class-Path: joda-time-2.8.jar
Build-Jdk: 1.8.0_92
Created-By: Maven Integration for Eclipse
Main-Class: hello.HelloMain
The source is very simple:
package hello;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
public class HelloMain {
public static void main(String[] args) {
System.out.println("Hello From My Main ! It worked\n");
final DateTime today = new DateTime().withZone(DateTimeZone.UTC);
DateTime tommorrow = today.plusDays(3);
String startTime = today.toString(DateTimeFormat.forPattern("yyyy-MM- dd'T'HH:mm'Z"));
String endTime = tommorrow.toString(DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm'Z"));
System.out.printf("The start time %s End Time %s \n", startTime, endTime);
}
}
This 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>hello</groupId>
<artifactId>hello</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>hello.HelloMain</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/joda-time/joda-time -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.8</version>
</dependency>
After trying many different approaches to the Pom file I had settled on a different approach. This would only apply if your using Eclipse to do this as Eclipse offers an Export to runnable jar feature. While in Eclipse highlight your project of interest, right click to Export and select Java/Runnable JAR file. Click next and select "Package required libraries into generated JAR". This built the jar file with all of the required jar files I needed. While this really does not solve the problem from the perspective of creating the output jar using the maven packaging it did provide a proper executable jar file.

Deploy war file to jetty using jenkins

I deployed the war file to tomcat using jenkins as a post-build action
WAR/EAR files=**/demo.war
Context path=application
Container=tomcat 7
Manager user name=admin
Manager password=admin
Tomcat URL=https://localhost:8080/
How to deploy a war file to jetty instead of tomcat using jenkins. The project is a maven project which does not have any plugin for jetty.
I think the simplest way to do this is the following:
1. Add to pluguns of pom.xml next lines
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.1.1.v20140108</version>
<configuration>
<stopPort>9966</stopPort>
<stopKey>stopKey</stopKey>
<stopWait>20</stopWait>
</configuration>
</plugin>
2. Change goals to
mvn jetty:stop jetty:run-forked
If you cannot change pom.xml then you can create separate pom.xml (on other folder). And run the same tasks with this pom.xml. Post Steps > Invoke top-level maven target > advavanced

What defines the "war-ness" of my project?

I'm running the goal: tomcat:deploy. There are no errors, but it's not deploying my project into tomcat. I noticed this message:
[INFO] Skipping non-war project
What defines the "war-ness" of my project? How do I make my Eclipse project a war project?
Here's my plugin setting:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
</plugin>
I have my structure like this:
src > main > java
src > main > webapp > WEB-INF > web.xml
This one works with the maven:war plugin. I'm able to build a war with this structure.
My end objective is to do away with the war building part and be able to deploy my project to tomcat with one maven command.
Maybe you are missing the 'packaging' element in your pom.xml:
<packaging>war</packaging>
If you don't include one, the default packaging is 'jar'.

Categories

Resources