AEM How to update POI version in OSGi Bundle Wrapper For The Apache POI Library? - aem

In AEM, there's a bundle named "OSGi Bundle Wrapper For The Apache POI Library".
I want to update POI version of that bundle to use POI 5.2.3 with AEM 6.3.
Is there's any way to easily update POI version in this bundle?
Thanks.

Apache POI provides a module to build an all-in-one OSGi bundle, see https://github.com/apache/poi/tree/trunk/osgi
It can either replace the OOB POI bundle, or you can build your own one on top of it, having the POI code in the internal classpath.

In your custom core bundle pom, you may specify embed dependency for the poi version you require. So that your bundle will refer to the poi version from embedded jar and not provided by AEM container.
Have you tried using the tag of maven-bundle-plugin -
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version></version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${bundle.symbolicName}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
<Bundle-Name>${bundle.name}</Bundle-Name>
<Export-Package>${bundle.namespace}</Export-Package>
<Bundle-Activator>Activator.class</Bundle-Activator>
<Embed-Dependency>*;scope=!provided|test;groupId=!org.mybundle.test</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Import-Package>*;resolution:=optional</Import-Package>
</instructions>
</configuration>
</plugin>
You can either include all the dependencies or you can configure to not to include specific ones. The scope attribute lets you configure which dependency jars you want to include based on their include scope. You should not include the dependencies which are only needed for compile and for test.
https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/how-to-embed-dependent-jar/m-p/225793

Related

How to use third party JAR into AEM?

I have a jar file that i received from other team and need to use in AEM. I can not use jar directly in AEM so i converted the Jar into bundle with help of the link "https://helpx.adobe.com/experience-manager/kb/ConvertAJarIntoOsgiBundle.html" , Now my bundle is ready and uploaded into AEM through felix console. Bundle is active. Now i need use the classe which are there in bundle to my java classes. How to use that bunlde in java classes . do i need to added the bundle in POM.xml? if so then how i can use that bundle into POM.xml so that my code can complile.
Now my bundle is ready and uploaded into AEM through felix console
That is not a good idea. Yes, you can install bundles from the Felix console but bundles installations in AEM ideally should be managed by the Sling OSGi Installer which can scan the JCR repository for bundles.
As said in the other response, you should put your bundle in a folder named "install" below the /apps folder.
My recommendation would be to use the Maven Content Package Plugin that is used to generate AEM comments to embedd your bundle in your AEM package:
<build>
<plugins>
<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>content-package-maven-plugin</artifactId>
<configuration>
<failOnMissingEmbed>true</failOnMissingEmbed>
<filterSource>src/main/META-INF/vault/filter.xml</filterSource>
<filters combine.self="override" />
<embeddeds>
<embedded>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.models.validation-impl</artifactId>
<target>/apps/example/install</target>
</embedded>
</embeddeds>
</configuration>
</plugin>
</plugins>
</build>
Also, dont forget to add /apps/example/install to your filter.xml.
More information on the content package plugin
You can put your lib into src/main/jcr_root/apps/your_app/libs/install folder(path depends on your project structure). Now it will be installed to AEM using maven.
To import necessary classes use provided scope, we have the following configuration for Jedis lib:
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.jedis</artifactId>
<version>2.7.3_1</version>
<scope>provided</scope>
</dependency>

Eclipse plugin with Maven dependencies for third party libraries

I am converting Subclipse to build with Eclipse Tycho and Maven.
Subclipse depends on a few third party JAR files that are not Eclipse plugins so do not exist in any p2 repository. Currently, I just include these in a lib folder within the plugin.
Since these JAR files do exist in Maven, I was hoping that by converting the plugins to build with Maven I could use Maven dependencies. IOW, the plugin would have a pom.xml where I used Maven dependencies to grab and include the third party jar's that have to be included in the plugin. Basically, it would just automate having to refresh what I include in the lib folder of the plugin.
Is this possible? I tried doing what I said above by when I build, I saw no sign that Maven/Tycho was trying to fetch the dependencies. I imagine it is because when the packaging is eclipse-plugin it looks solely at the Eclipse configuration files for the dependency information.
Thanks
To add plain (without OSGi metadata) jar files into your folder at biuild time, you can specify an <execution> of the maven-dependency-plugin to fetch them. However it will require to update your MANIFEST.MF Bundle-Classpath directive whenever a version changes.
It's usually better to hunt for OSGi-able jars or to make an extra effort to package existing libs as OSGi bundles/p2 artifacts like Eclipse Orbit or JBoss Tools Locus do.
Did you try doing the following after adding the dependencies to the pom.xml file?
Project->Clean
Right click on project: Maven->Update dependencies
Right click on project: Maven->Update project configuration
Just adding the plugin to pom dependencies and including the entry <pomDependencies>consider</pomDependencies> in the configuration of target-platform-configuration makes it work.
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho.version}</version>
<configuration>
<!-- The configuration to make tycho consider the maven dependencies -->
<pomDependencies>consider</pomDependencies>
<!-- other configurations -->
</configuartion>
</plugin>
<!-- other plugins-->
</plugins>
<dependencies>
<!-- An example third-party bundle (plugin) present in maven repository-->
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.gogo.shell</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
Reference link here.

