I read on http://eclipse.geekyramblings.net/2010/12/14/preventing-multiple-instances/ on how to prevent multiple instances of your RCP from being launched. But when I made my RCP(It's a simple RCP based on the "Hello RCP" Template) executable and tried launching it, it throws me this error
java.io.IOException: The location has not been set.
at org.eclipse.core.runtime.internal.adaptor.BasicLocation.lock(BasicLocation.java:174)
at testrcp.Application.start(Application.java:43)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
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:619)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
I am using
Eclipse Java EE IDE for Web Developers.
Version: Helios Service Release 1
Build id: 20100917-0705
Here is the code which is in my Application.java file
package testrcp;
import org.eclipse.core.runtime.Platform;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.osgi.service.datalocation.Location;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
/**
* This class controls all aspects of the application's execution
*/
public class Application implements IApplication {
/* (non-Javadoc)
* #see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext)
*/
public Object start(IApplicationContext context) throws Exception {
Display display = PlatformUI.createDisplay();
int exitCode = IApplication.EXIT_OK;
Location instanceLocation = Platform.getInstanceLocation();
if (!instanceLocation.lock()) {
MessageDialog.openError(new Shell(display), "App Title",
"Another instance of the Application is currently running.");
} else {
int returnCode = PlatformUI.createAndRunWorkbench(display,
new ApplicationWorkbenchAdvisor());
switch (returnCode) {
case PlatformUI.RETURN_RESTART :
exitCode = IApplication.EXIT_RESTART;
break;
default :
exitCode = IApplication.EXIT_OK;
}
}
instanceLocation.release();
display.dispose();
return exitCode;
}
/* (non-Javadoc)
* #see org.eclipse.equinox.app.IApplication#stop()
*/
public void stop() {
if (!PlatformUI.isWorkbenchRunning())
return;
final IWorkbench workbench = PlatformUI.getWorkbench();
final Display display = workbench.getDisplay();
display.syncExec(new Runnable() {
public void run() {
if (!display.isDisposed())
workbench.close();
}
});
}
}
Any help on resolving this issue or any suggestion, would be really appreciated.
Thanks,
Abbas
I was able to make it work by adding this line
instanceLocation.getURL();
after
Location instanceLocation = Platform.getInstanceLocation();
But be aware, this will however not prevent it from being launched from a different folder where the RCP executable exists... Is there any way to keep a check on that ?
You can also open a server socket when you launch your application. If you open another instance, communicate with the server. If you can communicate, that running instance can be opened leaving one instance of the application.
More in detail here
Related
I want to create a Movie Player in javafx using eclipse.My code is compile successfully but it gives run time error.I tried using different file path also.
But it not resolved the error.
My code is
package Player3;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class MediaPlayer3 extends Application{
public static void main(String args[])
{
launch(args);
}
public void start(Stage stage) throws Exception {
Group root = new Group();
Media media =new Media("file:////C://Kaise.MP4");
MediaPlayer player4=new MediaPlayer(media);
MediaView view = new MediaView(player4);
root.getChildren().add(view);
Scene scene =new Scene(root,400,400,Color.BLACK);
stage.setScene(scene);
stage.show();
player4.play();
}
}
The error is
Exception in Application start method
java.lang.reflect.InvocationTargetException
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 sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
java.lang.RuntimeException: Exception in Application start method
java.lang.RuntimeException: Exception in Application start method
As #Sergei Sirik mentioned this is JavaFX and not 'pure' java. Anyway reading the documentation of Media class for the constructor(String source) you will see :
The source must represent a valid URI and is immutable. Only HTTP, FILE, and JAR URLs are supported. If the provided URL is invalid then an exception will be thrown
So I will suggest first to create a File object ( to be able to check file permissions for read write etc ) and after that just pass the mediaFile.toURI().toString() to the Media class constructor and it will open.
Edit :
I guess you will use a FileChooser in future in order to load your video so it will make the file creation and handling much easier.
I had test the code below and it loads successfully my videos on my computer.
import java.io.File;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.scene.paint.Color;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String args[]) {
launch(args);
}
public void start(Stage stage) throws Exception {
Group root = new Group();
FileChooser fc = new FileChooser();
File x = fc.showOpenDialog(null);
Media media = new Media(x.toURI().toString());
MediaPlayer player4 = new MediaPlayer(media);
MediaView view = new MediaView(player4);
root.getChildren().add(view);
Scene scene = new Scene(root, 400, 400, Color.BLACK);
stage.setScene(scene);
stage.show();
player4.play();
}
}
If you have any error like :
MediaException: MEDIA_UNSUPPORTED : Unrecognized file signature!
It's probably cause you alter the file signature by hand or try to play an unsupported file format like mkv.
Just tried to run my old tests in java-9 and see them not running at all due to an exception thrown by the code that guarantees running on the FX-threaad (the ol' trick to instantiate a JFXPanel)
The stand-alone example below (it's the plain tutorial code) throws it as well:
Exception in thread "main" java.lang.UnsatisfiedLinkError: D:\java\jdk\190_ea\bin\awt.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1935)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1841)
at java.lang.Runtime.loadLibrary0(Runtime.java:874)
at java.lang.System.loadLibrary(System.java:1770)
at java.awt.Toolkit$3.run(Toolkit.java:1355)
at java.awt.Toolkit$3.run(Toolkit.java:1353)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Toolkit.loadLibraries(Toolkit.java:1352)
at java.awt.Toolkit.<clinit>(Toolkit.java:1387)
at java.awt.EventQueue.invokeLater(EventQueue.java:1268)
at javax.swing.SwingUtilities.invokeLater(SwingUtilities.java:1381)
at de.swingempire.fx.swing.JFXPanelExample.main(JFXPanelExample.java:59)
Environment is win7, jdk9-ea-107 (without jigsaw), eclipse-neon-ea - questions are simple: a) what's wrong exactly, b) how to fix?
The exact output of java -version is:
java version "9-ea" Java(TM) SE Runtime Environment (build 9-ea+107-2016-02-24-175644.javare.4520.nc)
Java HotSpot(TM) Client VM (build 9-ea+107-2016-02-24-175644.javare.4520.nc, mixed mode)
The code:
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
public class JFXPanelExample {
private static void initAndShowGUI() {
// This method is invoked on the EDT thread
JFrame frame = new JFrame("Swing and JavaFX");
final JFXPanel fxPanel = new JFXPanel();
frame.add(fxPanel);
frame.setSize(300, 200);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Platform.runLater(new Runnable() {
#Override
public void run() {
initFX(fxPanel);
}
});
}
private static void initFX(JFXPanel fxPanel) {
// This method is invoked on the JavaFX thread
Scene scene = createScene();
fxPanel.setScene(scene);
}
private static Scene createScene() {
Group root = new Group();
Scene scene = new Scene(root, Color.ALICEBLUE);
Text text = new Text();
text.setX(40);
text.setY(100);
text.setFont(new Font(25));
text.setText("Welcome JavaFX!");
root.getChildren().add(text);
return (scene);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
initAndShowGUI();
}
});
}
}
Update
tried both suggestions in the comments (updating to most recent 9-ea-107, running from the command line) - no success, same exception.
Another observation: the example above fails with the same stacktrace even when all fx related code is commented - plain swing won't run. Looks like something severely wrong in my environment.
I have followed every step in this (https://blogs.oracle.com/jmxetc/entry/connecting_scenebuilder_edited_fxml_to) tutorial, and yet keep getting an error about this section in the controller class:
myButton.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
System.out.println("That was easy, wasn't it?");
}
});
The only difference I can think of is that it was written for FX 2.0 and not 8.0?
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.Error: Unresolved compilation problems:
The method setOnAction(EventHandler<ActionEvent>) in the type ButtonBase is not applicable for the arguments (new EventHandler<ActionEvent>(){})
EventHandler cannot be resolved to a type
The method handle(ActionEvent) of type new EventHandler<ActionEvent>(){} must override or implement a supertype method
at simple.SimpleController.initialize(SimpleController.java:24)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at simple.Main.start(Main.java:26)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Exception running application simple.Main
Let me know if you need to see the classes and FXML files (dw, they're very short)
Thank you!
PS- Please bear with me if I need clarification about your answer because as a Java newbie I often get confused!
EDIT 1:
package simple;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class SimpleController
implements Initializable {
#FXML // fx:id="myButton"
private Button myButton; // Value injected by FXMLLoader
#Override // This method is called by the FXMLLoader when initialization is complete
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
assert myButton != null : "fx:id=\"myButton\" was not injected: check your FXML file 'simple.fxml'.";
// initialize your logic here: all #FXML variables will have been injected
myButton.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
System.out.println("That was easy, wasn't it?");
}
});
}
}
You are missing the import for EventHandler, and you have the wrong import for ActionEvent. (Also you have imported ActionListener for some reason, though you never use it.)
Your imports should be
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
I am trying to develop an eclipse plug-in. I am aware about the basics of this thing.
In a sample plugin template when we click the menu entry (or button with eclipse icon in below image in this case) in testing instance of eclipse, execute method of sampleHandler.java is executed and a pop-up shown in image below appears.
I want to invoke 'execute' method whenever I press some key (lets say backspace) in code editor instead of clicking any menu entry (or button).
SampleHandler.java
public class SampleHandler extends AbstractHandler {
public SampleHandler() {
}
/**
* the command has been executed, so extract extract the needed information
* from the application context.
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
MessageDialog.openInformation(
window.getShell(),
"Sdfsdfsadf",
"Hello, Eclipse world");
return null;
}
}
I tried suggestions given in other posts but I am unable to achieve the desired functionality.
As per my understanding from referenced post in above line, I tried below code -
package eventlisten.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentListener;
/**
* Our sample handler extends AbstractHandler, an IHandler base class.
* #see org.eclipse.core.commands.IHandler
* #see org.eclipse.core.commands.AbstractHandler
*/
public class SampleHandler extends AbstractHandler {
/**
* The constructor.
*/
public SampleHandler() {
}
/**
* the command has been executed, so extract extract the needed information
* from the application context.
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
MessageDialog.openInformation(window.getShell(),"EventListen","Trying event listen");
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editor = page.getActiveEditor();
IEditorInput input = editor.getEditorInput();
IDocument document=(((ITextEditor)editor).getDocumentProvider()).getDocument(IDocument.class);
document.addDocumentListener(new IDocumentListener() //**this is line 45**
{
#Override
public void documentAboutToBeChanged(DocumentEvent event) {
// TODO Auto-generated method stub
System.out.println("Hello");
}
#Override
public void documentChanged(DocumentEvent event) {
// TODO Auto-generated method stub
System.out.println("Hello second");
}
});
return null;
}
}
But after showing the pop-up , it throws the exception -
java.lang.NullPointerException
at eventlisten.handlers.SampleHandler.execute(SampleHandler.java:45)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:290)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:499)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169)
at org.eclipse.ui.internal.handlers.SlaveHandlerService.executeCommand(SlaveHandlerService.java:241)
at org.eclipse.ui.menus.CommandContributionItem.handleWidgetSelection(CommandContributionItem.java:829)
at org.eclipse.ui.menus.CommandContributionItem.access$19(CommandContributionItem.java:815)
at org.eclipse.ui.menus.CommandContributionItem$5.handleEvent(CommandContributionItem.java:805)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1276)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3562)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3186)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Can someone guide me through the process? Let me know in case more information is required.
Your first problem seems to be that you only interact with the documents when the user presses the button. There are better ways to set this up.
As far as I can tell, you want to either detect when a user modifies a document (probably by typing), any key is typed anywhere, or when the AST of the code is modified. You will probably only find one of the solutions below useful or relevant.
Listening to Document Changes
The solution you attempted is closest to the first one, so I'll start there. I did something like this (in the post you linked, as it turns out). Start by making your plugin extend the org.eclipse.ui.startup extension point, and define a class to override IStartup
That earlyStartup() will look something like:
#Override
public void earlyStartup() {
IWorkbench wb = PlatformUI.getWorkbench();
wb.addWindowListener(generateWindowListener());
}
We'll listen for windows to open, and when they do,
private IWindowListener generateWindowListener()
{
return new IWindowListener() {
#Override
public void windowOpened(IWorkbenchWindow window) {
IWorkbenchPage activePage = window.getActivePage();
activePage.addPartListener(generateIPartListener2());
}
#Override
public void windowDeactivated(IWorkbenchWindow window) {}
#Override
public void windowClosed(IWorkbenchWindow window) {}
#Override
public void windowActivated(IWorkbenchWindow window) {}
};
}
This part listener is where you should get the EditorPart, which means you can add the document listener:
private IPartListener2 generateIPartListener2()
{
return new IPartListener2() {
private void checkPart(IWorkbenchPartReference partRef) {
IWorkbenchPart part = partRef.getPart(false);
if (part instanceof IEditorPart)
{
IEditorPart editor = (IEditorPart) part;
IEditorInput input = editor.getEditorInput();
if (editor instanceof ITextEditor && input instanceof FileEditorInput) //double check. Error Editors can also bring up this call
{
IDocument document=(((ITextEditor)editor).getDocumentProvider()).getDocument(input);
document.addDocumentListener(/* your listener from above*/);
}
}
}
#Override
public void partOpened(IWorkbenchPartReference partRef) {
checkPart(partRef);
}
#Override
public void partInputChanged(IWorkbenchPartReference partRef)
{
checkPart(partRef);
}
#Override
public void partVisible(IWorkbenchPartReference partRef){}
#Override
public void partHidden(IWorkbenchPartReference partRef) {}
#Override
public void partDeactivated(IWorkbenchPartReference partRef) {}
#Override
public void partClosed(IWorkbenchPartReference partRef) {}
#Override
public void partBroughtToTop(IWorkbenchPartReference partRef) {}
#Override
public void partActivated(IWorkbenchPartReference partRef) {}
};
}
Listening to just the keypressess
This ends up being simpler to implement, but may be very noisy. We'll be looking at the Display and the Listener, which gets right into the SWT event loop.
You'll want to do the earlyStartup() extension again, and have something like:
#Override
public void earlyStartup() {
Display display = Display.getDefault();
display.setFilter(SWT.KeyUp, new Listener() {
#Override
public void handleEvent(Event event) {
//do stuff here. Be careful, this may cause lag
}
});
}
Listening to Java AST changes
The final one has the simplicity of the raw keyup approach, but will probably be as semantically useful as the first one I suggested. We will be listening to the JavaCore directly.
Again, in the earlyStartup method()
JavaCore.addElementChangedListener(new IElementChangedListener() {
#Override
public void elementChanged(ElementChangedEvent event)
{
//do stuff with the event
}
});
Conclusion: With luck, one of these three methods is useful to you. I've had reason to use each in my Eclipse development career -- each is useful in its own way.
I hope this helps.
I am completely new to jbehave and even automated testing.
I read a tutorial online and tried following the steps.
I am trying to run this application in eclipse IDE.
I made a Math.story file which contains the tests:
Scenario: 2 squared
Given a variable x with value 2
When I multiply x by 2
Then x should equal 4
In a .java file called ExampleSteps.java, the steps are written:
import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Named;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;
import org.jbehave.core.steps.Steps;
public class ExampleSteps extends Steps {
int x;
#Given("a variable x with value $value")
public void givenXValue(#Named("value") int value) {
x = value;
}
#When("I multiply x by $value")
public void whenImultiplyXBy(#Named("value") int value) {
x = x * value;
}
#Then("x should equal $value")
public void thenXshouldBe(#Named("value") int value) {
if (value != x)
throw new RuntimeException("x is " + x + ", but should be " + value);
}
}
I created another class SimpleJbehave which has the main method:
import java.util.Arrays;
import java.util.List;
import org.jbehave.core.embedder.Embedder;
public class SimpleJBehave {
private static Embedder embedder = new Embedder();
private static List<String> storyPaths = Arrays
.asList("Math.story");
public static void main(String[] args) {
embedder.candidateSteps().add(new ExampleSteps());
embedder.runStoriesAsPaths(storyPaths);
}
}
When I run this code, I get the following exception:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections/Transformer
at org.jbehave.core.configuration.Configuration.<init>(Configuration.java:112)
at org.jbehave.core.configuration.MostUsefulConfiguration.<init>(MostUsefulConfiguration.java:49)
at org.jbehave.core.embedder.Embedder.<init>(Embedder.java:30)
at org.jbehave.core.embedder.Embedder.<init>(Embedder.java:37)
at SimpleJBehave.<clinit>(SimpleJBehave.java:8)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections.Transformer
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 5 more
As I am a novice, I have not been able to understand what exactly the problem is.
It will be really nice if someone could tell me what I should do to get this code working.
Is my approach wrong?
Thank you very much in advance.
It looks like you don't have org.apache.commons.collections.Transformer on your classpath. It looks like this class is available in the apache-commons-transformer library here: http://commons.apache.org/collections/api-release/org/apache/commons/collections/Transformer.html
Download the jar and add it to your classpath. It might work.