I'm trying to import the following library: https://github.com/twitter/hbc
Which says I must import the folllowing in my pom.xml file:
<dependencies>
<dependency>
<groupId>com.twitter</groupId>
<artifactId>hbc-core</artifactId> <!-- or hbc-twitter4j -->
<version>2.2.0</version> <!-- or whatever the latest version is -->
</dependency>
</dependencies>
I'm totally new to Maven. I'm using Eclipse, which already had Maven installed. I created a new Maven project, and then created a new .xml file named pom.xml with the above. However, nothing seems to have been imported; library stuff isn't working in the project. For example, the option to import "httpHosts" does not exist.
How am I meant to actually import this?
As Jorge Campos, suggests you need to do some reading on basic Maven. principles. So please read this in order to get started.
In order to help you a bit this is how your pom.xml should look like:
<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>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Maven Quick Start Archetype</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>com.twitter</groupId>
<artifactId>hbc-core</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
You need to take care the groupid and artifact id sections, but I hope you will find out, if you spend some time and read about Maven :)
Related
I am trying to implement a custom processors in NiFi with mvn archetype:generate and I would like to import a class from org.apache.nifi.processors (in particular standard.util.*), but it gives me error (cannot be resolved).
My current workaround is to copy the classes that I want in my package, but what should I do to make it visible directly from the nifi package? Should I modify the pom.xml ?
Thanks in advance
The content of the pom.xml is the one generated by the mvn archetype:generate command:
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example.nifi</groupId>
<artifactId>stream-processorr</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>nifi-StreamProcessor-processors</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-utils</artifactId>
<version>1.10.0</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-mock</artifactId>
<version>1.10.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Presumably, and from a pure Maven standpoint, you would likely need to depend on nifi-standard-processors to get that package to resolve. That is where the majority of classes in that package exist. Of course, this depends on the specific class(es) of interest.
As a bit of context from the NiFi project perspective, the package listed is mostly tailored toward helper classes for the processors in the standard bundle. It is typically not a good practice to depend on these in other NAR bundles. However, if you share use case it may make sense to extract these to a separate module for wider use.
I created a custom my-commons library with maven. The commons pom contains eg the following dependency:
<?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">
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath/>
</parent>
<groupId>de.mydomain</groupId>
<artifactId>my-commons</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<properties>
<!-- workaround for http://jira.codehaus.org/browse/MASSEMBLY-603-->
<maven.build.timestamp>${maven.build.timestamp}</maven.build.timestamp>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
I installed the custom library into my local repository.
In a different project, I reuse the library. It resolves correctly, so it exists in the repo:
<project ...>
<groupId>de.mydomain</groupId>
<artifactId>my-core</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>my.domain</groupId>
<artifactId>my-commons</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>
Now in this project I'd like to use a class org.springframework.web.bind.annotation.ResponseBody.
Problem: the class is not in classpath. So maven complains [ERROR] cannot find symbol.
But why?? I'd expect the dependency being inherited!
Sidenote: I'm using Intellij IDEA if that matters. The same problem applies to all "inherited" libraries. The spring-web lib is just an example.
Please check if .m2 folder contains the jar you want to use or not. You can use mvn install command in commons project to generate the jar. Also you need to add commons project in your project pom that you are running.
You need to create the artifact for your commons project, through its pom.xml.
Like in my below example i created a separate project where i am using the AWS and some other dependency and then final jar, which i am using in other project :-
My AWS-client pom.xml looks like below :-
<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>com.kaamkaj</groupId>
<artifactId>aws-clients</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>aws-clients</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<aws.sdk.version>1.11.104</aws.sdk.version>
</properties>
<dependencies>
<!--AWS dependency-->
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-dynamodb -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
<version>${aws.sdk.version}</version>
</dependency>
<dependency>
<groupId>com.mercadopago</groupId>
<artifactId>sdk</artifactId>
<version>0.3.4</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>mercadopago</id>
<url>https://github.com/mercadopago/sdk-java/raw/master/releases</url>
</repository>
</repositories>
</project>
Also, run mvn clean install on the commons pom, in your case.
And then in all other project where i need to include the aws-client , i use the artifact-id of above project, like below :-
<dependency>
<groupId>com.kaamkaj</groupId>
<artifactId>aws-clients</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
Let me know if you have any questions:
Found it: removing the <maven.build.timestamp>... <property> solved the problem. I don't know why it prevented the inheritance to work properly, especially as I didn't get any errors.
I want to read protobuffer GTFS-realtime inputs using java, and this package
https://github.com/google/gtfs-realtime-bindings/blob/master/java/README.md
I created first a java project using Maven:
mvn archetype:generate -DgroupId=com.me.app -DartifactId=myproject -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
cd myproject
mvn package
...went fine.
According to the documentation of the GTFS-realtime binding package, the following should be included in the pom.xml:
<dependency>
<groupId>com.google.transit</groupId>
<artifactId>gtfs-realtime-bindings</artifactId>
<version>0.0.4</version>
</dependency>
In order to avoid duplicates (which made the compilation crashed) I removed the following lines:
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
so I got this pom.xml:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.me.app</groupId>
<artifactId>myproject</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>myproject</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>com.google.transit</groupId>
<artifactId>gtfs-realtime-bindings</artifactId>
<version>0.0.4</version>
</dependency>
</dependencies>
</project>
The compilation then crashed. I am a newcomer in java and may have missed a point about how to include an existing package into a new project. Does anyone see what I am doing wrong?
I am trying to have a seperate persistence.xml for my tests, but it is not working. I have already looked at this post :
JPA using alternative "persistence.xml"
The post states that I just need to have a persistence.xml file in my src/test/resources/META-INF directory. This persistence file contains my JPA configuration for the test phase (In my case just the in-memory database).
However when I run Maven-->Test ALWAYS picks up the main/src persistence.xml file.
Do I need to configure something extra in my POM? My POM feels pretty sparse :
<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>org.glassfish.embedded.samples.ejbcontainer</groupId>
<artifactId>ejbcontainer</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>ejbcontainer</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.1.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Here's what it looks like in netbeans
Test phase always goes to the main persistence.xml :(
I purchased the 'Apache Maven 3 Cookbook' and I'm trying to learn on adding dependencies to my maven projects.
my main project pom.xml:
<?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>
<groupId>net.srirangan.packt.maven</groupId>
<artifactId>TestModularApp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>TestModularApp</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.2</version>
</dependency>
</dependencies>
<modules>
<module>ChildProject</module>
<module>MyWebApp</module>
</modules>
</project>
as you can see here the packaging in this project is set to "pom" because this is the parent project.. ( that's all i know :) )
and then I created a subproject with the following pom.xml:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.srirangan.packt.maven</groupId>
<artifactId>TestModularApp</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.xpogames.childproject</groupId>
<artifactId>ChildProject</artifactId>
<version>1.0-SNAPSHOT</version>
<name>ChildProject</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
</project>
as you can see here i did not add a version property to the mysql-connect-java dependency because it supposed to inherit the version from the parent project. but for some reason, it doesn't.
when I run mvn compile on that project i get an error that the dependencies.dependency.version property is missing.
any ideas what i'm doing wrong? how can I resolve the issue that i won't need to specify versions in sub-projects too ?
thanks!
update
after watching Peter Lawrey's answer and watching the example on the url he provided
I noticed that my main XML is missing the property <dependencyManagement> around the <dependencies>. once I added that property then I didn't need to provide a version number in the sub-project.
Peter answer shows another method to achieve this goal.
thanks for everything!
Kfir
You inherit versions from the dependencies in the dependencyManagement section of your parent pom(s) and selectively include these in child poms.
In your case you don't need to mention the dependency again as it already included from the parent. (As it is for JUnit)
BTW: I use JUnit 4.10 which I haven't found any backward compatibility problems with.