I would like to use the Java AWS SDK only for S3 at the moment.
So, instead of importing the entire AWS SDK jar file I wanted to only import the necessary packages for accessing my S3 bucket into my web application (IDE: Netbeans).
To do this, I read that I should use Maven to build the jar I need.
I have tried two approaches but can't seem to also include all of the aws-java-sdk-s3 dependencies in the jar that I am building.
First approach
1) I download the zipped aws-sdk-java folder from https://github.com/aws/aws-sdk-java
2) I unzip to a local folder.
3) I navigate to the aws-java-sdk-s3 (ie: where the pom is located) folder in my console, then type "mvn clean install".
While this builds a jar file (located in aws-java-sdk-s3/target), the jar does not contain the dependencies specified in the POM file (eg: it does not include the BasicAWSCredentials class in the core package which I need).
Second Approach
Change the POM file located in the aws-java-sdk-master folder so that it imports the BOM and specifying my requirement (S3) by adding:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bom</artifactId>
<version>1.10.67</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
</dependency>
</dependencies>
and removing all other dependencies listed in the POM (eg: junit).
This approach fails while building the DynamoDB package, which I don't even need it to be building (I want to specify that it only needs S3).
Any suggestions as to what I'm doing wrong?
Perhaps the main issue here is that I'm new to Maven.
Thank you
update your pom.xml properly likewise,
<dependencies>
....
<!-- AWS dependencies -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.10.43</version>
</dependency>
....
</dependencies>
You can download the Jar that you are interested directly from maven :
http://central.maven.org/maven2/com/amazonaws/aws-java-sdk-s3/1.10.66/aws-java-sdk-s3-1.10.66.jar
update the URL with the version of the sdk you want to use and you can just import the jar in your project, no need to rebuild it
It worked fine for me using Gradle. Here is the Gradle build file I used as advised by the API doc.
group 'aws.test'
version '1.0'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:1.0.3.RELEASE"
}
}
apply plugin: "io.spring.dependency-management"
dependencyManagement {
imports {
mavenBom 'software.amazon.awssdk:bom:2.0.0-preview-12'
}
}
dependencies {
compile 'software.amazon.awssdk:s3'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
Related
I want to exclude the geronimo-javamail_1.4_spec jar from my project, I am using maven to build the project, I saw this article and I added the exclusion part to my pom.xml but somehow after I build my project I see the geronimo-javamail_1.4_spec-1.7.1.jar in my war file's WEB-INF\lib.
Please tell me how can I exclude this jar from my .war.
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-javamail_1.4_spec</artifactId>
<version>1.4</version>
<scope>provided</scope>
</dependency>
This way the maven will add them to the compilation classpath, but will not package them
I have the following scenario:
I want to use a project of mine (hosted on bintray.com) in another project of mine.
I set up a maven repository, uploaded artifacts and pom files and then was able to utilize the jar file(s) uploaded to the bintray maven repo just fine, with the following build.gradle file:
apply plugin: 'java'
apply plugin: 'application'
mainClassName = 'randers.test.usageTest.UsageTest'
repositories {
maven { url 'http://dl.bintray.com/randers00/NotEnoughVocab' }
jcenter()
}
dependencies {
compile(group: 'randers.notenoughvocab.core', name: 'notenoughvocab-core', version: '0.0.1', ext: 'jar')
}
jar {
manifest {
attributes "Main-Class": mainClassName
}
}
This build file successfully equips the project with my core library and even makes sources, etc. available in the IDE (IntelliJ IDEA I use)
The problem is: The core itself uses libraries, which are not gotten by gradle.
This is the pom file that is on bintray:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>randers.notenoughvocab.core</groupId>
<artifactId>notenoughvocab-core</artifactId>
<version>0.0.1</version>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.7</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom2</artifactId>
<version>2.0.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>1.10</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
<licenses>
<license>
<name>GNU General Public License, Version 3.0</name>
<url>http://www.gnu.org/licenses/gpl.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<contributors>
<contributor>
<name>Ruben Anders</name>
<email>RAnders00#users.noreply.github.com</email>
<url>https://github.com/RAnders00</url>
</contributor>
</contributors>
</project>
I looked at other projects on bintray and their pom files look similar.
Declaring the dependecy the traditional and simple way works fine:
compile 'randers.notenoughvocab.core:notenoughvocab-core:0.0.1'
It doesn't work when you specify ext: 'jar', because that is used to download a single artifact. From the user guide:
Artifact only notation
As said above, if no module descriptor file can be found, Gradle by default downloads a jar with the name of the module. But sometimes, even if the repository contains module descriptors, you want to download only the artifact jar, without the dependencies. [14] And sometimes you want to download a zip from a repository, that does not have module descriptors. Gradle provides an artifact only notation for those use cases - simply prefix the extension that you want to be downloaded with '#' sign:
Example 50.5. Artifact only notation
build.gradle
dependencies {
runtime "org.groovy:groovy:2.2.0#jar"
runtime group: 'org.groovy', name: 'groovy', version: '2.2.0', ext: 'jar'
}
I want to try this library in my android project. I am using Android Studio 0.4.6.
The README.markdown file tells me to insert this inside pom.xml:
<!-- in the 'repositories' section -->
<repository>
<id>keytwo.net</id>
<name>Keytwo.net Repository</name>
<url>http://audiobox.keytwo.net</url>
</repository>
<!-- in the 'dependencies' section -->
<dependency>
<groupId>io.socket</groupId>
<artifactId>socket.io-client</artifactId>
<version>0.2.1</version> <!-- the desidered version -->
</dependency>
The problem is that I do not have any pom.xml. I created one in my project root directory and synced gradle settings but it does nothing. Till now I only used already compiled .jar files or used the gradle compile function.
How can I use this library in my project?
Android Studio doesn't use Maven as its builder; it uses Gradle instead. Fortunately, Gradle can use Maven repositories to fetch dependencies, so it's a matter of taking that information that would go into the pom file and using it in Gradle format. These modifications go in the build.gradle file in your module's directory (not the build file in the project root directory).
First, set up the repository where it can find the dependency.
repositories {
maven { url 'http://audiobox.keytwo.net' }
}
and then add the dependency itself by adding this line to your dependencies block:
dependencies {
...
compile 'io.socket:socket.io-client:0.2.1'
}
Update:
From POM file:
compile '<groupId>:<artifactId>:<version>'
Syntax:
implementation 'groupId:artifactId:version'
If this is what you have to import in your Android Studio Project...
// Maven : Add these dependecies to your pom.xml (java6+)
// <dependency>
// <groupId>org.glassfish.jersey.core</groupId>
// <artifactId>jersey-client</artifactId>
// <version>2.8</version>
// </dependency>
// <dependency>
// <groupId>org.glassfish.jersey.media</groupId>
// <artifactId>jersey-media-json-jackson</artifactId>
// <version>2.8</version>
// </dependency>
then it translates to this...
implementation 'org.glassfish.jersey.core:jersey-client:2.8'
implementation 'org.glassfish.jersey.media:jersey-media-json-jackson:2.8'
I have set-up a mave project in Eclipse, I added the project dependencies to the pom.xml which was created by eclipse automatically.
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId> org.springframework.core </artifactId>
<version>3.0.6.RELEASE </version>
</dependency>
</dependencies>
Now when I import the Jdbc template in one of the classes, I get the import can't be resolved error
import org.springframework.jdbc.core.JdbcTemplate;
Are dependencies added during compilation time, or execution time only? if they are only available at execution time, then how can I compile the code?
One way to verify if maven dependencies are added to your project or not in eclipse is under the project ->libraries->Maven Dependencies, all the dependency you have added in your pom.xml should be present
In your case spring-jdbc{version}.jar should there else try to update the project, while updating the project by default all the dependencies would be downloaded to your home directory/.m2/repository. If you find your dependencies are not present check your proxy settings. http://maven.apache.org/guides/mini/guide-proxies.html
The simple problem you have is that the class org.springframework.jdbc.core.JdbcTemplate is contained in the following artifact:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>3.0.6.RELEASE</version>
</dependency>
but not in the spring-core nor as transitive dep. Apart from that you should first check to build the project on command line with Maven and afterward import it into Eclipse.
I am doing a project that has dependencies on some classes from the mahout and hadoop core jars. I was using javac with the classpath option to include them before, but someone suggested to me that I should use maven to build my project instead. However, I am not sure how to add the dependencies to these jar files which are located in my /usr/local directory.
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>0.20.205.0</version> <!-- or whatever version -->
</dependency>
<dependency>
<groupId>org.apache.mahout</groupId>
<artifactId>mahout-core</artifactId>
<version>0.5</version>
</dependency>
Add this to your pom:
<dependencies>
<dependency>
<groupId>org.apache.mahout</groupId>
<artifactId>mahout-core</artifactId>
<version>0.5</version>
</dependency>
<dependency>
<groupId>some.group</groupId>
<artifactId>hadoop</artifactId>
<version>some.version</version>
</dependency>
</dependencies>
If you have a copy of the jar to be used for say the hadoop example above, execute this command:
mvn install:install-file -Dfile=/some/path/my-hadoop.jar -DgroupId=some.group -DartifactId=hadoop -Dversion=some.version -Dpackaging=jar
Have a look at the maven documentation, especially the part on dependency management. If you want to use Maven you should get to know the basics (one of which is dependency management).
Basially you define your project's dependencies in the <dependencies> section of your pom. Look up maven central (the most common online repository) for the dependencies you want or search for other online repositories that might contain them.
If you can't find them, add the dependencies you want anyways (think of a sensible group id, artifact id and version) and try to compile. Maven will complain about the dependencies missing and provide a basic command to put those dependencies into the local repository. Copy those commands and fill in the appropriate path to the jar file and maven will deploy that dependency in your local repository.
Note that you should first look for the dependencies in an online repository since otherwise you'd have to manually deploy each new version in your local repo.