Showing posts with label find. Show all posts
Showing posts with label find. Show all posts

Thursday, November 26, 2015

Find all Java classes implementing a given interface.... reflections!

https://code.google.com/p/reflections/

Download the ÜBER JAR here https://code.google.com/p/reflections/downloads/detail?name=reflections-0.9.9-RC1-uberjar.jar&can=2&q=


package pierre.reflections;
import java.net.URL;
import java.util.Set;

import org.reflections.Reflections;



public class FindInterfaceImplementations {
 public static void main(String[] args) {
  Reflections reflections = new Reflections();
  Set<URL> urls = reflections.getConfiguration().getUrls();
  for (URL item : urls) {
   System.out.println(item.toString());
  }
  Set<Class<? extends javax.enterprise.inject.spi.InjectionTargetFactory>> classes = reflections.getSubTypesOf(javax.enterprise.inject.spi.InjectionTargetFactory.class);
  System.out.println(classes.size());
 }

}



This version will load only classes under the "oracle" package:



package com.pierre.typequerylanguage;

import java.io.File;
import java.util.Set;

import org.reflections.Reflections;

import oracle.ucp.ConnectionAffinityCallback;

public class FindInterfaceImplementation {
 public static boolean VERBOSE = true;

 public static void main(String[] args) {
  if (VERBOSE) {
   System.out.println("searching in the following jars:");
   System.out.println(System.getProperty("java.class.path").replace(File.pathSeparatorChar, '\n'));
  }
  Reflections reflections = new Reflections("oracle");
  System.out.println("searching now");
  
  
  Set<Class<? extends ConnectionAffinityCallback>> classes = reflections.getSubTypesOf(oracle.ucp.ConnectionAffinityCallback.class);
  for (Class clazz : classes) {
   System.out.println("found: " + clazz.getCanonicalName());
  }
  System.out.println("searching done");
 }

}





Thursday, November 1, 2012

find: missing argument to `-exec'

the syntax is:
find . -name *.xml -exec grep 7013 {} \;
MAKE SURE YOU ENTER THE SPACES EVERYWHERE, and the \ before the ;
crazy, uh?

Thursday, March 1, 2012

Recursive find and replace in files

If you need to make a change in all your OSB artifacts:

copy the sbconfig.jar in an empty folder
jar xvf sbconfig.jar
rm sbconfig.jar

perl -p -i -e 's/originalString/targetString/g' `find . -name '*' -type f`

jar cvf sbconfig.jar

done


if originalString contains / (like /bla/bly ) you can do this: \/bla\/bly

Saturday, February 18, 2012

find: paths must precede expression

the command
find .
recursively print all files starting from current directory

find . -name *.txt

should theoretically print only the .txt files.

It fails from the shell prompt with
"find: paths must precede expression"

this must be because the shell explodes *.txt before evaluating find.

Workaround: enclose '*.txt' in quotes

find . -name '*.txt'

Saturday, July 31, 2010

Bash shell tricks

Tarring files recursively with filter

to create:
find . -name *.out | xargs tar cvf cohservernodes.tar

to append:
find . -name *.log | xargs tar rvf cohservernodes.tar

to list:
tar tf cohservernodes.tar


Find a text in files, recursively:

find . | xargs grep -s whatever



find and replace recursively

for file in $(grep -il "whatever" *.txt)
do
sed -e "s/Hello/Goodbye/ig" $file > /tmp/tempfile.tmp
mv /tmp/tempfile.tmp $file
done

how about:

perl -p -i -e 's/oldstring/newstring/g' `find ./ -name *.html`

the above command works very well, but if you try

perl -p -i -e 's/oldstring/newstring/g' `find ./ -name *`

you get the error:

Can't do inplace edit: bla is not a regular file, <> line

because it tries to change also the directories

To do a find excluding directories you must do this (add -type f):

perl -p -i -e 's/oldstring/newstring/g' `find ./ -name * -type f`

Tuesday, October 6, 2009

find class or classes in jar for Unix or Windows

http://www.inetfeedback.com/jarscan/ on Unix


Examples ...
# To display the help message type:
java -jar jarscan.jar -help OR java -jar jarscan.jar
# To find the class ArrayList starting from the root of your c: drive type:
java -jar jarscan.jar -dir c:\ -class ArrayList



http://www.idesksoft.com/classfinder.html on Windows


Also, this command works on Linux:

find / -name '*.jar' 2> /dev/null | while read jarfile; do if jar tf "$jarfile" 2> /dev/null | grep FabricMeshUtils; then echo "$jarfile"; fi; done

(maybe you want to add a "| grep jar", otherwise it returns also .class files.

To dump all classes preceded by their jar file name:
find /acme/appsrv/bin/wl12.1a/ -type f -name '*.jar' | while read jarfile; do echo "$jarfile"; /acme/java/jdk170_71-64b/bin/jar -tf "$jarfile" ; done > /tmp/alljars.txt

Last but not least the great jar-explorer https://code.google.com/p/jar-explorer/wiki/HowToInstall, or rather https://github.com/javalite/jar-explorer. just run:

java -jar jarexplorer-0.7-BETA.jar

and remember that to search a class with package names you have to use the / and not the . as separator.

This command works also wonderfully:

find /cs/cfw/ -name "*.jar" -exec grep -Hls MyClass {} \;