1

Am not using any IDE and trying to fix some errors for a deployed war file in tomcat. I am trying to look for source of a package and Erroneous line seems to require parameters and has been imported from some package like

import com.somefirm.somepackage.someClass;

Following questions did not have answer my question:

In eclipse determine which jar file a class is from

How can I find files imported in a java class

I want to know is there any way I can find source of import manually. Is it even possible or not? How does a class look for packages to import?

Edit 1: Separated the links with a newline.

Edit 2: "am not using any IDE at the moment" was a bit late in the question. SO added Am not using IDE to first line.

Edit 3: Provided more clarity to the question, as to why I am needing it.

Edit 4: Added these edits. Thanks to @Jude-niroshan and @ErwinBolwidt

Ayushya
  • 9,599
  • 6
  • 41
  • 57
  • 2
    With most IDEs if you `CTRL + click` into the `someClass` of your import statement, the IDE will open the source for that class (either decompiled or maybe actual source, if you linked the dependencies to source code). You can then cross reference with your directory structure to see which JAR is providing this class. – Tim Biegeleisen Jun 26 '17 at 02:59
  • @TimBiegeleisen Am not using IDE. – Ayushya Jun 26 '17 at 03:08
  • 4
    @AyushyaChitransh It's is **really** annoying and bad form to change the meaning of your question to invalidate existing answers and comments - especially when you do not indicate that you have edited your question, – Erwin Bolwidt Jun 26 '17 at 03:09
  • 1
    There is a tool called Jar Finder (or something similar) which can search for classes in a folder full of JARs. I think this might be only your only option, to search for your class in all your JAR dependencies. Note that if you were using something like Maven or Gradle this would be much easier. Consider making the switch if possible. – Tim Biegeleisen Jun 26 '17 at 03:10
  • 2
    And no, your question before editing said "and am not using any IDE **at the moment.**" - so suggesting you how to use an IDE for this is a perfectly good response to your question. – Erwin Bolwidt Jun 26 '17 at 03:12
  • 1
    classes are resolved from the classpath at runtime. if you are limited to "tools already on the box", as jar files are simply zip files you could use a zip command (or the jar command in the JDK) to list the contents of each jar within the war and grep for the directory / filename (which the JVM maps to package and classname) – slipperyseal Jun 26 '17 at 03:12
  • How can you have an erroneous line in a deployed WAR file? And why aren't you using an IDE? – user207421 Jun 26 '17 at 03:16
  • 1
    @EJP the war file was not able to make connection, and it is using an applicationContext.xml which defines some values whose parameters are defined in a class in `org.gk.persistence.MySQLAdaptor` I am looking for that class in the folder which was generated when war file was served. But I may tried too hard to not be specific to my problem. – Ayushya Jun 26 '17 at 03:27
  • 2
    @ErwinBolwidt By using "and am not using any IDE at the moment." I indicated that I do not want answers related to IDE. But people probably did not read full question. So I edited to make it more clear about that point. I am new to SO and did not know that I should have indicated about edits in the question. – Ayushya Jun 26 '17 at 03:53
  • 1
    I looked at the edit history, looks fine to me. Adding the bit about a deployed WAR file seemed to change the meaning more then your clarification. – Ryan Leach Jun 26 '17 at 04:52
  • @RyanTheLeach I did not know about a how folders created by war files are different from normal java application, so I was looking for a general answer as to where these packages that are imported come from, but it seems that a lot depends on the context in which JAVA application is being used. Should I add the error I am getting, if that helps? – Ayushya Jun 26 '17 at 05:18
  • I appreciate the quick accept. – GhostCat Jun 26 '17 at 07:03

1 Answers1

4

The point is: the exact location of a class is determined by your class path setup.

You define at some point which classes are available when compiling your application respectively which classes to ship with it.

So, when you are not using an ide - you have to search the "elements" in the class path that gets applied for your build. For example by looking into each jar file.

Given your comments: I think you have to step back. You seem to lack basic knowledge of Java. You have to understand how that WAR file is built. There should be some sort of build description; containing the dependencies and other contents of the WAR delivery. You have to analyse those. Beyond that: if these packages are from your team/company/... a simple file search might do the job. If those packages are "external", like open source libraries - then you might try to simple google for the class name; or turn to grepcode.com.

And the other thing you asked: a compiled class contains only fully qualified class names. There are no import statements in class files any more. So when a class "needs" another class, it asks the JVM to load that class (given the fully qualified name). And the JVM simply looks into the classpath, and loads the first class that matches the given name.

GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • I guess that means I have to look into the jar files for "elements" where _class path_ is defined. And jar files refer to those which were used to build war files? Will they not be found in the folder which was created when war file was deployed? – Ayushya Jun 26 '17 at 05:35
  • 2
    See my updates. But my gut feeling is: you have to **seriously** do some learning first. We can't explain problem solutions to you, when you are lacking the skills to understand them - because your knowledge of java is so restricted! – GhostCat Jun 26 '17 at 06:28
  • @AyushyaChitransh Got another small update, regarding imports within compiled classes. – GhostCat Jun 26 '17 at 07:00
  • I am new to JAVA and have not even built war files, I am using a script from https://github.com/reactome/container/blob/feature/tomcat/java-application-builder/maven_builds.sh to build war files in the same project. – Ayushya Jun 26 '17 at 07:04