Build web app in Eclipse to run on Tomcat - java

I'm a newbie in building web apps. I just created dynamic web project in my Eclipse and successfully ran the jsp file on tomcat (as an eclipse's plugin)
However, when I tried to ran it on my actual server it failed, and I found a post here where someone addressed this issue. But the problem is I don't know how to build my web app and
Thus the servlet was not compiled, and no File "myServlet.class" was
deployed to the server
Can someone direct me to the right solution please?

Related

Trying to deploy a Spring Boot web app using a JAR file, however am getting 404 NOT_FOUND errors on my JSPs

First post on here and I'm fairly new to JAVA so please keep that in mind ;) I've spent literally days trying to solve my problem and am running out of patience. Here's the deal : I've got a Spring Boot web app that I've successfully deployed on Digital Ocean by running a Tomcat Server and deploying a WAR file on my cloud VM. Everything was working fine with that set up when my app wasn't a Spring Boot app. Since then I've changed it to Spring Boot (added Spring Security etc.) and would like to deploy a JAR file which has Tomcat built into it which I was told is simpler and the better way of doing things. After creating my JAR file via my IntelliJ IDE, using Maven clean and build I'm able to run the app successfully on my windows machine command line which I've confirmed runs : localhost:8080/login spits out a message to the console so I know it's in my controller as well as I can see a connection to my DB. The issue is my JSPs files aren't loading and am seeing the below in my console:
Errors
Forwarding to [/WEB-INF/view/login.jsp]
Completed 404 NOT_FOUND
After many hours I've realized that when I open my JAR file via WinRAR, the JAR file is missing my files that I had under my webapp directory in IntelliJ. Since this is a stand alone executable JAR, these files need to be located somewhere in my JAR, right?
Two questions I guess:
1.Do I need to do something special to get my webapp files added to the JAR during the build?
2.Can I just alter the JAR manually and place them in there? If so, where should I locate them so that they can be accessed and I won't get the 404 errors anymore?
Thanks all for your help. Much appreciated.

Deploy java web application to Tomcat with Visual Studio Code

I'm trying to deploy a java web application to Tomcat using Visual Studio Code and I'm having some issues that I'd like to share.
After installing the extension Tomcat for Java, I've tried to deploy a Maven Java Web project. To do so, I've clicked over project's folder and selected "Run on Tomcat Server" option. The result is an error with this message: The folder is not a valid web app to run on Tomcat Server.
Then, I've realized that maybe I should create a war file before running it on Tomcat. Therefore, I've executed mvn clean package command and afterwards execute "Run on Tomcat Server" option over the war file. Doing this the project has been deployed correctly.
However, compared to Eclipse's way to work with Tomcat, it seems to me a bit tedious. Particularly if I'm working with static files, like css or js, because every time I modify a file I should execute mvn clean package and "Run on Tomcat Server". Whereas, in Eclipse, these files are deployed automatically on Tomcat without restarting.
I wonder if there is another way to work with VS Code and Tomcat for Java.
Thanks!
If you use Spring, there is an easy way.
The Spring Initializr extension comes with an embedded Tomcat installation, and hot reloading works out of the box.
Rely on the following guide to install it:
https://code.visualstudio.com/docs/java/java-spring-boot

Spring MVC App runs in Eclipse but not Intellij - 404 Not Found

I've written a Spring MVC app that is functional on an app server. I'm attempting to switch development of this app from Eclipse and to Intellij. I am very new to the IDE so I'm not sure where I have gone wrong here.
When I run this application on the server in Eclipse it goes to localhost just fine and works as expected. I created a run configuration in IntelliJ, the app compiles and the server log says it was deployed successfully.
However in the browser it gives the standard HTTP Status 404 - Resource Not Available.
I really don't think it's the servlet or web.xml because those are working just fine in Eclipse. I've also created a brand new app in Intellij to test it and it works fine. So it must be something specific to IntelliJ that I have misconfigured or not setup at all...any ideas? Let me know if you need to see specific screens or anything.
So after toying with this, making it worse a few times, and then getting it back to the original 404 I found the difference.
Eclipse has an internal tomcat server it runs projects on, Intellij runs its projects on the default tomcat server installed on your computer. Intellij exports the project you are running to the server in the web apps folder as the name of your project.
So after I found that, in my tomcat run configuration in Intellij I had to specifiy the application context. Edit Configurations -> Deployment tab -> Application context, and set it to /YourProjectName. My guess is that this tells tomcat where to find your project within the web apps folder.
I hope this can help anyone else who is a relative beginner to tomcat/java EE and intellij like I am.
There is a plugin in intellij called "Smart Tomcat", it allows running spring or web app with much fewer configurations.

What are the drawbacks of deploying a website using the Eclipse IDE?

I started my journey into web applications about three years ago and I'm happy to say that I've finally deployed a working website. My concern is that to deploy the website I use the Eclipse IDE and a Tomcat webserver. So basically I right click the project in Eclipse and then choose "Run As > Run on Server" and then select the Tomcat server I downloaded - from that point on the console spits out some startup messages and my website is online and ready for use. What are are some of the drawbacks of deploying a project this way. I've read just briefly about WAR files and adding them to Tomcats Webapps folder but I could neither get that working nor did I understand completely the process...so is it acceptable to just deploy the project the way I have been doing thus far by running it in Eclipse?
Generally Development machine and deployment server is different.
On Deployment server one may not have eclipse always.
WAR file is just a webarchive which includes all the necessary files. WAR makes your project portable.
Export WAR from eclipse place it in tomcat webapps in any machine and restart tomcat.
You should have your webapp successfully running on that machine.
That's a fine way for deploying a server when you're learning, or always have the server (the only server!) running on your development machine.
If you need to push to a remote machine, it won't work, and you'll need to learn other methods then, but for now, what you're doing is fine.

Setting build path in eclipse java

I have searched stackoverflow before posting this question.
In eclipse i am running a tomcat server. I deleted the .class files from the work folder of the tomcat server. From then on I am facing the issue saying the class couldnot be found.
I re-built the project. Didnt help
Can you please suggest how to fix this issue.
You should NOT run Tomcat as a normal program inside Eclipse. You should use the EE version of Eclipse, and then add Tomcat in the server view. This will allow you to deploy Dynamic Web Projects directly to Tomcat or any other supported server.
delete the server from eclipse server view and create it again.

Categories