2

Currently I am passing command line arguments to invoke a Program. I am showing a small code snippet for your reference.

public class Main {
    public static void main(String[] args) throws Exception {

        GlobalVariable.activity = args[0];
        GlobalVariable.templatePath = args[1];
      ....

        }

To invoke the above program, I pass the following command from Eclipse. enter image description here

Now, I am trying to develop an eclipse plugin that invoke this command from Java Program itself. To develop a plugin, I have done the following:

  1. Eclipse (New -> Project -> Eclipse Plugin Project ) with a project name "org.example.helloworld"
  2. I have chosen "Plug-in with a pop-up menu" template.
  3. Now, I have written the following code in "NewAction.java" to pass the command line parameters to my main file, as shown above".
public void run(IAction action) {
      String args[]  = new String[2];
      args[0] = "compile-vocab-spec"; 
      args[1] = "C:\\Template\\";

      try {
          Main.main(args);
      } catch (Exception e) {
          e.printStackTrace();
      }   
  }

My problem is - I am not able to invoke the Main.java file. What is the wrong with this techniques? any other alternatives are also welcomed please. Please let me know in case you need more information for further clarity.

I see the following messages on Console when I run the code.

!SESSION 2015-11-15 14:04:18.580 -----------------------------------------------
eclipse.buildId=4.5.1.M20150904-0015
java.version=1.8.0_51
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Framework arguments:  -product org.eclipse.platform.ide
Command-line arguments:  -product org.eclipse.platform.ide -data C:\Users\inpapat4\workspace/../runtime-EclipseApplication -dev file:C:/Users/inpapat4/workspace/.metadata/.plugins/org.eclipse.pde.core/Eclipse Application/dev.properties -os win32 -ws win32 -arch x86_64 -consoleLog

!ENTRY org.eclipse.core.net 4 0 2015-11-15 14:04:36.102
!MESSAGE WinHttp.GetProxyForUrl for pac failed with error 'The proxy auto-configuration script could not be downloaded
' #12167.

!ENTRY org.eclipse.ui 4 0 2015-11-15 14:04:46.332
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.NoClassDefFoundError: org/antlr/runtime/CharStream
    at org.example.helloworld.popup.actions.NewAction.run(NewAction.java:42)
    at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:247)
    at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:595)
    at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:511)
    at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:420)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4362)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1113)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4180)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3769)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
    at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
    at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:654)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:598)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1488)
Caused by: java.lang.ClassNotFoundException: org.antlr.runtime.CharStream cannot be found by org.example.helloworld_1.0.0.qualifier
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:439)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:352)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:344)
    at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 32 more

The content of MANIFEST.MF file is as follows:

Bundle-ManifestVersion: 2
Bundle-Name: Helloworld
Bundle-SymbolicName: org.example.helloworld;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: org.example.helloworld.Activator
Require-Bundle: org.eclipse.ui,
 org.eclipse.core.runtime,
 org.eclipse.core.resources
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
9
  • 2
    What happens when you run the above code? Commented Nov 15, 2015 at 6:41
  • Thanks Elliott Frisch for the comment. To answer your question, I am updating the question with the message I see on console. Commented Nov 15, 2015 at 8:36
  • 1
    So what exactly is the problem? Does the code compile? Do you get an exception when you run it? Commented Nov 15, 2015 at 8:37
  • @greg-449 : I have updated the question with the error messages that I see on console when I run this code. Commented Nov 15, 2015 at 8:40
  • 1
    So you haven't included all the jars necessary to run your code in the plugin - in particular the jar containing org.antlr.runtime.CharStream. Commented Nov 15, 2015 at 8:54

1 Answer 1

1

The jars required in your plugin must be listed in the MANIFEST.MF in the Bundle-Classpath entry.

To do this open the MANIFEST.MF editor, on the 'Runtime' tab add the jars to the 'Classpath' section.

The result might look something like:

enter image description here

The '.' entry is for the plugin files, I then have 3 jars in a 'lib' folder.

Also make sure the jars are listed in the 'build.properties' file so that they are included in the final plugin jar.

Sign up to request clarification or add additional context in comments.

1 Comment

Many thanks for resolving the issue! This has been solved now. :) :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.