Google App Engine with Spring MVC - java

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.

Related

Adding dependencies to existing project via Spring CLI

Is there any way to add dependencies to existing spring project using Spring CLI (for instance via shell)?
I tried to looked for on this website
docs.spring.io.
But I couldn't find working way of adding dependency like Spring Web or Spring Data JPA to existing spring project.
If you are using STS or Eclipse for your development then you can easily add dependencies using CLI. You need to press the Ctrl+Space Bar in your pom.xml. It will show you the option with Edit starters as shown below, then click on it it will open your CLI interface
Ctrl+Space Bar
You can use pom.xml to add dependencies to your existing spring project whether you created your project by using Spring CLI or any other way.
Go to Maven Repository: https://mvnrepository.com/
Search for your required dependencies
Copy the dependency for maven and paste it in your pom.xml
To add a dependancy from Spring CLI, you can use the following command:
spring init -a <name_of_your_artifact> --dependencies=web,data-jpa <my_project>
where:
<name_of_your_artifact>: the artifact Id for the project.
and
<my_project>: name of the file where the .zip of spring initilizer will be extractred.

using spring boot in a maven project

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

Instead of using Maven to pull in a third party dependency, how can I implement the source of that dependency directly into my project?

Situation:
Spring Security currently does not have a feature I need and it is a simple change to implement the feature. As a quick and dirty proof of concept (before getting the change approved through Spring), I want to pull the source of Spring Security and make the change and put reference it directly in my application.
The app is not a multi module project and has just one project that compiles into a war.
This is the Maven artifact
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
<version>${spring.security.version}</version>
</dependency>
but I don't want it to be grabbed from Maven Central since I will provide it (just not sure where I need to put it).
You should deploy your modified spring-security-ldap into you're local (or company's internal) repository with your own version and then use that version in your pom.
When the change has been accepted by Spring, you switch to their version.
Download spring-security-ldap sources, modify them (including version number), run a maven build, and they'll be deployed in your local maven repository.
Then include the dependency with the new version number in your project, .

Tomcat libraries to include in Eclipse with Maven

I'm building a web application with Eclipse using Maven. The server is going to be Apache Tomcat. Eclipse already has tomcat 6 libraries which you can include in your build path and Web Application Module facet to be chosen. That's the way I work without Maven.
However, Maven is able to include the required dependencies to use them in tomcat. My question is, what is the right thing, not to include them via Maven and continue doing that like before, or not to configure eclipse build path and make maven solve it?
The best approach for container specific API like the server API is include it in the maven POM however set the dependency as provided scope so it will be available in your class path for eclipse however maven will not package it in the WAR file when generating it. e.G.
<dependency>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<scope>provided</scope>
</dependency>
As far as I know Maven do not solve it, if you do not specifically say that your project needs these dependences. The best way is to configure the pom.xml and set the dependencies and build the project using Maven and edit it in eclipse. So once you are done you can easily "package" (build the war) and deploy it in any server location.

What is the connection between maven and my application?

I need to build java project. The project should include two modules: domain and web.
The domain module contains all the entities, the business logic and hibernate integration.
The web module should be depend on the domain module and contains web application using apache wicket.
I wonder about the maven usage.
Should I create a project and modules using maven? If so, how?
What kind of archetype are relevant for my project and modules?
What is better experience - create the project myself or use maven?
I am using intellij.
I'm assuming you don't need a server for others to access your code,
but rather, you want to use maven/ant for internal project
organization/dependency resolution/source organization.
Should I create a project and modules using maven?
Yes, either maven or ant will be useful for any non-trivial Java or Java EE project with external dependencies, and build/testing requirements.
If so, how?
Either ant/maven will allow you to easily setup a platform independent "build" file, so that you can easily resolve dependencies, build your jar executables, and run unit tests in order by issuing a single command, rather than multiple clicks to different plugins in whatver the ide-of-the-month is. You can do this in eclipse using the maven plugin to create a new maven project, or , as you suggest, by creating an artifact by running the regular mvn install.
What kind of archetype are relevant for my project and modules?
To learn use maven-archetype-quickstart.
For a regular (simple) j2ee app, try maven-archetype-webapp.
There is also a j2ee archetype as well.
What is better experience - create the project myself or use maven?
A simple, 3-step, robust method for setting up a maven project :
1) Use maven archetypes to create and setup your "hello world" project.
2) Import the maven project into your ide as a java project.
3) Edit/refine/fix code in your IDE, but use maven to build and test the whole application.
Update: external web frameworks
Creating a wicket (or gwt or any other framework) oriented web app will
Be best done following specific tutorials related to the framework itself. In order to add theframework libs, just paste the maven info in your pom.xml like thus, and run a "mvn install" command :
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-core</artifactId>
<version>1.5.3</version>
</dependency>
I'd recommend you to use maven. The reasons why I use maven:
IDE agnostic. You can use idea, eclipse or some other ID.
Dependencies management
Powerful plugin system
You can manually create 3 maven module
app.parent with pom packaging and no parent.
app.domain with jar packaging and app.parent parent
app.web with war packaging and app.parent parent
and import app.parent to idea.
Also checkout Wicket quick-start Maven archetype creation page http://wicket.apache.org/start/quickstart.html

Categories