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
Related
Grails newbie here. My application is in Grails, my IDE is IntelliJ IDEA. I configured my project (in IntelliJ) to say that my resources folder is under root\src\resources. I have an image file in there that I need to load into an InputStream / BufferedImage. However I can't seem to get to those resources from my Grails controller. This is what I was trying:
def image = this.getClass().getClassLoader().getResourceAsStream("image.png")
But that just returns null. I use this exact same convention in Java projects (well, except I have to declare image being of type InputStream), and it does work there. I was under the impression that I could essentially drop Java code in a Grails project and it should just work. What do I need to do differently to get this to work in my Grails controller? I need to access that static resource file.
If you mark a directory as a source directory in IntelliJ IDEA, Grails won't know about it. You have to configure Grails properly by either adding your new directory as a source directory or move the resource to one of the standard source directories.
I've never actually added a new source directory myself, but the answer to this stackoverflow question looks promising.
Other than that, you can just add resources to any source directory and it will be included, for example: grails-app/conf, src/java, src/groovy and more. In addition, any file in web-app/META-INF/classes will also be in the classpath of the application. The last one is great to know about if you need to copy a java or groovy source file (i.e. just copy, no compilation).
Try this
servletContext.getResourceAsStream("/WEB-INF/resources/yourfile")
I have to use a Javascript file in my GWT Project. This Javascript is in a common library project and I deploy it together with my GWT Project using ANT.
So, I have no problem in production environment: but I cannot test it in development phase.
I tried to create an Eclipse link to Javascript resource but seem that GWT "can't see it".
Some behavior with other kind of resources (images, css etc.).
Is it a bug or is there another way to do?
I'm using Eclipse Juno, GWT 2.5.0 and Debian 7.0.
Thank you.
Can you just use script tag in your project's .html file?
If you're using some kind of source control, it usually has a way to make a link to a dependent project or file. Simply include that link in your GWT Project, and reference the file through there.
If you can't or don't want to do it through your source control, do it through your OS. Since you're using Linux, simply make a symbolic link to the common file/folder using ln -s (if you were using Windows, you'd need to run mklink from the command line), and reference the file that way.
In either case - source control or OS - you'll be able to see the file(s) when you refresh your project in Eclipse, and modifying one will modify the other in its own directory.
Edit - information on symbolic links in CVS
I haven't played with CVS in quite some time, so can't speak much about its capabilities for symbolic links. A bit of googling said it's not supported, though there are workarounds. One workaround is to add script files that run during checkout. That sounds like it may still be tough to make OS-agnostic. I did find one site that mentioned using module aliases to get the same result. Maybe that will give what you need. An excerpt from the site follows:
One common way to handle situations like this in CVS is to alias the
collection in a modules file rule. -Checkout the "CVSROOT" module and
you'll find the "modules" file; simply change it and check it in like
anything else, with the exception that when you check in CVSROOT files
they "activate" at the same time. The example below may look a little
kludgy, and it is because AFAIK you can't redefine a directory and alias
it at the same time, sadly. I'll use a typical Java situation as its
package system lends itself well to this kind of thing:
Real module directories are "a", "b", and "common"
Directory alias for all common srouce
_common_src_all -d src/com/mycompany/common common/src/com/mycompany/common
Full "A" project including common
a_all &a &_common_src_all
Full "B" project including common
b_all &b &_common_src_all
I'd like to package my Java EE6 web classes (beans, filters, servlets) into jar and place it into /WEB-INF/lib/ directory along with other utility jars and abandon /WEB-INF/classes/ directory totally.
Are there any substantial differences between the two in terms of classloading, acessing application context, etc?
Thanks.
PS: Whenever googling any of java specs I'm always redirected to Oracle documentation index which is dozen clicks away from original url. Anyone knows what's happening there?
I'd go for /WEB-INF/classes. It allows you to run your application in debug mode and hot-swap classes on change. If you package everything as a jar, you'd have to repackage and redeploy the app every time you change a class.
Well, shortly: Imagine you have class org.example.Test.class, if you put it into jar and in WEB-INF/lib/ directory, and copy the same class into WEB-INF/classes/ then classloader of that application will use last one (from WEB-INF/classes/).
Sometimes you can use it as advantage - I have a library, and it has a bug... I look for source of that class (where bug is; I miss the part of how I know that bug is in that class, that's another story), I add that class to the project with fixed code, and it is compiled into WEB-INF/classes/ while library still exist in WEB-INF/lib/. Fixed class will be used until library will be fixed.
In Tomcat Servlet container's definition: WEB-INF\classes is searched before WEB-INF\lib. You can choose to delegate your classloading to your custom classloader - even then the order above is maintained.
If you choose to go with a different provider e.g. JBOss, Glassfish, Jetty it might have a different order, but I am not sure about those.
we have downloaded jar files for lambdaj and its dependencies which are again jar files.
we do not know how to go about it. we have copied these files in the
C:\Program Files\Java\jre6\lib\ext
have set the class path in environment variales as:
variable: classpath
path: C:\Program Files\Java\jre6\lib\ext
but we do not know how to go further. we want to run some lambdaj programs.
can anyone suggest how to run lambdaj programs?
You would run a Java program that requires lambdaj in exactly the same way you'd run any other java program with an external dependency, i.e. by invoking the java executable passing in the fully-qualified name of the Main class, or the JAR with an appropriate manifest, or by deploying it in a servlet container, etc. Additionally you should be putting the LambdaJ JAR on the classpath for this invocation, not in the lib folder for your entire JVM.
What have you tried so far and why/how is it not working? Your question at the moment is a bit analogous to "I want to use Microsoft Word to view some Word documents, how do I do this?".
Update for comment 1: You said "it's not working". That doesn't help anyone address your problem as it gives no clue what you expected to happen and what you observed, only that they were different. As for where JAR files can be stored - you can put them in any directory, so long as that directory is on the classpath (or you add it to the classpath) of the Java application that runs. The canonical place to put external dependencies is in a folder called lib below the root of your project, but the important thing is that you choose somewhere consistent and sensible.
It sounds like you don't quite grok Java and classpaths yet. If you have followed some tutorials and are still stuck, ask for help to let you understand. Adding more detail to your question, including the layout of your files, the commands you issued, and the response that came back would be useful too.
If you are using Netbeans create a project and right click on the Libraries folder within the desired project. Click Add JAR/Folder...
I was unfortunately forced to result to uploading a WAR file as my backup for a web application I am working on.
Luckily I have the most recent WAR file available. I am using Eclipse IDE and am using the Web Tools plugin for all the J2EE work that I am doing with the Dynamic Web Application Project.
When I imported my WAR file, and ran it on a local server, everything works fine. The problem I a ran into is that in the Java Resources/src folder that all my packages and .java files were now only consists of all the same packages, but they are empty.
I checked to see if I could find the files and I found the .class files in an "Imported files" folder that is not accessible in the Eclipse Project Explorer. I believe that I need to do some type of build or something so that my .java files are available for me, but unfortunately this is one area where I lack.
One thing I would also like to know is, one way or the other, am I able to obtain the .java source code files if I have access to the .class files?
Also, I would like to configure this environment as it was before where my Java Resources:src folder contaiend the packages and .java files.
One thing I would also like to know is, one way or the other, am I able to obtain the .java source code files if I have access to the .class files?
The short answer is No. There is no way to regenerate original source files from bytecode files.
If you were really, really desperate you could try to use a Java bytecode decompiler on your bytecode files, but the result will be be nothing like your original source code.
All comments and javadocs will be gone.
All original code layout will be gone.
Original local variable and parameter names may be gone, depending on your original compiler switches.
Constant expressions may have been pre-evaluated, and loops, string concatenations and other constructs may have been transformed unrecognizably.
Depending on the maturity of the decompiler, the Java code might not be semantically equivalent to the original code, and might not even be compilable.
I hope you haven't spent too long developing this application because the best answer may be to start again.