0

I am familiar with Java as a language but not JSP and Spring framework. I am trying to load an existing project and using vim as my IDE.

Originally, when working on it using eclipse, I installed openjdk7-jdk, downloaded the tomcat7 server from its website and extracted to a location, imported project in current workspace, set up the tomcat for server environment. I was able to see the application in browser.

I am looking for a way to use vim, installing tomcat from official repos and then either set up a new host for this application or adding a context for the same. I have tried both the ways but still not able to make it work. I get the tomcat standard 404 error page.

This answer here says that this may work if I create a .war file and place it in the webapps folder. Is this the only way to run a spring based application?

After working in ASP.Net, ROR, Django, I am assuming Java also has similar deployment structure.

Community
  • 1
  • 1
Harsh Gupta
  • 4,348
  • 2
  • 25
  • 30
  • Start by reading this to understand what a .war file is: http://stackoverflow.com/questions/5871053/java-war-vs-jar-what-is-the-difference – User404 May 07 '15 at 11:42
  • I would recommend learning to use Maven, and using it for building and deploying your project. – meskobalazs May 07 '15 at 11:42
  • .war inside tomcat will work for you – Pramod S. Nikam May 07 '15 at 11:42
  • @User404 I understand what a .war file is. I am interested in knowing if it's the only way. – Harsh Gupta May 07 '15 at 11:54
  • @meskobalazs, let me see if I could get Maven to work for me. Why have they made this so complicated and tightly bound with an IDE? I thought OSS was supposed to help developers select their own tools for development. Or am I hallucinating and could get this to work? – Harsh Gupta May 07 '15 at 12:02
  • You can deploy (copy to the webapps dir) a .war file or a folder that has the same internal structure, als known as an "exploded WAR". With Tomcat you can also deploy using the manager web API, that allows you to (re)deploy/stop an app without afffecting other apps running in the ame Tomcat instance. – Pierre Henry May 07 '15 at 12:04
  • @HarshGupta It is not tightly bound to the IDE, it's just much more effective to use one. By the way Maven works great with command line tools (Even the Eclipse plugin does that internally). – meskobalazs May 07 '15 at 12:11

2 Answers2

0

One thing is that Tomcat is not required for spring based applications. But if you are implementing J2EE application on Tomcat, make sure you have Spring context defined in your webapps web.xml (inside WEB-INF directory).

The Spring Application context must be initialized through your ServletContextListener implementation.

  • Could to point me to an example? Like I said, all this is alien to me right now. Still trying to make sense of many things. – Harsh Gupta May 07 '15 at 12:03
  • @HarshGupta Go through [this](http://stackoverflow.com/questions/18229139/spring-framework-does-not-required-sever-is-it-true) discussion for better understanding. – Tejas Unnikrishnan Aug 02 '15 at 09:42
0

Oups, seems there a long way to heaven ... More seriously you must pass by several steps (that a nice IDE like Eclipse or Netbeans can hide from you) :

  • create the source files for the application - you spoke of vim it can be used for that step
  • compile and build the application to a .war - this step is almost mandatory but i would not dare avoid it as I explain below - you can use low level tools like javac but you really should use ant or maven here ; if you are lucky, there is already a pom.xml (maven) or build.xml (ant) in the sources
  • deploy the war to a tomcat

In theory, it should be possible to individually compile the java file into .class, build a full hierarchy by hand and put that manually in webapps folder of tomcat. But never do that - or at least never say that I adviced you to do it :-)

Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252