This question already has answers here:
Where does Eclipse deploy web applications using WTP?
(2 answers)
Closed 14 days ago.
I have dynamic web project in my Eclipse with Java that was used to create simple SOAP web service that runs on Tomcat 9. Service was published and runs fine.
But I can't find where Eclipse puts java class files and other libraries when I start web service. I can't find any changes in Tomcat folder.
I'm usually doing this to find file location of classes
YourClass.getProtectionDomain().getCodeSource().getLocation().getPath()
Replace "YourClass" with any class in your project, debug and evaluate this line, then this will reveal file location.
Also another hint, as per my understanding, a web application can packaged as a war file and can put to tomcat/webapps folder or web application path can be specified manually in a context xml file of tomcat/conf/localhost folder
Related
I am trying to get a Java web application that uses servlets to run on MAMP. To run java files on tomcat, I have installed tomcat 10 into the MAMP folder seemingly correctly following this tutorial so I am unsure why MAMP cannot call/use the servlet programs. (Since my web application has PHP files and using Regular Tomcat with PHP is a buggy mess I need to use MAMP). Every time the program needs to call a servlet this error it thrown: The requested URL was not found on this server (The html and php files run fine)
What I am using:
Netbeans IDE
Java maven Web application
What I have tried:
Changing Root directory to the "src", "main" and "webapp" folders (The sevlets are seperated from the web application folder under "java"
Essentially: How can I configure MAMP to run java servlets?
This question already has answers here:
Multiple contexts with the same path error running web service in Eclipse using Tomcat
(24 answers)
Closed 4 years ago.
I got following error when I tried to run a project on eclipse. Can someone please explain what can be done to resolve it.
Could not publish server configuration for Tomcat v7.0 Server at localhost.
Multiple Contexts have a path of "/CityHotel".
Multiple Contexts have a path of "/OOPEmployeeWebApp".
Possibly you have a context configured in Eclipse and a WAR file deployed in the Tomcat webapps directory, both with the same name.
check your tomcat folder and /conf and server.xml, and remove the duplicated contexts
It should be a configuration problem, might be you need some server specific configs you didnt set, thus it is throwing the error.
It could also be an actual duplication error, in which case check all class paths for duplications.
I have followed this very basic tutorial for setting up a WebSocket endpoint in Java: http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/HomeWebsocket/WebsocketHome.html
Heroku, however, expects me to rely on Play Framework: https://devcenter.heroku.com/articles/play-java-websockets
My question is: how could I deploy the same without any additional frameworks and what procedure should I go through in order to make things work?
The problem you had was this:
The tutorial you followed was made for the GlassFish Application Server but Heroku only supports Tomcat 8 and Jetty. See here: https://devcenter.heroku.com/articles/war-deployment
But don't worry, I ported and tested the tutorial to run with Tomcat 8.
I also added the glassfish implementation of the javax.json specification.
(Make sure to download the implementation and not the spec interfaces only)
You can find it here: http://central.maven.org/maven2/org/glassfish/javax.json/1.0.4/
I also noticed why maybe your index.html didn't work locally: I think it was because the WebSocket URL was hardcoded in the websocket.js file.
I have taken the liberty to fix this by making it dynamic.
Here is the complete NetBeans 8.0.2 project:
http://ray.hulha.net/WebsocketHome.zip
Here is the best way to create a war file from inside NetBeans 7 or 8:
There is one catch however, the Tomcat 8 on Heroku is missing the websocket addon.
But no worries, you can added it manually to the war file.
Here are the steps:
Download the Tomcat websocket addon here:
http://central.maven.org/maven2/org/apache/tomcat/embed/tomcat-embed-websocket/8.0.29/tomcat-embed-websocket-8.0.29.jar
The war file is really just a zip file. So I used 7-zip to open the war file. Then navigate to the WEB-INF/lib folder inside the war file.
Copy the jar into the war. Drag and Drop the tomcat-embed-websocket-8.0.29.jar into the lib folder of the war file inside 7-Zip.
Z-Zip will ask if you really want to copy the jar into the war file.
Say Yes.
Here is the compiled war file complete with the tomcat-embed-websocket-8.0.29.jar ready to deploy on Heroku:
http://ray.hulha.net/WebsocketHome.war
I used this command to deploy it:
heroku war:deploy WebsocketHome.war --app websockethome
Make sure to replace the app name in the end with your app name.
And here is the working result:
http://websockethome.herokuapp.com/
Heroku does not require Play framework to use Websockets. That is just an example. As long as your app from the Oracle tutorial binds to $PORT it should work.
I have developed a dynamic web project using eclipse and i am having a domain name and a web hoster. all i want to do is to upload my eclipse project to my web hosting site. Currently i am using html 5 template on my website but i want to upload my own project on it. I have heard that we can do it by using war file but i am not sure how to do it as my html 5 template contains many html page like index.html and it is more in size as compare to war file which i have exported. Please tell me i am totally clueless about it
Your web host needs to support Java and some Servlet container. If they don't already have those two things installed, you'll need to install them yourself. Once that is done, in Eclipse, you will need to export your project in the form of a .war file and place it in the appropriate folder of your Servlet Container. For example, with Tomcat, you would place it in its /webapps directory. You then start your Servlet Container. Your web application will be up and running.
If your web project includes Java web technologies such as Servlets and JSP, you will need to
Build your war file first either with Ant, or Maven.
Then you can upload the war file to your web server using some type of deployment tool that is usually available on the hosting web server. For Apache Tomcat for example, you can use the Tomcat Manager tool to deploy your war file.
I am trying to do the spring security tutorial at this link.
In the section entitled "Running the Tutorial application without Spring Security", I took the following steps (adjusted for differences between the current version and the version that was in use when the tutorial was written):
1.) I downloaded the latest release of the Spring Security Distribution,
2.) found and unzipped a war file in the dist directory called spring-security-samples-tutorial-3.1.2.RELEASE.war
3.) Renamed the resulting folder spring-security-tutorial
4.) Created a general project in eclipse called spring-security-tutorial
5.) Imported all of the contents of the unzipped spring-security-samples-tutorial-3.1.2.RELEASE.war
6.) Right clicked on the project in eclipse and selected configure...convert to maven project
7.) Then right clicked on the project and clicked run as...
But there was no "run on server" option. (I had chosen a general project instead of a Dynamic Web Project in hopes of preserving the file structure of the application to be imported)
I then started to repeat the process, but creating a Dynamic Web Project instead of a general project, and eclipse wants me to select the "src folders on build path". The file structure of the web application has 8 .class files in subfolders of WEB-INF, and I am not able to locate any .java files.
What steps can I take in order to download this and run it in eclipse on the server? With the ability to edit the classes?
I have read that I can select a .class file in eclipse and it will open the bytecode in the editor, so I imagine I can convert the class files to java files easily enough. But doing that within a general project triggers the error message that the class is not part of the classpath, so we need to get it in a working web project that can be run on the tomcat server from within eclipse first, I think.
A war file is a Web application ARchive (basically a zip). It is meant to contain a web application's compiled class files and resources (properties files, jsps, css, html, js, etc.). It a package that can be used by an application server (or servlet container) like Tomcat. Except through a Decompiler, you will not have access to the source code from the compiled .class files.
I doubt you can run this on Eclipse's Tomcat instances. Instead go to your Tomcat installation. Mine is at C:\apache-tomcat-7.0.22. Rename the war to something simple like security.war and place it inside the webapps folder, ie. C:\apache-tomcat-7.0.22\webapps\security.war. Go to C:\apache-tomcat-7.0.22\bin and execute the startup.bat Windows batch file. This script sets up the classpath and launches a Java application containing all the applications in webapps. You can see the startup logs in C:\apache-tomcat-7.0.22\logs\catalina.out (as you would normally in Eclipse console).
You can then go to localhost:8080/security to hit the application. Replace 8080 with whatever port you're configured on. security is the same name as the war file. When Tomcat starts (based on a config parameter) it will extract the war into a package directory under webapps with the same name.
You can play around with configuration settings. Some of the important ones are here.
You can shutdown Tomcat by running the C:\apache-tomcat-7.0.22\bin\shutdown.bat Batch file script. You'll have to do this and restart if you change something in the application (ex. the web.xml or a properties file).
I think the tutorial you linked was meant more for trying security settings than actually changing the source code. I'm sure there are other samples online for Spring security, I just don't know them.