简体   繁体   中英

Add jar to eclipse plugin

I am trying to write eclipse plugin. I need to use a jar file in my code. inside the

public class SampleHandler extends AbstractHandler {
    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {

The jar file is directly accessed using Process p = Runtime.getRuntime().exec(checkStyle_cmd); checkDtyle_cmd is String "java -jar"+"location of jar file"+ (some other stuff).

I created a 'lib' folder. Used it as source folder. Pasted the jar there. Added "/ProjectName/lib/jar_file_name.jar" to Classpath in Runtime. Did not work. So, also added /Test5/lib/checkstyle-7.1.2-all.jar in bin.includes build.properties. Still no luck. I get unable to access jar file error

It might be better to actually extract the code from the jar than to run it from the command line.

Within a .jar folder is the .class files of the byte code, this compiled from .java files and run by the VM.

You can use this website to decompile .class files.

As far running the code from the command line, as others have said you need to know the absolute path and the relative path may not exist sometimes, it would just be all around better to have all the source code compiled into one .jar rather two .jar's.

You can get the absolute path of the jar in your plug-in using something like:

Bundle bundle = FrameworkUtil.getBundle(getClass());

URL url = FileLocator.find(bundle, new Path("/lib/jar_file_name.jar"), null);

url = FileLocator.toFileURL(url);

String path = URIUtil.toFile(URIUtil.toURI(fileURL)).getAbsolutePath();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM