Solved

How to find packages/class files?

Posted on 2003-12-11
14
606 Views
Last Modified: 2010-03-31
I've been compiling JAXB auto generated code and keep having to hunt down the jar files for specific JAXB packages and or class files.  Latest example that the compiler is complaining doesn't exist is "com.sun.msv.datatype.xsd.TimeType".  I'm using the latest Netbeans IDE under Windows 2000.  Anyone know of a utility and or way in Netbeans to hunt down and or look up these class files?  
0
Comment
Question by:Taurus
  • 7
  • 5
  • 2
14 Comments
 
LVL 15

Expert Comment

by:jimmack
ID: 9924357
I've written an application that does exactly what you're looking for (for exactly the same reason).

I haven't sorted out the packaging for distribution yet because I've been "busy" doing other things.  Your question has prompted me to get on with it.  If I can get it sorted out before you get another alternative, I'll post again to let you know where to download it.

(Eventually, it will be freely downloadable from my web site - when I get that updated too ;-))
0
 

Author Comment

by:Taurus
ID: 9924807
That would be nice.  When do you think you will have it?  I did do some searching and found:
http://www.zipscan.co.uk/
I may use it, unless yours is done soon or I can figure out how to make the Netbeans IDE do a search.  It will search Jar files but it seems one must mount them directly which is pretty tedious and creates a multistep process when it should be one step.

On another note, do you know if likewise there is a utility to show just which classes an application utilizes, and extract them to a temporary directory so that they can be repackaged into one compact .jar? Or will just do it without the temporary directory.  FYI and for reference here is an application that used to do something similar:
http://www.zipscan.co.uk/
0
 

Author Comment

by:Taurus
ID: 9924862
Whoops the second URL above was supposed to be: http://www.obsolete.com/people/cansdale/java/class_spider/index.htm
0
 
LVL 15

Accepted Solution

by:
jimmack earned 100 total points
ID: 9924881
>> On another note, do you know if likewise there is a utility to show just which classes an application utilizes, and extract them to a temporary directory so that they can be repackaged into one compact .jar?

I wish!  ;-)  I could have done with that for this packaging problem :-)

OK.  I've got the package together.  You can download it (temporarily) from:

http://www.ossmobile.co.uk/ClassFinder/ClassFinder.zip

I would really appreciate it if you could provide some feedback on it.

To any other experts who may be considering downloading this application - I would appreciate it if you could hold-off for now.  The tool is still not ready to be released into the wild.  However if you insist on looking at it, I would consider it a professional courtesy if you would also provide feedback.
0
 

Author Comment

by:Taurus
ID: 9925140
I downloaded it and tested on the class I just was trying to find.  It worked excellently.  Big thanks, it will be a real time saver.  

Per feedback, here are some minor suggestions(I'll e-mail you directly if I have more):
1) Per removing sources, it would be nice if one could use the delete key or be able to right click and get a context menu with a delete option.
2)  Maybe add the capability to be able to put in multiple search strings at one time.
3)  Maybe add a button to clear the results window.
4)  When you distribute the Jars you might just mention the location of the file that contains the main method.
0
 

Author Comment

by:Taurus
ID: 9925294
Does anyone know a way to get the list of class dependencies from the compiler?  Given that information it would be easy to extend this application so that it would create a jar with "only" the necessary classes. :)
0
 
LVL 4

Assisted Solution

by:tapasvi
tapasvi earned 30 total points
ID: 9925966
This code finds a given class file in all the jar files under DIR_NAME.

you may need to change DIR_NAME field.

---------------------------------


import java.io.File;
import java.io.IOException;
import java.util.jar.JarFile;
import java.util.Enumeration;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.StringTokenizer;

public class TestJar
{
   public static void main(String[] args)
   {
            if(args.length != 1)
            {
                  System.out.println("USAGE: java TestJar <class file name>");
            }
            else
            {
                  JarFile   jf = null;
                  Matcher m = null;
                  String token = "";
                  StringTokenizer st = null;
                  StringBuffer sb = null;
                  final String DIR_NAME = "\\\\bng-tv4850\\bea\\weblogic81\\server\\lib";
                  File dirName = new File (DIR_NAME);
                  String[] fileList = dirName.list();
                  Pattern p = Pattern.compile("[a-zA-Z]*"+args[0]+"[a-zA-Z]*");
                  try
                  {
                        //System.out.println("Directory content is ");
                        outer:for (int i=0; i < fileList.length;i++)
                        {
                           sb = new StringBuffer();
                           //System.out.println(fileList[i]);
                           if(Pattern.matches("[a-zA-Z]*[.]jar", fileList[i]))
                           {
                                    jf = new JarFile(DIR_NAME+"\\"+fileList[i]);
                              inner:for (Enumeration e = jf.entries(); e.hasMoreElements() ;)
                                  {
                                           sb.append(e.nextElement());
                                     }
                                    st = new StringTokenizer(sb.toString(),"/");
                                    while (st.hasMoreTokens())
                                    {
                                          token = st.nextToken("/");
                                          m = p.matcher(token.trim());
                                          if( m != null && m.matches())
                                          {
                                                System.out.println(args[0] +" file is in "+jf.getName());
                                                break outer;
                                          }
                                    }

                               }
                        }
                  }
                  catch(IOException e)
                  {
                        e.printStackTrace();
                  }
            }
   }

}
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Expert Comment

by:tapasvi
ID: 9925983
Hi to Taurus from a Taurus ;-)

http://classycle.sourceforge.net/ may be useful to u for class dependency find.

I havent tried it out myself..:-(


0
 

Author Comment

by:Taurus
ID: 9926037
Thanks tapasvi, I'll check it out.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9927481
;-)

Thanx Taurus
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9927653
Taurus,

  Thanx for the suggestions :-)  I'm glad (relieved ;-)) it worked.  I would appreciate it if you could let me know:

  1) What OS have you run it on (I've only given it a good hammering on Linux)?
  2) Do you think that the way it was packaged was acceptable?
0
 

Author Comment

by:Taurus
ID: 9929759
I ran it on Windows 2000 Server.  When you say packaged, do you mean the UI or the jar files?  I just unzipped the jars to a directory, mounted them with the Netbeans IDE, located the file with main(), and ran it.  I didn't have webstart loaded so it wasn't a one step process.  Webstart was included with the JDK&Netbeans distribution, but it didn't install.  
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9931560
Oh, OK ;-)

I packaged it into a jar and included a readme file for running it from the command line.  If it worked with no problems from within Netbeans, that's even better news ;-)

I've put in two of the changes you suggested - delete key and clear button.  I'll post on this question again when I've published it properly on my web site.

Thanx again.

Jim.
0
 

Author Comment

by:Taurus
ID: 9932646
I briefly tried the classycle app that tapasvi referenced.  It seemed to spit out a list of class dependencies that looked, at a glance, correct.  I would further refine my suggestion regarding the app allow multiple search queries at once and then have an option to select one or more search result classes and have them extracted to a designated directory.  You would need to create subdirectories under the designated dir, to match the package hierarchy or have that option at least.  This would be great don't you think:)

Whether or not you do this your app. is a life saver.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now