Drunk Knight
Drunk Knight

Reputation: 141

Migrate dependencies from local to Maven

I have a Java code in which I added JARs using Maven and also from the local system. Now as I am running it on a different system, the local JARs are missing. How can I add everything to Maven and remove the local class paths?

<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.memeanalytics</groupId>
<artifactId>kafka-consumer-storm</artifactId>
<packaging>jar</packaging>
<version>1.1.0</version>
<name>HibernateExample</name>
<url>http://maven.apache.org</url>


<repositories>

    <repository>
        <id>github-releases</id>
        <url>http://oss.sonatype.org/content/repositories/github-releases/</url>
    </repository>

    <repository>
        <id>clojars</id>
        <url>http://clojars.org/repo</url>
    </repository>

    <repository>
        <id>cloudera-repo-releases</id>
        <url>https://repository.cloudera.com/artifactory/repo/</url>
    </repository>

</repositories>

<dependencies>

    <!-- <dependency> <groupId>net.wurstmeister.storm</groupId> <artifactId>storm-kafka-0.8-plus</artifactId> 
        <version>0.4.0</version> </dependency> -->

    <dependency>
        <groupId>org.xerial.snappy</groupId>
        <artifactId>snappy-java</artifactId>
        <version>1.1.1.3</version> <!-- was 1.1.0-M3 -->
    </dependency>

    <dependency>
        <groupId>org.apache.storm</groupId>
        <artifactId>storm-kafka</artifactId>
        <version>0.9.3</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>1.6</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>com.sd.dwh.kafka.storm.Invoker</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Upvotes: 1

Views: 747

Answers (3)

Bevor
Bevor

Reputation: 8605

I don't know what you mean by "local JARs". If you mean a mixture of Maven dependencies and manually added JARs into the IDE, then this is a very bad idea. Either you use Maven or not. If you use Maven, everything should be a Maven dependency. In future, you need every manually added jars to be managed by Maven by adding it into the local repository: https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html After you added it into the local repository, you can add it as dependency in your pom.xml as you do with all other dependencies from Maven central.

If you share the project with other people or other computers, you run into the problem you were talking about. In a team (or inside a local network), you usually run a repository manager like Nexus. When there are new dependencies which were manually added (and installed to the local repository) you usually deploy it to Nexus which acts as a proxy between your local network and Maven central. Then, everybody in your team or local network can find these dependencies.

Upvotes: 1

W-S
W-S

Reputation: 524

You can setup a maven repository manager like nexus for your local development which can proxy the maven central repository and you can deploy your own library in it. And when you need to develop on another environment, you can get the dependencies from your local maven repository.

Upvotes: 0

ernest_k
ernest_k

Reputation: 45319

The easiest attempt to fix is to:
1. Take note of all the jars/dependencies that you added manually to the classpath (using your IDE or otherwise)
2. Use maven central search facilities (http://search.maven.org/) to locate those dependencies (one by one, of course) in public repositories. The results you find using online maven searches will include a snippet of the pom for those dependencies (<dependency>...</dependency>). Copy and paste them into your existing pom.xml's dependencies section. 3. Remove your IDE-based classpath entries.

Of course, this can only work if those dependencies are in public repositories.

Upvotes: 0

Related Questions