I am starting a new project with maven and spring boot and got problems already at the very beginning :-) Finally it works now, but I would like to know what I did wrong:
I simply wanted to add spring boot to my project by adding the maven dependencies:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-build</artifactId>
<version>1.5.9.RELEASE</version>
</dependency>
which can be found in Maven-Central.
This doesn't work.
Then I found out, that the correct dependency is without "-build":
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>1.5.9.RELEASE</version>
</dependency>
I would like to understand, where is the problem:
Do I get the info on the wrong place and maven central is wrong ?
Or why did I get problems from beginning. What is the correct aproach ?
I think one of the best approaches for creating new SpringBoot projects is to use the Spring Initilizr: https://start.spring.io/. With this tool you will get a generated .zip file which containts the basic maven/gradle folder structure and has the correct dependencies in your pom.xml or build.gradle file. During the creation of the .zip you can easily search for you required SpringBoot dependencies like Web or Security and with a tick in the checkbox will get you the right dependency.
You can also use a Plugin for Eclipse called Spring Tool Suite which enables you to create fresh SpringBoot project out of eclipse with rightclick -> New -> New Spring Starter Project. This is also available in IntelliJ or you use the dedicated IDEA STS from Eclipse https://spring.io/tools/sts/all
Related
We are planning to create one spring boot project , which we create as jar file , and this jar we will use as dependency for another spring boot application , point is the first jar must contains the classes we code and its related jar files , is it possible like that ?can any one help us please .
Problem is when i create the jar , only my classes which i coded are packing into jar , not the dependencies of that app
Just use spring-boot-maven-plugin or spring-boot-gradle-plugin depending on your build system. Purpose of these plugins is exactly your use case.
Spring Guides are great place to start exploring: Maven Guide, Gradle Guide.
The only caveat is that you want to exclude tomcat internal container from such shared library:
Maven:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- ... -->
</dependencies>
Gradle:
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
...
}
You can do that by using "maven shade" plugin for creating a Fat jar, also called uber-jar of the parent project, which you want to use in child project. This Fat jar contains the code you have written along with all the dependencies of the project. You can check here for more details : https://maven.apache.org/plugins/maven-shade-plugin/index.html. The Fat jar created will be placed in your local repository.
In your child project, you can use parent project as a dependency by specifying following properties:
<dependency>
<groupId>parent_project_group_id</groupId>
<artifactId>parent_project_artifact_id</artifactId>
<version>parent_project_version</version>
<dependency>
Make sure that you build parent project with maven shade plugin and not with spring boot default plugin. Also, use "clean install" as goal while building the parent project.
I am reading a tutorial on "Building Microservices with Spring", however, I can't find "spring-boot-starter-security" dependency - I am using Spring Tool Suite 3.8.3
Any guidance on how to install this dependency will be highly appreciated.
PS: I am new to Java and SpringFramework
Maven dependency management picture
You could also right-click on the pom.xml file and go to "Spring -> Edit Starters" and select the one for spring security there. It adds that spring boot starter dependency to your pom for you.
You need to find your pom.xml, this is the file where all your dependencies are managed.
You can find a file in the Spring Tool Suite, by going to the search menu and d selecting file. You simply then need to enter "pom.xml" in the "File name patterns (seperated by comma):" field and press search.
You then can add the dependency like this in the <dependencies> </dependencies> element of the xml file.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>1.4.0.M3</version>
</dependency>
I need to add cxf-core, cxf-frontend ext. file in the project. I am trying to add these using maven dependency in pom.xml but it didn't work and version number is getting be red when it is added.
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-core</artifactId>
<version>2.6.2</version>
</dependency>
org.apache.cxf:cxf-rt-core:2.6.2 not found.
I also tried to add using external .jar libraries. The IDE is Intellij IDEA.
2.6.2 worked for me, I used Eclipse to create a new maven project and pasted in your dependency. It worked, fetched the required jars and give me this dependency hierarchy.
I want to use GAE with Spring MVC
so, I found this following site.
here
but This site's example seems to manually add jar files.
I think it is inefficient.
In eclipse, Is there another way like adding dependency on pom.xml in spring MVC project?
I would suggest you to git clone the guestbook-spring project (it's adding Spring MVC to the GAE guestbook example) and continue from there.
We have builded our webapp app based on this, and it's great.
P.S. Also, it got tests for the controller included. It's good to have it as inspiration for testing you future app (as a developing practice).
Yes, if you have created a maven project, then it is much easier to add dependencies using pom.xml.
You can edit directly, or use eclipse maven pom manager to add dependencies directly, or from a repository.
The link you gave does not create a maven project, but you can modify the instructions so it does.
You can create maven project instead of Web Application at the start, then add Spring dependencies and continue adding dependencies from there.
You could use gae archetype to create your project firstly, and then add spring components to pom.xml:
mvn archetype:generate -Dappengine-version=1.9.14 -Dapplication-id=your-app-id -Dfilter=com.google.appengine.archetypes
where -Dappengine-version is set to the most recent App Engine Java SDK version, and application-id is set to the Developer console application ID used for your app.
I found simple way.
1.First, Create Spring MVC Project, and add dependency and plugin in pom.xml
1.1 add gae dependency
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>1.9.14</version>
</dependency>
1.2 add gae plugin
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>1.9.14</version>
</plugin>
In WEB-INF, create appengine-web.xml and logging.properties
then, you can run it on server
Create a new Web Application project as it is shown, after that right click project -> Configure -> Convert to maven project.
I learned Spring via Spring In Action 3 few month ago. I downloaded Spring libraries from official site (list was like in SIA3(aop, asm, aspects, beans ...)), added them to my project and everything worked fine. Now I want to use Maven, but I am getting a lot of errors and sinking in searching what library to add.
I am newby, dont know all Spring dependencies(within it libs) and the question is not about my errors, but about the way to add all Spring libraries to my project via Maven. How do you usually add Spring libs using Maven?
You don't have to download the libraries themselves anymore. That is what Maven is for. (and quite some more, of course)
set up Maven properly
set up Maven in the IDE tool you have (like this)
edit the pom.xml to include what you need, adding the dependencies in the in the dependencies tag.
Maven takes care of resolving the dependencies of the specified packages. If a package depends on other packages, it will do it for you. You only have to specify the packages you directly need
For example
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6</version>
</dependency>
You can easily find the packages using Google, and searching for "maven repository "
Avoiding version clashes
Also, as Bart mentioned, the common way of having Spring in the pom.xml - as it has way too many versions, and clashes can occur - is through a common property specifying the version for all Spring components. (Based on this answer)
Specify the property in the properties tag:
<properties>
<spring.version>3.0.5.RELEASE</spring.version>
</properties>
Then use it in the dependencies like this:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
Be careful to use it for ALL components to avoid version clashes. (of course, issues mught still occur, bz having different libraries reference spring too, but that is another story in its own.)
Side note
Keep in mind note that Maven projects use specific directory layout. When I first started using maven for my own projects, first I created a new blank one, and played around with it, before I began migrating my older projects to use maven. Believe me, it pays off.
Add spring artifacts to your pom.xml file. For example
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.2.4.RELEASE</version>
You can find more artifact info here
http://mvnrepository.com/
HERE you can find the dependencies as per your requirement. Just click on the dependency and inside click on the latest release, scroll down there is your code inside the <dependencies> Your required dependency and version</dependencies>.
Just copy the XML code and paste it in your pom.xml file.