POM dependency for AEM 6.2 implementation of Amazon S3 Bucket - maven

I am trying to implement Amazon S3 in Adobe Experience Manager 6.2 and using maven 3.3.9.
When i add dependency:
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.aws-java-sdk</artifactId>
<version>1.11.18_1</version>
</dependency>
It is not building project and throwing maven-scr-plugin error:
SCR Descriptor parsing had failures.
[ERROR] Failed to execute goal org.apache.felix:maven-scr-plugin:1.20.0:scr (generate-scr-scrdescriptor) on project aviva-investors-bundle: SCR Descriptor parsing had failures (see log) -> [Help 1]
If I try to add only JAR
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.2</version>
</dependency>
Build is successful. But I am not able to resolve my project bundle. Bundle is in Installed state. Imported Packages shows: Cannot resolve dependency:
com.amazonaws.services.s3,version=[1.11,2) -- Cannot be resolved
Not sure what to add in dependency to make my imports work.
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.ClientConfiguration;
etc.
Any help is much needed.

When you include a dependency in your maven build it is not push to the osgi container. It would be used only to compile your site bundle.
Heres two options what do can do.
1. Upload the s3 jar as an osgi bundle
2. Create another maven task to deploy third party dependencies to your osgi container. See http://www.cqblueprints.com/tipsandtricks/build-and-deploy-osgi/deploy-third-party-libs.html

Related

Import of jar in IntelliJ is successful and imports are resolved but mvn clean install and package fails

Some classes in my spring boot maven project were showing errors on some imports , so I had to add an external jar dependency in my IntellIJ (Community) . After adding it all the errors are gone , and i can see the jar is listed inside external libraries in IntelliJ . I try to run the spring boot project , works fine . But when i try to do a mvn clean install or mvn clean on the project directory , it fails showing import errors on the same classes for which purpose i had added the jar . I tried re-building the project , invalidating caches , but issue still remains the same . I am not able to understand if adding the JAR has resolved the import errors , and project also starts , why mvn phases are having failure as if no jar is added ?
In a Maven based project you must manage project build configuration, including dependency management in Maven pom.xml build files, not adding it via IDE interface. So you need to add the required dependencies using the Maven's dependency management mechanism, simply inside Maven dependencies section. e.g.
<dependencies>
...
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.3.4.RELEASE</version>
</dependency>
...
</dependencies>
And by the way the IDE helps you with that.

How to add aem Uber jar dependency in maven build

