Question

Ok this is long and has many stupid questions, because I am a dumb beginner.

Im a single developer working on a project (Java Web App) and I am relatively new to Java. I am even newer to the Spring framework. I have managed to write a small project that uses one servlet and some jsp's to authenticate users against a database and route them to either a welcome page or an error page based on login credentials. I have gotten to this point but it is only the beginning of what this application will do ofcourse. Most importantly, I am not using any Spring.

I understand that it is in my interest to learn the spring framework if I am to design Java EE enterprise applications because it makes many things easier. So, in that quest, I headed over to the tutorials on this website:

http://spring.io/guides/gs/serving-web-content/

in order to do some learning. I relized quickly that all of their examples include a Maven or Gradle script for dependencies and for build. So, I thought oh no now I have to learn about one of these build tools if I need to use Spring framework? So, with my limited knowledge and reading around, I picked Gradle when I started understanding that it is the latest generation build tool in the line of Ant->Maven->Gradle. So, I thought Gradle is what I should invest my time in.

Anyway, when I started to work on the Spring tutorial above, I quickly realized that they are doing this at the command line and not on an IDE. That confused me even further because I thought why would anyone used command line in todays world full of capable IDEs. I had Eclipse (plain vanilla + Spring Tool Suite) installed already so I thought I will do this on Eclipse instead. That's where my confusion skyrocketed.

For starters, I couldn't figure out what kind of project template to start with. Should it be a "Dynamic Web Project?" No wait it has to be some kind of a Spring template right? Otherwise why would I go through the trouble of adding the Spring Tool Suite and get all these new templates? Ok, so I picked a Spring template. I quickly realized that I also have the option to import the Spring MVC tutorial that I was doing into Eclipse. So, I did that. More confusion, now I realized that if I right click on the imported example project, there is no longer a "Run on server" option in the "Run as" menu. I thought why is that gone? I must have picked the wrong project template. But wait, I couldn't have picked the wrong template because I imported the whole project from the Spring website. Oh man my head hurts. After some thinking I remembered.....oh yes they talked about Gradle and I already downloaded it and set my Path environment variable for it so I'll use Gradle to build and run this project. Ok now how do I invoke Gradle from within Elipse? More reading told me I must have Eclipse Gradle Integration. So I downloaded that plugin into eclipse. Now, in my right click menu I have a "Gradle" and "Gradle..." option but still no "Run on server". Man, why is this so complicated I am a beginner simply trying to run a tutorial Spring MVC project. Anyway, I chose "Gradle" from the "run as" option and I saw that Gradle prints out a bunch of a stuff in the Eclipse console like when its starting the embedded servlet container and other good stuff. But I see nothing else happening. I expected the Eclipse embedded web browser to show me "Hello world". But wait this isn't a web project because there is no Web-Inf folder in its hierarchy, so why would I see a browser...okay but I also don't see "hello world" in the console? Where is the project running? Ahaha..finally I launched my own Chrome browser and pointed it to localhost URL and glory, I saw "hello world".

It took me two and a half days of playing around to figure all out up to this point. As you can see, my understanding is in its infancy on these things and I need some questions answered. If am looking to build a Java web application and I am the only developer:

  1. Do I need a build tool? I thought this was for teams.
  2. If so, is Gradle ok?
  3. Which Eclipse template to start with?
  4. Some other Spring MVC tutorials I saw online like the one from tutorialspoint do include jsp's and are web based(and not simply command line). Those tutorials ask you to import some jars(Spring and related jars like commons-logging) into the project at some point. How do these guys know which of the spring jars they need? Is it from experience or is there another source for this knowledge? I thought this dependency management is where the whole need for the build tool comes in and that's what Gradle will handle for me, nevermind I don't know how to ask Gradle to do that yet.
  5. Once I start a project and start using Spring incrementally, how do I know what additional jars I need at certain points?

Thanks for reading until this line and thanks for your help.

Was it helpful?

Solution

Do I need a build tool? I thought this was for teams.

Yes, you need when you work with a large project which need lot jars, classes and configuration files to run application, by using a build tool that will take care of all these things. build tool will save some time typing commands. As you can probably guess, it’s not reasonable to use the command line if you have many source code modules and they should be compiled and linked in a particular order.

you said your a single developer, so build tool is just an overhead.

If so, is Gradle ok?

Ok.

Which Eclipse template to start with?

Dynamic Web Project.

Some other Spring MVC tutorials.... How do these guys know which of the spring jars they need?.....

Well, when you going to develop a web application with spring, then you need to have jar files like: spring-core.jar, spring-web.jar, spring-webmvc.jar etc. same when you need any ORM framework like hibernate then you need to add hibernate releated jar files in project build path. When you go through some tutorials they will be listed like what are jar or dependencies you need to add.

Once I start a project and start using Spring incrementally, how do I know what additional jars I need at certain points?

It depends upon you which frameworks you need to use further in your application, then, you should make available all the dependencies(jar files) of the framework to your project build path.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top