Reputation: 9658
I have created a simple Java project in Eclipse and created a pom.xml file in the root folder. Now I want to download all of the Spring Framework dependencies by executing the pom.xml file.
Is it possible to use the pom.xml file in a simple Java project not in a Maven project and download all of the Spring Framework dependencies?
I have right clicked on pom.xml file and run as "Maven install"
on console i found this.
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building my-app 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ my-app ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/oodles/Documents/MyWorkspace/MySpringProjectMaven/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ my-app ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ my-app ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/oodles/Documents/MyWorkspace/MySpringProjectMaven/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ my-app ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ my-app ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ my-app ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: /home/oodles/Documents/MyWorkspace/MySpringProjectMaven/target/my-app-1.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ my-app ---
[INFO] Installing /home/oodles/Documents/MyWorkspace/MySpringProjectMaven/target/my-app-1.jar to /home/oodles/.m2/repository/com/qasim/app/my-app/1/my-app-1.jar
[INFO] Installing /home/oodles/Documents/MyWorkspace/MySpringProjectMaven/pom.xml to /home/oodles/.m2/repository/com/qasim/app/my-app/1/my-app-1.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.013 s
[INFO] Finished at: 2015-03-18T23:32:49+05:30
[INFO] Final Memory: 8M/150M
[INFO] ------------------------------------------------------------------------
i could not understand what happen after clicking on Maven install. Some folder created named target folder with my-app.jar and i added this jar to build path . But i think it is not working. I have Test class with following code:
package com.qasim.app;
public class Test {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("MySpringConfig.xml");
Restaurant obj = (Restaurant) context.getBean("restaurantBean");
obj.greetCustomer();
}
}
And pom.xml file:
<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.qasim.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
</dependencies>
</project>
But in Test class compiler complaing at application context line "create class named applicationContext" if the dependencies got downloaded after running "Maven install" command then it should show some "Import hint" for application context
Upvotes: 1
Views: 9038
Reputation: 2844
Update: A advice to start off: I realy recomend to consult the official documentation found here http://maven.apache.org/guides/index.html - take your time to read at least the points below "Introductions" since it will explain you on how to use Maven and how it works ;)
I copy&pasted your pom.xml
and could compile your Java class (well i removed the Restaurant reference and just created a empty file for the Spring config).
Looking at your build output:
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ my-app ---
[INFO] No sources to compile
Maven tells you it dit not compile any sources - this strongly implies you are not using the correct standard Maven folder structure.
I just set up a mini-project using your pom.xml
and the Maven standard folder structure like so:
(Note: I had to remove the paths due to company security restrictions as I am writing from within my office)
If you setup your classes under src/main/java
and place your config under src/main/resources
Maven will be able to locate the class and compiles it while it will also take your resources and places them in your jar. In my case i just created a empty file MySpringConfig.xml
which obviously wont work when trying to load the ApplicationContext
you can however see in the stacktrace below that the file itself could be found and loaded (but while parsing it the empty content was not satisfying for the SAX-parser - i bet yours looks better :).
Try it out and dont forget to consult the maven reference since i did not go too deep into the folder structures etc. ;)
Yes - you should be able to right click the pom.xml
, choose run AS
and for example choose Maven install
(corresponds to mvn install
) or define the phases to be processed under Maven build...
Alternatively you should be able to create a new Launch configuration for Maven and point the Base directory:
to where your pom.xml
resides.
Note: Afaik you need the M2-Plugin installed in Eclipse to work with Maven (i dont know lots about that funny tool but i have a Eclipse Juno here that was able to build a Maven project created manually inside a "simple java application" project).
Note: If you just need the dependencies and use Maven as a "helper" to download them you can always manually download the Jar from most remote repositories like for example here: http://mvnrepository.com/search?q=spring
Upvotes: 1