Where are the generated JSP class files located? - java

I am using Tomcat 7.1 and Eclipse Indigo to develop a Java Web Application.
I just want to ask if anybody knows where the JSP translated files (the java files) are stored? Its often i receive exceptions indicating the jsp java file line, but if i can not see the file it is more difficult to correct the bug.

Doubleclick the Tomcat entry in Servers tab in Eclipse. You'll see something like this in Server Locations section:
If you haven't changed the server path and it thus defaults to Eclipse's workspace metadata, then the Tomcat's /work directory is not in Tomcat's own installation folder, but in the path as shown in the above screenshot.
Unrelated to the concrete problem, if you adhere the JSP coding recommendations and you avoid Java code in JSP altogether, then debugging will be so much easier, along with a lot of other advantages.

The JSP translated files are stored (in Tomcat) in /work/Catalina/localhost/[your_app_context]/org/apache/jsp/.
Should check in other containers or web servers.

you can find the jsp compailed java classes in your workspace:
And the path is: workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\auctuus\org\apache\jsp\jsp\gbp\settings

Related

Can I avoid redeployment of a project in WebLogic, if I only change JSPs?

I have a project that runs inside the WebLogic server. 80 % of changes I do to the code affect JSP files only (not the class files). Those JSP files contain the frontend logic.
Whenever I change the JSP page, I need to do the following steps to see my changes:
mvn install inside the source directory.
Redeploy the application in WebLogic Admin Console ("Deployments", "Update").
Is it possible to avoid these two steps, if the only thing I change are JSP files (I don't touch Java files therefore, no class files are modified)?
Note that the application in question is set up in WebLogic so that it reads the directory with the class files (myProject/target), not a WAR file.
I have no definite information whether or not JRebel supports WebLogic. Its only alternative known to me, DCEVM, does not support WebLogic according to the last statement here.
Update 1 (02.05.2018 15:23 MSK): Changing
<wls:resource-reload-check-secs>-1</wls:resource-reload-check-secs>
to
<wls:resource-reload-check-secs>1</wls:resource-reload-check-secs>
in myProject/src/main/webapp/WEB-INF/weblogic.xml didn't help. When I deploy the application, then make a change to a JSP file, then run mvn install, the changes do not take effect.
There is page-check-seconds properties in weblogic.xml (beside others). Take a look at "weblogic.xml"
If you run in dev mode and not prod wls will redeploy each time a jsp changes at source
No, for several reasons. JSPs have to be compiled. They are not simple html pages. They are also cached by the server. You most definitely have to redeploy the project.

Does Tomcat automatically compile java servlets?

I'm using Tomcat 7.0 with Eclipse. The tomcat server is synchronized with eclipse. After creating my first class, I put the .java file under src/(default package)/HelloWorld.java (not good practice I know but just for testing)
The content is just as follows, fairly simple:
import java.io.*;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
#WebServlet("/HelloWorld")
public class HelloWorld extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println ("Hello World");
}
}
Well many tutorials claim that I must use javac to compile the code. But I did nothing and it ran with no problem. Also everytime I change the code it updates immediately just like magic. Something must be working but I don't know what it is.
Yeah it's obviously a newbie question so any help is welcome. Also It's better if you have any systematical and easy-to-follow tutorial links. I'm searching for them for several days but got lots of inconsistent answers.
To me, You mix 2 main technologies - tomcat as a web container and eclipse as your IDE. Their integration confuses you.
Lets leave JSP for now and talk only about servlets, because it confuses even more
Tomcat cannot work with source files (*.java). You Must compile your application with javac for example and create something called WAR - web archive - a zip file that will contain your compiled class and adheres some EE standards that tomcat understands (its also possible to use folder instead of zip, but lets put it aside as well, its not relevant for this explanation).
Among others this war (once compiled correctly) will contain your compiled servlet class HelloWorld.class).
Once tomcat is started and recognizes your war file in deployment folder it opens it and loads in runtime.
No compilation, only runtime loading.
Now people talk here about JSP.
In fact JSP is something that is technically equivalent to servlet but resembles HTML.
You put the file with extension .jsp and build your WAR. java compiler can't read JSP files, so you should put them into your war file somehow (usually build tools/IDE do it for you). Bottom line is you have JSP files as you've created them in your war.
Now you put your war into Tomcat, it recognizes it as before and loads. At this point it still does nothing with your JSPs.
So, your war is deployed, tomcat is started and go to 'http://localhost:8080/myfirstjsp.jsp' from your browser
At this point (first invocation of your JSP) a lot of thing happen:
Tomcat gets your browser's HTTP request
Tomcat recognizes that it should process the JSP file
Tomcat parses your JSP file
Tomcat compiles it internally to some class file that you're not aware of (its stored internally in Tomcat),
Tomcat loads this file in runtime and treats it as a compiled Java class.
Next time you'll invoke the JSP, it will be already compiled.
The last question here is how Eclipse connected to all this story :)
In fact Eclipse has an integration with tomcat, so all the war-creating-and-deploying stuff is transparent to do. That's why you push 'play' on eclipse and it compiles your project, creates a war, makes sure tomcat is aware of this war (configures deployment related stuff), starts tomcat and voila! - you have you application working.
Its important to understand what happens at what level
Hope this helps
Mark
It looks like you are using the tomcat server plugin with Eclipse. In this case, as soon as you save your .java file, eclipse compiles it and updates the class files in tomcat server automatically.
Eclipse is an IDE, it does most of the things for you automatically like compiling the code, setting up classpath to include the required jar files etc.
If you want to follow the tutorials, I would suggest you use a plain text editor and a standalone tomcat server. Then, you will have to do all the steps mentioned in the tutorial(compiling the servlet class using javac, copying the .class file to tomcat server etc.)
No. Java EE container (Tomcat) cannot compile .java files automatically/implicitly. In fact the JSP engine of container will parse the JSP and generate the class file - JSP-wiki
Take a look at Eclipse Build Story.

