0

I have installed Maven and created a simple project according to their instructions. I then added the spring-context (per the Spring IO site) dependency. Nothing interesting happens.

{rant} I HATE that Spring is shoving Maven down my throat! Maven is TERRIBLE in established shops that can't stop what they are doing to Maven-ize hundreds of artifacts. On top of that, Spring has now fragmented the dependencies in incomprehensible ways. Stupid! {/rant}

I assume there is some way to simply download all the JAR in a dependency. Can anyone provide a pom.xml and a command line that starts with "mvn"?

Steve11235
  • 2,849
  • 1
  • 17
  • 18
  • You could always download the jars from mvnrepository.com. The webpage will show you the dependencies. Maven isn't a terrible tool just because you're stuck on a legacy build. Granted spring could do more for non-maven shops but you're free to think with your feet and find an alternative... – Ben Thurley Nov 25 '13 at 21:58

3 Answers3

1

When you have all dependencies defined, then you only need to run mvn dependency:copy-dependencies, then maven ({rant} the great tool{/rant}) will put all dependencies including transitive dependencies to the target/dependencies folder

@See: http://maven.apache.org/plugins/maven-dependency-plugin/copy-dependencies-mojo.html

<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>

    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>

    <groupId>com.test</groupId>
    <artifactId>com.test</artifactId>

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

    <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>

    </dependencies>
</project>
Ralph
  • 118,862
  • 56
  • 287
  • 383
  • Would you please provide a complete pom.xml? I understand what you are saying, but I doubt I can make it work. – Steve11235 Nov 25 '13 at 21:19
  • Do you have a pom for your project? – Ralph Nov 25 '13 at 21:26
  • Yes, the Maven install instruction create a basic project with a pom. – Steve11235 Nov 25 '13 at 21:30
  • Thanks for the POM. I added the various groups and ran mvn package. I now have a my-app-blah.jar. However, I don't see any sign of the Spring JAR. – Steve11235 Nov 25 '13 at 21:35
  • as i sad run: "mvn dependency:copy-dependencies" !!! If you run mvn:package, then the jars will be "only" in your local m2 repostiory (c:/documents//.m2/repository/org/springframework/spring-core/3.2.5.RELEASE/) – Ralph Nov 25 '13 at 21:42
  • Sorry. The page isn't updating correctly, so I just now saw your response when I tried to add a comment. I mis-read what you typed initially. I see the dependency folder, and it has the JAR in it. Thanks. I knew I couldn't be that hard, but I wouldn't have figured out without your help... – Steve11235 Nov 25 '13 at 21:46
0

This is how you add the Spring context dependency to your project.

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>3.2.2.RELEASE</version>
</dependency>

Now it depends exactly what you want. Whatever mvn command you run the dependencies will be first downloaded to your Maven local repository, not your project.

Here you can also download the jar http://search.maven.org/#browse|-618956366, but it's not the recommended way.

Alternatively, you can clear your entire Maven local repository and then after a command like mvn package or mvn install it will be repopulated again with all your dependencies. If it's a web application your war will contain in WEB-INF/lib all the dependencies. If you want to create a jar with all dependencies see How can I create an executable JAR with dependencies using Maven?.

Community
  • 1
  • 1
Adrian Ber
  • 20,474
  • 12
  • 67
  • 117
  • OK, this is a start. I don't have a project. I'm a consultant working on a client machine. I'm not authorized to have Maven at all, and I'm certainly not going to try to update RAD with it. – Steve11235 Nov 25 '13 at 21:17
  • I added a dependency of that form to a default project created by mvn, and it didn't do anything. – Steve11235 Nov 25 '13 at 21:17
  • I need to know ALL the dependent JAR. I am not in a position to guess. – Steve11235 Nov 25 '13 at 21:18
  • When I run mvn by itself, I get a no goals specified error. That would explain why nothing is downloaded. – Steve11235 Nov 25 '13 at 21:24
  • 1
    That's the exact reason for using Maven, because it automatically resolves your dependencies. See my edited answer. – Adrian Ber Nov 25 '13 at 21:26
  • I ran mvn package, which ran to completion. I don't see any indication that the Spring dependencies were downloaded, nor do I see any sort of repository. Where might it be? – Steve11235 Nov 25 '13 at 21:30
0

I accepted Ralph's answer, but I wanted to record the steps I took to do the full task. Just to clarify, I don't have a problem with Maven. I have a BIG problem with Spring forcing me to use it.

Download Maven, unzip it. Note that it requires M2_HOME and JAVA_HOME properties, which can be set in a CMD file if you don't want to make them permanent.

Run this command to create a default project, with a pom.xml. Note that you should be in an empty folder when you do it.

mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

Move into the my-app folder that was just created and edit the pom.xml. Note that Maven seems to require a JUnit dependency for testing.

<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.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>

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

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>3.2.2.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>3.2.2.RELEASE</version>
    </dependency>
</dependencies>

Run

mvn dependency:copy-dependencies

and your project should now have a dependencies folder with all the JAR.

Steve11235
  • 2,849
  • 1
  • 17
  • 18