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'
Related
I have created a maven archetype from a project, in this project's pom file, there's an dependency demo-admin
<dependency>
<groupId>com.demo</groupId>
<artifactId>demo-admin</artifactId>
<version>${demo-admin.version}</version>
</dependency>
this dependency is installed in my local repository.
But when I checked the generated archetype files, the pom.xml file in the archetype-resources folder, the dependency looks as below
<dependency>
<groupId>${groupId}</groupId>
<artifactId>${rootArtifactId}-admin</artifactId>
<version>${version}</version>
</dependency>
so every times I create a new project from the archetype, the maven coordinates of this denpendency will change.
Anybody has the same issue?
EDIT:
This issue could be reproduced as below steps:
create a project which GAV as below
<groupId>com.demo</groupId>
<artifactId>abc-admin</artifactId>
<version>1.0.0</version>
create a project which GAV as below
<groupId>com.demo</groupId>
<artifactId>abc</artifactId>
<version>1.0.0</version>
the second project contains a dependency
<dependency>
<groupId>com.demo</groupId>
<artifactId>demo-admin</artifactId>
<version>1.0.0</version>
</dependency>
create an archetype from the second project using the command below
a. cd abc
b. mvn clean
c. mvn archetype:create-from-project
go the "abc/target/generated-sources/archetype/src/main/resources/archetype-resources" folder, you can see a pom file, in the pom file, the dependency looks as below
<dependency>
<groupId>${groupId}</groupId>
<artifactId>${rootArtifactId}-admin</artifactId>
<version>${version}</version>
</dependency>
so, if I create a new project based on the abc archetype, when I input different GAV, the dependency will also changed based on the input values
I guess this is the automatic replacement of your of the groupId and artifactId of your demo project by placeholders.
Either give you demo project some name that never appears anywhere else or edit the resulting archetype by replacing the placeholders with the correct values.
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'
}
I have a custom maven plugin. In order to retrieve project's dependencies I use jcabi-aether library. It works fine for getting the project-scope dependencies. But what I need is to resolve plugin-scope dependencies so the call will look like:
<plugin>
<groupId>com.maven</groupId>
<artifactId>some-maven-plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<configuration>
<some>${some}/path</some>
</configuration>
<dependencies>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.8.1</version>
<classifier>sources</classifier>
</dependency>
</dependencies>
</plugin>
...
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-aether</artifactId>
<version>0.10.1</version>
</dependency>
Does anybody has any idea?
Thank you
To retrieve plugin scope dependencies from the execute method of your custom Mojo, you need to loop over the elements of the build as following:
Build build = super.getProject().getBuild();
if (null != build) {
List<Plugin> plugins = build.getPlugins();
for (Plugin plugin : plugins) {
List<Dependency> dependencies = plugin.getDependencies();
// you can then use your custom code here or just collected them for later usage.
// An example of what you can get, below
for (Dependency dependency : dependencies) {
getLog().info(dependency.getGroupId());
getLog().info(dependency.getArtifactId());
getLog().info(dependency.getVersion());
getLog().info(dependency.getClassifier());
getLog().info(dependency.getScope());
// etc.
}
}
}
Once you have them, I believe you can then use the Aether API to get transitive dependencies as you already did for project dependencies.
I am trying to get used to Eclipse/Java but am more familiar with MS VisualStudio. Lets say I have Java Library (Project1) which has some dependencies on jar files via Properties->Java Build Path->Libraries (eg: AWS SDK, gson, swagger, etc). Now if I have Project2 and set a project dependency for Project2 to Project1 via Properties->Java Build Path->Project, I would hope that Project1 dependents would also be included for Project2. I dont see that happening or I am missing a step. I have been googling but I don't see any tutorial/documentation discussing 2 levels of dependents. I see that the Project1 jar is being referenced but what about the dependents for Project1? I am receiving an error such as:
The type XXXX cannot be resolved. It is indirectly referenced from
required .class files XXXX
I strongly suggest using Maven, which is a great and easy to use dependency manager.
Probably your eclipse already comes shipped with it, all you have to do is:
Do this for both projects:
Right click both projects, go to Configure -> Convert to Maven Project.
Create a group id,artirfact id and specify the version for your projects.
It will generate a pom.xml file in the root of your project.
Something like this:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
</dependencies>
</project>
You can add dependencies for your projects just by adding a dependency tag.
<dependency>
<groupId>yourGroup</groupId>
<artifactId>yourProject</artifactId>
<version>1.0.0</version>
</dependency>
After that just right click your projects go to
Run -> Run Configurations -> Maven Clean
Run -> Run Configurations -> Maven Install
and it will automatically download and install your dependencies for you.
You might want to have a look at Maven or a tool like this (Gradle, Ivy...) to handle your dependencies.
Relying on Eclipse for defining your build process (and dependencies) is a bad idea for long term projects.
This depends a little, on your project.
In case it is just a Java project, then it is better to use a build tool like Ant with Ivy, Maven or Gradle. As these contain the dependencies and other configuration details. Eclipse Mars (v4.5.1) comes with build in support for all these build tools.
In case it is an Eclipse Plug-in which you are developing, then you can configure it in Eclipse. And then store the configuration files, with the source code in the code repository.
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.