NetBeans adding external library Vaadin Framework

How can I add external library to Vaadin framework using NetBeans?
I can't find libraries folder there. Additionally I want use pi4j library.
I haven't seen it there like in normal Java Application Libraries folder.
Looks like you are using Maven. In that case you have to edit your pom.xml file (you can find it in the Project Files folder in NetBeans).
Google for the Maven coordinates for the library you want to include and add the corresponding dependency section in the dependencies section. For example, to add Log4j, you must add the following in your pom.xml:
...
<dependencies>
...
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.5</version>
</dependency>
...
</dependencies>
...
Alternatively, you can right click the Dependencies folder in NetBeans, select Add Dependency..., and add the corresponding Maven coordinates or search for the dependency (keep in mind the Maven Index may be updated the first time you search for a dependency, process that might take some seconds/minutes).

Replace class files before maven assembly

I'm facing a very unique situation and need some advice:
I'm working on a project which depends on an other project from my same company and now I need to apply some modifications to the dependency.
The problem which I have is that the source code from the dependency has been lost, so the only thing I have is a maven dependency in the repository, with the corresponding jar file.
On top of that, some of the classes in the Jar file where created using JiBX parser, mapping some XSD files which I neither have, and the resulting classes are synthetic and I found no decompiler able to handle them properly.
The only good thing of all of that is that the class which I need to change can be properly decompiled, so went for the following:
I decompiled the whole jar file and ended up with some classes (the
JiBx ones) with empty or wrongly implemented methods.
I commented out the body of the wrong methods to have stub objects, applied the required changes to the right classes and recompiled.
I took the old Jar file, opened it and manually replaced the old class with the new one.
And the resulting Jar worked as expected.
Now my question is: Can I do all of that using Maven?
The idea would be to put the JiBX class files as resources, and keep the stub equivalents as source files and then let maven:
Compile everything as usual, putting all the compiled class files
into target folder
Remove stub class files from target folder and replace them with the old precompiled class files
package the jar.
Which approach would you recommend?
UPDATE
I give some more details about the dependency project structure:
All classes are inside the same package:
my.project.domain.JiBX__c_GeneratedObfuscatedClass1.java
my.project.domain.JiBX__c_GeneratedObfuscatedClass2.java
my.project.domain.JiBX__c_GeneratedObfuscatedClass3.java
my.project.domain.CustomizableClass1.java
my.project.domain.CustomizableClass2.java
my.project.domain.CustomizableClass3.java
JiBX classes are not imported properly as dependency and if I try to put any of the CustmizableClasses into the project source and let the JiBX ones be in a dependency, the compiler reports missing methods.
I also tried using the Shade Plugin as suggested, but since I need to include the JiBX classes into my source path, I will end up having to include into package JiBX classes from jar dependency and compiled CustomizableClasses, but skipping CustomizableClasses from jar dep and compiled JiBX classes.
I looks like it can work, but I admit that I still didn't find the way of doing it.
Any clues will be very welcomed.
UPDATE 2 (RESOLUTION)
I explain here how I finally managed this using the shade plugin as suggested, just in case someone else needs to do the same:
I finally created a project with the decompiled classes inside the same package, and left the methods which didn't want to be decompiled commented out.
In the pom.xml I added the following:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>${project.groupId}:${project.artifactId}</include>
<include>TheDamnedProject:WithoutSources</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>TheDamnedProject:WithoutSources</artifact>
<includes>
<!-- These classes will be taken directly from dependency JAR -->
<include>my/package/ClassWhichCouldNotBeDecompiled1.class</include>
<include>my/package/ClassWhichCouldNotBeDecompiled2.class</include>
<include>my/package/ClassWhichCouldNotBeDecompiled3.class</include>
<include>my/package/ClassWhichCouldNotBeDecompiled4.class</include>
</includes>
</filter>
<filter>
<artifact>${project.groupId}:${project.artifactId}</artifact>
<excludes>
<!-- These classes will be overridden by the ones inside the JAR -->
<exclude>my/package/ClassWhichCouldNotBeDecompiled1.class</exclude>
<exclude>my/package/ClassWhichCouldNotBeDecompiled2.class</exclude>
<exclude>my/package/ClassWhichCouldNotBeDecompiled3.class</exclude>
<exclude>my/package/ClassWhichCouldNotBeDecompiled4.class</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
thanks!
Carles
Here's how I would do that:
Create a new Maven project for this Jar file, with packaging type jar
Include the original Jar file as a dependency
Add the one decompiled .java file in the src folder
This should get you to a point where the .java file can be compiled, since the other classes from the jar file are available.
You now have two Jar files: one original, and one that should just contain the single recompiled and changed class.
Adding both to your application class path might work, but will depend on the order on the classpath.
If you want to end up with one jar file, I recommend to take a look at the Maven Shade Plugin (http://maven.apache.org/plugins/maven-shade-plugin/), which will allow you to create a new Jar file with contents from multiple sources. It will allow you to filter what goes into the new Jar file.
The Maven Shade plugin allows you to specify which classes from each artifact are included. It uses wildcards and include/exclude tags for this, as described here: http://maven.apache.org/plugins/maven-shade-plugin/examples/includes-excludes.html
Once that Jar file is created, I would release it using the Maven Release plugin, and then include that artifact downstream. This will allow you to only update the patched Jar when it is really required, it probably doesn't have to be on every build. But that depends on your usage pattern.
For the version number of the new Jar file, I recommend to use a variation of the original one. Use the same groupId and artifactId, then modify the version number. If the original has 1.0.2, your new, patched file should be released as 1.0.2-1, to indicate that it's based on the 1.0.2 sources. If you need to make an additional change, release that as 1.0.2-2 and so on. This will make it easy to understand which version your patches are based on, and the incrementing patch number will give you a means to distinguis the releases.

GWT. Maven. GWT Module <module_name> not found in project sources or resources

I have a maven multi-module project. One of this modules (compiled as .jar) contains only domain objects, which will be used at client and server sides (I add this .jar as dependency to other my modules).
I know that GWT module, where will be used objects from shared .jar, must also have source files for successful compilation. So I tried to add to my pom.xml both:
<resources>
<resource>
<directory>src/main/java/<path></directory>
<includes>
<include>**/*.java</include>
<include>**/*.gwt.xml</include>
</includes>
</resource>
</resources>
and
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<versionRange>[${gwt.version}]</versionRange>
<goals>
<goal>resources</goal>
</goals>
<plugin>
But resulting .jar don't contain GWT module source (i.e gwt.xml). All sources of domain classes are added as well (at root directory of .jar), but ModuleName.gwt.xml not.
Where is problem? Thanks.
If your .gwt.xml file is in src/main/resources/ then it won't get copied if you specify src/main/java/ as the resource path...
You should probably omit the <resource> section and let the GWT plugin include the source in the jar or at least have two sections, one for the .gwt.xml file (src/main/resources or where you put it) and one for the source code (as you have it now).
Cheers,
I was troubleshooting this error today so I'm just posting my fix:
Multi-module gwt project being build with the maven gwt plugin needs an entry in the pom.xml like:
<modules>
<module>../theothermodule</module>
</modules>
In order to compile.
This error have multiple explanations. Check list:
if you are referencing a gwt module you need to point to the *.gwt.xml file in dot notation without the file extension. E.g. com.example.ThirdParty refers to com/example/ThirdParty.gwt.xml module
to import the 3rd party module, add <inherits name="com.example.ThirdParty" /> to your *.gwt.xml file
the ThirdParty.gwt.xml should contain one or more source elements pointing to translatable code. E.g. <source path='shared' />.
all translatable code in ThirdParty.jar needs to include plaintext *.java sources. E.g. com/example/shared/Widget.class and com/example/shared/Widget.java are both present
the ThirdParty.jar is on your classpath
Notes:
if the ThirdParty gwt module does not have entry point it does not need to be compiled with gwt compiler
the gwt compiler does not require extra configuration to include the ThirdParty module as long as its jar is on classpath and your *.gwt.xml inherits ThirdParty.gwt.xml; the same applies to the gwt maven plugin