Get the available functions/methods of java package in C#
I want to know tha开发者_StackOverflow社区t is it possible to get the classes, functions/methods available in a java package from C#. Suppose I have a java package p which contains SampleClass. I want to inspect this package from C# so that I can get SampleClass. I do not want to use this class in C# in fact I just want to get the name of the available classes and functions.
Hope this is possible!
Thanks
Assuming that you have a JDK installed, you can use 'jar -tf jarName.jar' to get a list of classes, which you can then parse.
To get more information about a particular class, you can use the command-line 'javap' utility to print out a list of all methods and fields. This is in a fairly easily parsable format. For example:
javap -classpath . com.prosc.io.ZipCreator
Compiled from "ZipCreator.java"
public class com.prosc.io.ZipCreator extends java.lang.Object{
public com.prosc.io.ZipCreator();
public java.lang.Integer getLevel();
public void setLevel(java.lang.Integer);
public void createZip(java.io.File, java.io.File) throws java.io.IOException;
public void createZip(java.io.File, java.util.zip.ZipOutputStream) throws java.io.IOException;
public void setMaximumZipSize(long);
static {};
}
If you are asking about Jar files. It is just a zip file.
You can map folders and files to class names like that: "/java/lang/Object.class" --> "java.lang.Object".
On this post you can read about listing the contents of a .zip folder in c#.
The advantage of this method is that you don't need to worry about JDK installed but if you are planning anything complex e.g. list of methods I would go for solution proposed by @Jesse Barnum.
精彩评论