This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

JAR file

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the easiest way to find out if a desired class file is in a (or better in a number of) JAR file(s)?
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hmmm.....just now I answered a similar qstn in this post.
I would use a list. Not sure if there is a better way.
The std options for the jar command are:

regds.
- satya
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont think So there are any options to check only if a particular file exist or not.
What u can do is list all the file in ur jar file and check it if the required file is there or not.
eg :-
jar -vtf rt.jar
------------------
Sandeep Jain
 
Sandeep Jain
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont think So there are any options to check only if a particular file exist or not.
What u can do is list all the file in ur jar file and check it if the required file is there or not.
eg :-
jar -vtf rt.jar
------------------
Sandeep Jain
 
Frank Lin
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, it can be easily done with one JAR file by using the jar and piped find command in windows or grep in unix
jar -tvf rt.jar | find "ClassName"
But I was looking for some kind of utility program that searches all jar/zip files in the classpath and list them out. I guess I need to create my own.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is free java code "jwhich.java" which will help U locate the class file in the class path. Hope this may add to the info U have obtained.
---------------------------------
public class JWhich {
/**
* Prints the absolute pathname of the class file
* containing the specified class name, as prescribed
* by the current classpath.
*
* @param className Name of the class.
*/
public static void which(String className) {
if (!className.startsWith("/")) {
className = "/" + className;
}
className = className.replace('.', '/');
className = className + ".class";
java.net.URL classUrl =
new JWhich().getClass().getResource(className);
if (classUrl != null) {
System.out.println("\nClass '" + className +
"' found in \n'" + classUrl.getFile() + "'");
} else {
System.out.println("\nClass '" + className +
"' not found in \n'" +
System.getProperty("java.class.path") + "'");
}
}
public static void main(String args[]) {
if (args.length > 0) {
JWhich.which(args[0]);
} else {
System.err.println("Usage: java JWhich <classname>");
}
}
}
 
Ranch Hand
Posts: 318
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote this myself a long time back to "jwhich dir"

JWhichDir

see
http://www.geocities.com/kalpeshsoni/JWhichDir.zip
[ September 22, 2008: Message edited by: Kalpesh Soni ]
 
I found a beautiful pie. And a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic