0
votes

I just downloaded a Spring tutorial off the internet and am trying to run it in my local workspace. To do it, I first tried to get all the dependant jars needed by the project. I tried maven build and it failed because dependant jar's were missing from my local repository and those jar's were also missing from the remote repository(the one which my project uses)

Initially, my settings.xml only has a reference to the remote repository url which is used across the organization by various projects. I cannot expect it to be uptodate with latest jars. Can I get the remote repository names of the various utility projects fore.g for Log4j, commons logging, spring jars etc. I can then put these repository urls in my setting.xml to solve my issue.

EDIT: I even tried "http://repo1.maven.org/maven2/" which I thought houses all the required latest jars but even this wont work.

Example..

Missing:

1) log4j:log4j:jar:1.2.13

Try downloading the file manually from the project website.

Then, install it using the command: mvn install:install-file -DgroupId=log4j -DartifactId=log4j \ -Dversion=1.2.13 -Dpackaging=jar -Dfile=/path/to/file

Path to dependency: 1) com.mkyong.core:Spring3Example:jar:1.0-SNAPSHOT 2) org.codehaus.castor:castor:jar:1.1.2.1 3) log4j:log4j:jar:1.2.13

2) xerces:xerces:jar:1.4.0

Try downloading the file manually from the project website.

Then, install it using the command: mvn install:install-file -DgroupId=xerces -DartifactId=xerces \ -Dversion=1.4.0 -Dpackaging=jar -Dfile=/path/to/file

Path to dependency: 1) com.mkyong.core:Spring3Example:jar:1.0-SNAPSHOT 2) org.codehaus.castor:castor:jar:1.1.2.1 3) xerces:xerces:jar:1.4.0

3) commons-lang:commons-lang:jar:2.5

Try downloading the file manually from the project website.

Then, install it using the command: mvn install:install-file -DgroupId=commons-lang -DartifactId=commons-lang \ -Dversion=2.5 -Dpackaging=jar -Dfile=/path/to/file

My 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.mkyong.core</groupId>
<artifactId>Spring3Example</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Spring3Example</name>
<url>http://maven.apache.org</url>

<properties>
    <spring.version>3.0.5.RELEASE</spring.version>
</properties>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.2</version>
        <scope>test</scope>
    </dependency>

    <!-- Spring 3 dependencies -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
    </dependency>


    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-oxm</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <!-- Uses Castor for XML -->
    <dependency>
        <groupId>org.codehaus.castor</groupId>
        <artifactId>castor</artifactId>
        <version>1.1.2.1</version>
    </dependency>

    <!-- Castor need this -->
    <dependency>
        <groupId>xerces</groupId>
        <artifactId>xercesImpl</artifactId>
        <version>2.8.1</version>
    </dependency>

</dependencies>

My setting .xml

<settings>
    <localRepository>
        C:\Repository
    </localRepository>

    <interactiveMode>true</interactiveMode>
    <offline>false</offline>

    <profiles>
            <profile>
                <id>R2</id>
                <activation>
                    <activeByDefault>true</activeByDefault>
                </activation>
                <repositories>


                    <repository>
                        <id>Log4j</id>
                        <url>http://central.maven.org/maven2</url>
                        <layout>default</layout>
                        <releases>
                            <enabled>true</enabled>
                            <updatePolicy>never</updatePolicy>
                            <checksumPolicy>warn</checksumPolicy>
                        </releases>
                        <snapshots>
                            <enabled>false</enabled>
                            <updatePolicy>never</updatePolicy>
                            <checksumPolicy>warn</checksumPolicy>
                        </snapshots>
                    </repository>                   

                </repositories>
                <pluginRepositories>
                    <pluginRepository>
                        <id>Artifact_Repository_Plugin</id>
                        <url>http://central.maven.org/maven2</url>
                        <layout>default</layout>
                        <releases>
                            <enabled>true</enabled>
                            <updatePolicy>never</updatePolicy>
                            <checksumPolicy>warn</checksumPolicy>
                        </releases>
                        <snapshots>
                            <enabled>false</enabled>
                            <updatePolicy>never</updatePolicy>
                            <checksumPolicy>warn</checksumPolicy>
                        </snapshots>
                    </pluginRepository>                                                         
                </pluginRepositories>
            </profile>
        </profiles>

        <pluginGroups>
            <pluginGroup>com.hsbc.alm.maven.plugins</pluginGroup>
            <pluginGroup>com.hsbc.alm.maven.scm</pluginGroup>
            <pluginGroup>com.hsbc.alm.maven.jr2</pluginGroup>
    </pluginGroups>

</settings>
3
can you post your pom, your settings xml ?ant
please check pom.xml and setting.xmlMetalhead

3 Answers

1
votes

Yes you are on the right path all you need to do is this or a good solution would be to generate a new archetype with the all added jar files which you have downloaded. And then using the same artifact whenever you make a similar project.

Even if you are lacking with the m2Eclipse plugin , you can use the following commands.

This can be achieved if you follow the commands as:

Move to the project and type the following command to make the project as archetype

mvn archetype:create-from-project

Install the archetype to the local repository

mvn install

Move to some directory where you wish to locate the new project created with your created archetype

mvn archetype:generate -DarchetypeCatalog=local

If a list is populated with numbers to filter then select accordingly and you are done.

0
votes

This one is building successfully (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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.test.new.project</groupId>
  <artifactId>dadada</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>dadada</name>
  <url>http://maven.apache.org</url>

  <properties>
    <spring.version>3.0.5.RELEASE</spring.version>
</properties>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.2</version>
        <scope>test</scope>
    </dependency>

    <!-- Spring 3 dependencies -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
    </dependency>


    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-oxm</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <!-- Uses Castor for XML -->
    <dependency>
        <groupId>org.codehaus.castor</groupId>
        <artifactId>castor</artifactId>
        <version>1.1.2.1</version>
    </dependency>

    <!-- Castor need this -->
    <dependency>
        <groupId>xerces</groupId>
        <artifactId>xercesImpl</artifactId>
        <version>2.8.1</version>
    </dependency>

</dependencies>
</project>

My settings.xml :

<?xml version="1.0" encoding="UTF-8"?>

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">


  <proxies>

  </proxies>

  <servers>

  </servers>

  <mirrors>

  </mirrors>

  <profiles>

  </profiles>

</settings>

Not sure why you need to alter settings.xml is there specific reason?

Environment info :

Apache Maven 2.2.1 (r801777; 2009-08-06 21:16:01+0200) Java version: 1.6.0_29

0
votes

I was finally able to solve the jar download issue by defining proxy settings in my settings.xml. My company uses a proxy to communicate with outside world.Having said that, I also learnt that there is no need to define specific remote repository in settings.xml bcos maven by default searches in its own repository which mostly has all the opensource jars.

    <proxies>
   <proxy>
      <active>true</active>
      <protocol>http</protocol>
      <host>xyz.hk.hsbc</host>
      <port>8080</port>       
    </proxy>
</proxies>