Solved

How to find packages/class files?

Posted on 2003-12-11
14
605 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>> 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 4

Expert Comment

by:tapasvi
Comment Utility
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
Comment Utility
Thanks tapasvi, I'll check it out.
0
 
LVL 15

Expert Comment

by:jimmack
Comment Utility
;-)

Thanx Taurus
0
 
LVL 15

Expert Comment

by:jimmack
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

743 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

17 Experts available now in Live!

Get 1:1 Help Now