Where does Eclipse store generated servlet files for Tomcat? - java

I'm using Eclipse Java EE IDE and launch Tomcat from the Server's tab on Eclipse.
Where does Eclipse store generated servlet .java files for JSP files? I've checked the Tomcat installation directory, but nothing there.
Thanks.

Doubleclick the server entry in Servers view and check the path represented by Server path. Explore in there from inside the workspace directory. The generated classes are there.
If you choose the 2nd option Use Tomcat installation, then it will be available Tomcat's /work folder, there where you expected it to be.

go to your application work space directory(not eclipse installation directory) in windows explorer(not in eclipse IDE explorer).
in my laptop it is d:/applicationdata/j2ee
then follow the path as:
work space directory(in my case j2ee)/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/catalina/localhost
here u will find your application

Eclipse doesn't generate servlet files for JSP files. Validation happens directly on JSP syntax. When a JSP is deployed to an app server like Tomcat, the server may choose to generate servlet files to disk, but that is not required. The generation and compilation can happen in memory or the app server may even compile JSP files directly to bytecode.
I don't know specifically about Tomcat, but if it does generate servlet files to disk, the temporary directory containing these files will be somewhere under your Tomcat install.

/home/waheguru/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/Catalina/localhost/jspnotes/org/apache/jsp
localhost or your website name,
project name is jspnotes, whatever your project.
This path is shown in Linux Mint.

Check META-INF\context.xml file from your work space. There will be path metioned like below
workDir="C:\apache-tomcat-7.0.39\work"
In above path you will find the package structure of your project and in it there will be both *_jsp.java and *_jsp.class

Related

Rest service in Java runs from Tomcat server but not inside Eclipse