How to refer a jar outside exe in Java desktop application?

I have a Java application installed. The jar is bundled into an .exe file using Launch4J. Now I want to create a patch for this application.
If I create another jar containing only updated files, how can I refer it in the original code?
I have java application installed. ..Now I want to create a patch for this application.
This is one of the strengths of the Java Web Start launch technology that comes with the J2SE. Simply update the Jar on the server, and the next time the app. launches, it will be updated.
The update can be honed for your use-case, configured to be done lazily or eagerly, before or after launch, or even programatically controlled using the JNLP API's DownloadService.
..And the jar is bundlled into an .exe file ..
'Unfortunately', JWS works on Windows, ..and Mac., and *nix - so you may have to expand your horizons.
BTW - I have no idea how to do the same with Launch4J, but then, that is really the wrong question. I aim to provide an answer to the right question, which is "How do I deploy & update a Java rich client?". ;)
I've never worked with Launch4J, however I think you should try to affect the classpath. JRE always loads the classes from the classpath. From this point of view, jars have no added value and just serve as a containers for your *.class files and resources.
Now, if you succeed to configure your tool to do something like:
classpath = C:\Temp\my_patch_path;$your_current_classpath
then its enough to put your changed files into C:\Temp\my_patch_path (of course preserving the package structure). JRE will load your classes first in this case.
Hope, this helps
Mark
It is might not be possible to do this without changing the contents of the exe.

WebLogic load jar without class file?

I'm currently working on a prebuilt application running on weblogic.
The application consist in NAME_APPLICATION.jar that must be deployed on weblogic.
My problem is that I can't analyze anything for the simple reason that the jar DOES NOT CONTAIN ANY .JAVA OR .CLASS FILE
The jar just contain the following files:
- APPLICATION_1.0.sources
- APPLICATION_1.0.space
- APPLICATION.ws
- GET_SOMETHING.ds
- GET_SOMETHING.service
I really don't understand it. Where is the application ? How weblogic knows the logic (forgive me the pun) of the app? How to edit the application and where is the source files?
It's the first time that I see such Jar file, it's probably because I'm a weblogic beginner
Thanks
These are resources that must be available on the classpath for the application to find them and access them. I am guessing that the documentation tells you to deploy it as a shared library.
If they are binary files (not text files that you could try reading with a text editor), then whatever application needs them obviously knows their format and how to read them.

Java code - looking for source code

I have this Java code some other person wrote, specifically JSPs. I am trying to understand where everything is.
In my index.jsp (the main file which is loaded) it imports a certain namespace (I suppose tomcat does all the compiling, I don't know):
<%# page import="org.sgrp.SearchResults"%>
This physical location doesn't exist in my CLASSPATH so I suppose it's referring to a namespace inside the .jar code structure (correct me if I'm wrong).
So how am I suppose to find the source code for this? Does Tomcat set a specific CLASSPATH location for each project?
EDIT
I'm trying to understand if Tomcat follows a certain structure so I can find where the source code for this stuff is.
From the perspective of a web
application, class or resource loading
looks in the following repositories,
in this order:
* Bootstrap classes of your JVM
* System class loader classes
* /WEB-INF/classes of your web application
* /WEB-INF/lib/*.jar of your web application
* $CATALINA_HOME/lib
* $CATALINA_HOME/lib/*.jar
from the Tomcat docs.
The most likely locations for classes specific to your application are the WEB-INF/lib/*.jar and WEB-INF/classes. However as others have mentioned, this will contain compiled class files and you wont be able to see the exact java source (even after decompiling)
jars are compressed javabyte code. In order to get the sources you'll have to decompile them. There are a few utilities out there, but working with decompiled code is a bit of a nightmare if you ask me, I wouldn't recommend it, especially not if you didn't already know this. :D
The source code will generally be stored elsewhere.
As far as your specific questions on Tomcat, I don't know, having never working with Tomcat before.
You can look for the jars in two places:
/web-inf/lib directory (it has all the custom jars in use by the app)
The build file (mvn, ant etc)
Source code might not be there at all. So, first of all, you need to find which jar exactly has that imported class. Then just search the web to find the project/API website. There you can look for the source, if its an open source library. Otherwise, decomplilation is the only option left, and that might not be very helpful.
class path is, in my experience, commonly set in the ant build file of each project

Categories