Strange Java web application in Eclipse - java

I am new to Java web programming and currently working with a Java web project. Although I have searched for days but still not able to figure out what kind of project is it and how to configure to get it run. It has a webapps directory and a web application inside. But the Java code is stored outside and under the root directory.
So what documents should I read to get familiar with this kind of project, and how could I configure to get it run on Tomcat?

You should check the .project file located in your case at mapsview/.project to get more insight about this project. It has builder and natures information which helps you understand what kind of project is.

Related

Eclipse Java Resources Folder

I am learning Java Dynamic Web Development and have confusion about the folder structure created by Eclipse. I am running the latest Eclipse IDE 2021-03 JEE and noticing that, when creating new projects, the project structure appears to be different when comparing to the online tutorials I've seen. I am noticing a WebContent folder in which I believe I can simply rename the folder from "src/main/webapp" to "WebContent" in the Content Directory during the web project creation. But the Java Resources is one that I cannot seem to add manually and it is always appearing in every tutorial I've seen. I am hoping for some direction on this.
Thanks!

New to J2EE - Hosting a Spring MVC based project using Tomcat 7 server on local dev machine (no Eclipse)

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.
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.
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 :-)

how to run a spring application in tomcat without using eclipse etc

my application is running in eclipse but i want to run it on tomcat .i want to run my spring application in tomcat server and don't want to use eclipse or any other tool, so how can i do that and where do i put my various files basically the directory of it, and the complete procedure to do that.
main problem is in the directory structure and the path to be put in the tomcat server to run that application. i tried but it gives the 404 error file not found ,as i am new to the spring framework explain in detail
You are asking a very broad question. But, in an attempt to point you in the right direction please see this article. The link given provides insight into the directory structure of your application.
Now as far as running "outside of eclipse" you should be able to export your project from the "File" menu as a "Web Application Archive" or "WAR" file. This file can then be placed under ${CATALINA_BASE}/webapps and be launched when you start your container.
If you are using a stock configuration and you have an archive named "myapp.war", you can access it on
http://localhost:8080/myapp
I hope this information helps you get to where you need to go.
First export the war file using eclipse as you are using eclipse.
Then follow the procedure
How to deploy a war file in Tomcat 7

what are the steps in order to run java enterprise application

