Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java code - looking for source code

Tags:

java

jsp

tomcat

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.

like image 694
Luca Matteis Avatar asked Oct 27 '10 08:10

Luca Matteis


People also ask

Where can I find Java source code?

Install the Java SE Development Kit from http://java.sun.com/javase/downloads/index.jsp. Once installed, you should find an archive called src. zip in the top of the JDK installation directory. The Java source code is in there.

How do I find the source code of a string?

Right-click in the source code area. From the pop-up menu, click Find. Alternatively, press the Ctrl+F keys. Enter the text you want to find in the Find dialog box.

What is Java source code in Java?

Source code refers to the high-level code or assembly code that is generated by a human/programmer. Source code is easy to read and modify. It is written by the programmer by using any High-Level Language or Intermediate language which is human-readable.

How is Java source code saved?

Java source code is compiled into bytecode when we use the javac compiler. The bytecode gets saved on the disk with the file extension . class . When the program is to be run, the bytecode is converted, using the just-in-time (JIT) compiler.


2 Answers

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)

like image 97
JoseK Avatar answered Sep 21 '22 12:09

JoseK


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.

like image 31
OmnipotentEntity Avatar answered Sep 22 '22 12:09

OmnipotentEntity