I have used the maven archetype10 as shown below and created the project structure and everything was fine.
mvn archetype:generate -DarchetypeGroupId=com.adobe.granite.archetypes -DarchetypeArtifactId=aem-project-archetype -DarchetypeVersion=10 -DarchetypeRepository=https://repo.adobe.com/nexus/content/groups/public/
Now i wanted to add the aem uber-jar dependency and added the below dependency tags in the project pom.xml and in core module pom.xml respectively and also my repository tags are same as https://repo.adobe.com/
<dependency>
<groupId>com.adobe.aem</groupId>
<artifactId>uber-jar</artifactId>
<version>6.2.0</version>
<scope>provided</scope>
</dependency>
after adding the above dependency tag when i compile it is giving me the below error.
[ERROR] Failed to execute goal on project aemexample.core: Could not
resolve dependencies for project
com.krishh.example:aemexample.core:bundle:0.1: Could not transfer
artifact com.adobe.aem:uber-jar:jar:6.2.0 from/to
adobe-public-releases
(http://repo.adobe.com/nexus/content/groups/public): hostname in
certificate didn't match: <repo.adobe.com> != <devedge.day.com> OR
<devedge.day.com> -> [Help 1]
Is there anything am missing to add extra dependencies to compile and run this successfully.
You seem to be missing a classifier in your dependency. Try adding the one for AEM APIs, as suggested in the documentation. This should help Maven locate the necessary JAR in the repository:
<dependency>
<groupId>com.adobe.aem</groupId>
<artifactId>uber-jar</artifactId>
<version>6.2.0</version>
<classifier>apis</classifier>
<scope>provided</scope>
</dependency>
If that doesn't help, you should also look at the certificate warning. Check out the answers to this question for more information on the subject.
TL;DR - possible causes could be:
an old Maven version using an HTTP library that is not compliant with the certificate being used by the repository - try upgrading Maven
erroneous certificate used by the server
potential network configuration issues between you and the repository
an actual attempt at getting you to download a malicious file by a party pretending to be the Nexus

Maven not importing External Library into project after adding to .pom file in Intellij

I'm having trouble correctly importing a library into a project that I'm running. I have added the library as a dependency in the .pom, refreshed the pom, run mvn clean install, and I have set auto-import up so that the project gets updated correctly, but the project does not get added as an External Library, and I can't use it in my project. I get no errors. What am I doing wrong?
Here is the relevant part of my pom
..properties
<crowd.version>2.5.0</crowd.version>
.. end properties
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.atlassian.crowd</groupId>
<artifactId>crowd-integration-springsecurity</artifactId>
<version>${crowd.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</dependencyManagement>
Here is the question I was following to debug my error:
Import Maven dependencies in IntelliJ IDEA
I think you missed the point of dependency management; read more in official docs. This is a feature that you can centralize common dependency information that is then shared been different projects. All by itself, this definioition will not import the dependency.
What you probably want is just a plain dependency: drop the dependencyManagement tags, and move you dependency into the correct block in the pom.

Failed to read artifact in my case

I am using MacBook. I have installed Apache Maven 3.1.1 .
Under my maven local repository path, I see that there is already installed the artifact of my base project:
~/.m2/repository/com/my/base/project/MyBase/1.0/MyBase-1.0.jar
In another project(feature-project)'s pom.xml, I added my base project as a dependency:
<dependency>
<groupId>com.my.base.project</groupId>
<artifactId>MyBase</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
But when I run maven clean install under feature-project, I got error:
Failed to collect dependencies at com.my.base.project:MyBase:jar:1.0: Failed to read artifact descriptor for com.my.base.project:MyBase:jar:1.0:
WhY? What did I do wrong?

Errors using maven-bundle-plugin Embed-Dependency

I have a Maven project that's building fine, and I'm attempting to add a reference to twitter4j.
So I add this to the pom:
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>[2.2,)</version>
<type>jar</type>
<optional>false</optional>
<scope>compile</scope>
</dependency>
When I build (mvn clean install) I get:
[ERROR] Error building bundle net.stevex.tweetfetcher:tweetfetcher-bundle:bundle:1.0-SNAPSHOT : Unresolved references to [twitter4j] by class(es) on the Bundle-Classpath[Jar:dot]: [net/stevex/tweetfetcher/impl/TweetFetcherImpl.class]
This makes sense .. the twitter4j package isn't embedded in the bundle. So I add an Embed-Dependency to the maven-bundle-plugin's instructions:
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
And now when I build, I get:
[ERROR] Error building bundle net.stevex.tweetfetcher:tweetfetcher-bundle:bundle:1.0-SNAPSHOT : Unresolved references to [dalvik.system, javax.crypto, javax.crypto.spec, javax.management, javax.management.openmbean, org.apache.commons.logging, org.apache.log4j, org.slf4j.impl, twitter4j.internal.http.alternative] by class(es) on the Bundle-Classpath[Jar:dot, Jar:twitter4j-core-2.2.3.jar]: [twitter4j/internal/logging/CommonsLoggingLogger.class, twitter4j/internal/logging/Log4JLoggerFactory.class, twitter4j/auth/OAuthToken.class, twitter4j/internal/http/HttpClientFactory.class, twitter4j/auth/OAuthAuthorization.class, twitter4j/internal/logging/Log4JLogger.class, twitter4j/conf/ConfigurationBase.class, twitter4j/TwitterAPIMonitor.class, twitter4j/internal/logging/CommonsLoggingLoggerFactory.class, twitter4j/management/APIStatisticsOpenMBean.class, twitter4j/internal/logging/Logger.class]
I don't understand why the twitter4j classes are missing, and I don't understand the references to dalvik.system, javax.crypto, etc. What's wrong here?
The problem is that the twitter4j project requires all of the packages listed in the error list. When you use it does not include all transitive dependencies. There is an Embed Transitive instruction for the maven-bundle-plugin that will embed all transitive dependencies
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
However, this kind of defeats the purpose of OSGi. This leaves you with two options that I know of:
Search for the packages in the second in the SpringSource EBR. You simply enter the package name in the search box, and the results will include the xml for your POM file. The SpringSource bundles will include references to other bundles in the EBR, eliminating the problem of transitive dependencies.
Use the bundle-all goal of the maven-bundle-plugin. This goal will run the maven bundle plugin for every dependency of your project, and place the resulting bundles into your target directory. You could then install these bundles into your local repository.
I would recommend using option 1 for as many of the bundles as you can find, then defaulting to option 2 when SpringSource doesn't have them.

Resources