I am unable to find another article that solves my problem but am happy to hear about one if you know the answer.
I have a RESTful service built in Java with Eclipse. It uses Spring and all of its bells and whistles.
After much work with configuration files, I am able to build the service into a war file, deploy it to my Tomcat webapps folder, and run it from standalone Tomcat. However, it still throws several errors on start when I try to start it from a service defined within Eclipse. The errors are the same errors that I was seeing before I got the config files correct for standalone Tomcat. The errors are about the inability to create the required beans because of references to properties that can't be found.
How did I get it running in Tomcat? I added a couple of .properties files to define properties needed by the beans that get launched at startup and then added a 'set CLASSPATH=...' line to the setenv.bat file in the Tomcat bin folder. This new line adds the properties files into the CLASSPATH. That seems to have fixed everything from standalone Tomcat.
So, my question is, "How do I make these same changes inside my Eclipse server?" I have added the properties folder with the property files under the config folder in Eclipse, just like it is in my native Tomcat folders, but I do not know how to modify the CLASSPATH string to specifically point to my .properties files (as I have done in the setenv.bat file for standalone Tomcat).
I think I understand the problem, but have no idea about the solution.
Thanks for listening.
Dave
Eclipse does not use any *.sh/*.bat files to startup Tomcat. In order to modify the way the server is started you have to open the configuration UI of the server by double-clicking on the server in the Servers view.
From there you will be able to modify the classpath of the system classloader through "Open launch configuration".
Another important setting is "Server path" which tells Eclipse, the value of $CATALINA_BASE. You can modify it only after removing all modules and cleaning the server. It is useful to set it to an easily accessible directory: this way you can verify directly that Eclipse didn't mess up your application deployment (sometimes it "forgets" to copy some libraries).
The "Configuration path" setting tells Eclipse where to find the files (but not subdirectories) that will be copied into $CATALINA_BASE/conf.
Remark: if your application requires you to add libraries to the top classloader, there is probably a problem in your project. The "missing" libraries should be added to WEB-INF/lib of your application instead: look into the "Deployment assembly" of your Eclipse project configuration.

decompiler project run on tomcat

I have a java project which can run on tomcat and the project now have some problem which need me to fix. They give me a ROOT file to replace the root on tomcat to let the project run.I have all the .class file and I can decompiler to see them.But, how can I put these code into eclipse and run them as a web service? Jdk version:1.6.0.22 and Tomcat version:6.0.0.29
Actually you can do that. Create an eclipse Dynamic web Project, copy all the sources and paste to src folder project.
Go to the WEB-INF/lib of your app and copy all the jar files and paste to WebContent/WEB-INF/lib folder.
Verify the WEB-INF folder of your app because maybe there are jsp or html files in there, in case of that please copy all them an paste to WebContent/WEB-INF
Now the challenge will be the jdk version and tomcat version that are old, try to use the same versions on your development environment otherwise it will be kind of dificult to put the change to production environment.
Then try to run, it will throw a lot of errors, verify them and keep looking other dependencies maybe the configurations on web.xml, or server.xml. Sorry but its a very detail process, its not automatic.
Note: if you need only to change a .class file, then change it and compile it and just replace the .class file on production environment, avoid to replace the entire project, and remember, if you make any change on production please restart tomcat and verify log files, and again verify log files it will save a lot of time and effort.
Hope it helps.

Update files on a tomcat server, via Eclipse

I've recently found out how to remotely debug my java files on a Tomcat server via eclipse and was wondering something. I am wondering if I could import the same files into Eclipse that are currently housed in the webapps folder on my tomcat server, and instead of having to go to that filepath anytime I need to make a code change with the files in the tomcat server, be able to make them directly in Eclipse which I would be using to debug anyway.
Currently I've tried importing the same project folder from the webapps folder in Tomcat into Eclipse and made a small code change, relaunched my server, but am not seeing the change in my tomcat library.
When importing into Eclipse does it make it's own separate instance of the files, instead of actually being able to import the same exact files as in the tomcat server?
If you double-click the Tomcat server in the 'Servers' view inside Eclipse, you will see a configuration tab "Server Locations".
By default, eclipse doesn't make changes to the tomcat 'webapps' folder, it uses folders under its workspace.
Changing that option to 'Use tomcat installation' will make the changes be visible from the tomcat/webapps folder on your file system.

Eclipse Java Servlet access to higher level directory

I've installed Eclipse with web development and during download have installed Tomcat7 to dir E:\Eclipse\tomcat7.
When in Eclipse and trying to test the program I'm getting a realPath of
C:/Users/user/Documents/eclipseJEEWorkspace/javaWebPages/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/org.example.web/WEB-INF/classes/
as my real path and not what I expect which is E:\Eclipse\tomcat7\webapps\org.example.web/WEB-INF/classes/
1) how do I get the real path of the servlet rather than the temporary path...
or am I missing something with how Eclipse uses the installed server? If this is the way then do I have to continuously create the WAR and fiddle around recreating/deleting all the time?
The reason for this is I'm also trying to get a JAVA Servlet getting access to a file in a path higher than webapps. I'm new to servlets....
My development includes third party software that all reference an individual file our.properties so changing the structure is unfortunately not a option.
My directory structure is:
/tomcat
/mycompany
/properties
our.properties //the file we want to access
/*otherfiles
/html
/*not used in this context but to show usage
/javascript
/*not used in this context but to show usage
/webapps
/org.example01.web
/META-INF
/WEB-INF
/org.example02.web
/META-INF
/WEB-INF
/org.example03.web
/META-INF
/WEB-INF
How do I tell my Servlet to access the our.properties file?
I've tried getPath, getResource but without getting the first bit to work, I doubt I'll be getting anywhere fast.
Thanks
When you run Tomcat under Eclipse, via the Tomcat plugin, the webapps path is changed. Eclipse uses .metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ folder to deploy the project. That's not a temporary path, it's the actual path since your web application is deployed there.
If you run tomcat from command line, or as a service and deploy your web application, you'll see that the path of the servlet will be as you expected.
In order the change the default path to deploy for Eclipse, double click to your Tomcat under Servers view and modify Server locations section.

Website directory structure different from eclipse

I am coding a website using java servlets and am using eclipse and tomcat. When I test it using localhost, it works fine. But when I am deploying it on my actual website, the directory structure is messed up and the files are not called properly.
My eclipse directory structure on localhost is
Project Name
.src/packageName/java files
.WebContent/HTML files.
When I make a call from the html files, I use the relative location and tomcat automatically knows to look in the src/packageName folder. For example, from the /WebContent/login.html page makes a onClick call as follows,
. This will automatically trigger the java file in /src/packageName/welcome
When I am deploying it in my actual website, the WebContent/login.html is throwing an error WebContent/welcome file is not found. How do I tell my website to search in /src/packageName folder?
Hmm...have you been sure to package the application as a war for deployment.

Categories

Resources