Sorry for this simple questions but i am too much confused with how to run java application. Whenever i ask some each one tells his own tools to proceed and i have learn that thing.
So provided i have simple basic eclipse with no plugin and i have downloaded the sample web application which uses spring , hibernate , mysql ,
The folder structure of app is
.setting
src--main,test
target
.classpath
.project
Now i want to run this using localhost in browser
what thing i need to do. i will tell from my knowledge and u guys can correct it
i don't want to use STS or install any plugin in eclipse.
I imported the project from eclipse
menu and i appeared on left window
As it uses spring do i have to add
the spring jar files in build path
of spring. or anything else
Same for hibernate jar files
Fior simple java app i used to
compile the class which contain the
void main function but i have no
idea which file to compile to run
this app
I added the mysql connector in build
path to connect with mysql in simple
java app. will same thing work here?
I knoow we need web server for that.
so if i want to install glass fish
server then how will i connect it to eclispe or that app. will tomcat be
ok than glass fish??? i know tthere
is eclispe ide with embedded glass
fish but i want integrate evrything
myself
IN browser i which url i need to use
to see that app
I don't know how did maven , appfuse fit in here. Can i run app without maven if yes then what does maven really do , i mean does it compile the java files or what. If i require maven then
Do i need to install it separately i
mean exe file or jar file
how to link with eclipse
I have read about building with
maven , what will ahppen after
building i mean what is the result
of building , will i see browser
after building or after building
there are some steps further. do
maven needs to link with web server
installed
sorry for basics questions but i am confused with all new trminology
Building a webapp is complicated. I will try and address your specific questions.
Utimately you don't need Maven or Appfuse, both can be very helpful.
Maven is a build tool. Maven and Eclipse do some similar tasks. Both can compile your code and manage a classpath. Maven handles a lot of things out of the box that Eclipse can't do by default. Maven can manage dependencies (i.e. download the spring jars for you) and create complex build processes.
If you are unfamiliar with Maven and creating a build file from scratch then it probably won't be much help. If you have a pom.xml (Maven build file) from somewhere else then Maven can be a big help. The result of Maven depends on how your build file is structured. The result is most often either a .war file (described below as step 5) or that your application is deployed directly to your web server (described below as step 6).
Appfuse is also not mandatory but can be useful. Appfuse will create a skeleton project for you. When it does this it will create a pom.xml (Maven build file) to automatically build your project. Appfuse by itself doesn't do anything other than help get projects started. Most people don't start building web apps from scratch anymore since getting the directory structure right and creating the build file can be a lot of work and it's easy to make mistakes. A tool similar to Appfuse is Spring Roo.
Tomcat, Glassfish, Jetty, and JBoss are web servers. They are also often called Servlet Containers which is just another name for a web server that hosts servlets in a certain fashion. Any of them will work for your project, they all have different learning curves. Integrating them into Eclipse may work for you, when I got started I found it was easier (although a little slower) to keep them separate.
In the JDK there is an interface named javax.servlet.Servlet. This is the interface that the entry class of your web application must implement. In particular the method service(ServletRequest req, ServletResponse res) is called every time there is a request for a URL. If you want your web application to respond to HTTP it may be simpler to extend the abstract class HttpServlet (which implements Servlet) instead. Most libraries (i.e. Spring web framework) have their own implementations of Servlet that are the entry point to the library.
I will now describe the basic process for building a web application. This is a complicated process and most people eventually automate it with Maven. I do not suggest trying to manually walk through the process yourself it can be very complicated but you can if you want. I am going to assume that you are placing all of your built files in a folder named $BUILD
Compile your source code. The compiled classes need to end up in a folder called $BUILD/WEB-INF/classes
Place all your jar files (external libraries) in a folder named $BUILD/WEB-INF/lib
Create a deployment descriptor, this is a file that tells your web server how to deploy your code. The most important thing in this file is a mapping from URLs to Java classes that implement Servlet. It should be named web.xml and put in $BUILD/WEB-INF
jar up the all this code with the root of the jar being at $BUILD. You could call this code application.jar
Rename the jar file extension to war. A war file is simply a jar file that has the required WEB-INF directory inside of it.
Deploy this war file to your web server (Tomcat/JBoss/Jetty/Glassfish/etc.), the process for doing this is different for each web server
That is the basics of web application deployment. Your web server will extract the war file and load all of the jars in the lib folder into the classpath. It will then take any URL requests it receives and send them to the appropriate Servlet implementations declared in your deployment descriptor.
As you can see this is not a simple process. This is the reason tools like Appfuse and Roo exist. They try and give you a starting point which does all of this basic stuff for you. If you are having trouble I would suggest trying again from scratch with Appfuse/Roo. As you start to get the hang of things I would also suggest learning more about Maven (or Ivy+Ant) to handle dependencies for you.
You should download the Java EE edition of Eclipse - it contains the code needed to work with enterprise applications.
You will also need an enterprise server (like JBoss or Glassfish) and the corresponding server adapter, which is a bit much for a beginner.
The easiest way to get started is to download Netbeans with Glassfish and use that instead - at least for now - as everything is configured correctly and it is very fast to get started! When you are more familiar with the way things work, you can switch back to Eclipse if you want to.

In IDEA, I setup to deploy using web app exploded, how do to .war file?

Using IDEA and tomcat I setup a simple spring mvc app (thanks to you guys) and it was deploying using a 'web app exploded' format.
Is a .war file the same thing, except in a single file appname.war?
How can I configure IDEA to do this?
how do I have IDEA make a .war file during compilation and/or deployment?
how do I link this to tomcat?
when tomcat runs, how does it point to my output and where does it configure my app to run?
It depends on the IntelliJ IDEA version you are using.
Usually in the same screen where you setup the exploded directory, you can setup to generate a WAR file too - just need select that checkbox.
With IntelliJ IDEA 9.x however, a new configuration was introduced called "Artefacts" - it is much more flexibile, but for me it was not as intuitive as the old solution.
Here is a small article about this "Artefact" new feature, but you can read more about it directly from the IntelliJ online help.
If you want to control tomcat form inside IntelliJ (e.g. practical when developing), than you need to add in the project configuration a new Facet - the Tomcat Facet. That way you can specify in that screen the deployment mode.

Categories