Ok, I have a(n) RCP application (that I didn't write), and an application I've developed using just SWT. What I want to do is basically import and launch the main method of the SWT application with arguments, such that it runs in another window, like it's another process. The argument I want to pass is a complex data structure that I don't want to serialize.
I originally thought I could just design my SWT app to be a library and import it, have it spawn its shell, etc. But I neglected to think about how the SWT app's main loop has to run on the main thread, which seems problematic.
So I started looking into integrating it with the eclipse plugin architecture. Problem: I don't know anything about the eclipse plugin architecture or RCP, and when I try to learn, I run into an inscrutable wall of things that are totally unlike what I want to do (ie building new buttons onto the eclipse workbench). How do I get started developing a plugin that just launches another window?
You will need some kind of button to launch your application so just must hook into the Eclipse menu system.
Try:
1) In Eclipse, File -> New Project-> Plug-in project
2) Make sure you check "This plug-in will make contributions to the ui"
3) Uncheck "generate activator" since you won't be needing it
4) Select "Hello World command" from the code template
Now you will have a sample handler and a method called execute where you could call your SWT-application with the display you're using in the RCP-application. If you really must call void main(String[] args) you could get the display by calling Display.getDefault(), which will either create a new display or use the one from the RCP-application.
You will also have to modify the plugin.xml file so it points to the correct menu in your RCP-application. If you want your launch command to be in the file menu etc.
Finally, right-click on your project and select Export -> Plug-in Development and create a jar-file where you launcher will be in. Drop that jar into the plugins folder of the RCP-application and you should be able to launch the SWT-application from the command you've just created.
There will probably be a couple of bumps on the way, but that's roughly what you will have to do.
Related
I am a newbie with Java and trying to write a very simple program like this ofcourse
public class FirstProg {
public static void main( String[] args) {
System.out.println(" I am learning how to code");
System.out.println("Today's date is");
}}
When I ran it, it said to me that, the selection can not be launched, and there are no recent launches , I ran it on Eclipse. Could you please give me some ideas? I am a newbie and very confuse with this problem. Thank you very much.
It is difficult to be exact, because we don't know exactly what you've clicked on, or what version of eclipse you have. Eclipse is very flexible, and one result of that is that it does not have the same subwindows and buttons for every user.
There is a standard 'view', i.e., a subwindow within Eclipse's main window, called "Project Explorer. It is most often on the left side of the eclipse window, and displays folders and files in one or more projects.
Find the folder for your project in that view, right-click on it, and look for the options "Run As..." and "Debug As...". Those are also menus, they will have options that depend on how your eclipse is configured. But one of the options should be "Java Application", which is the right one for what you're doing. "Run As..." runs your program; "Debug As" runs it under the eclipse debugger.
If there is only one Java class in the project with a main(String[] args) method, then eclipse will run that class. If there's more than one such class, it will ask you to choose.
Once you've done this, there are usually buttons on the top of eclipse; one is an insect-looking icon, the the other a triangle with a point to the right -- the first is 'debug', the second is 'run', and once you have debugged or run a class, clicking on one of those will debug or run the last class you debugged or ran.
Good luck.
I wrote two java projects which are purely independent.
When I run the first project "aa", automatically a "Run Configurations" window appeared, and I chose "cc" (cc.java) under Java Application tab.
The app run.
but when I made another java project "dd" and wrote code in its class "ff", The run button showed the output of cc.java in console.
I had to go to "Run Configurations", and select "ff" (ff.java) under Java Application tab.
Why I have to to do this everytime?
What if I have multiple classes under one project?
Is there anyway to run a project by simply clicking run button?
Regards,
BAQAR RAZA MANGRANI
Struggling programmer.
As far as I know, if you have several classes including a main method in eclipse, as soon as you run them once, they appear as shortcuts when expanding the run button(or debug). Just click on the small arrow next to the start button and select the file you want to run.
every now and then I am launching JUnit tests from within Eclipse by using
Run As > JUnit Plug-in Test
By default Eclipse assumes you are running something which requires a workbench and chooses in the "Main" section of the launch configuration
LaunchConfig > Main > Program To Run > Run an application >
org.eclipse.ui.ide.workbench
I can understand why this is the default, but for me (and for all in our team) this is never ever the case. We always need to run our JUnit Plug-in Tests as
LaunchConfig > Main > Program To Run > Run an application >
[No Application] Headless Mode
How do I change this default behaviour?
I am currently using Eclipse 4.4.
It seems a custom LaunchConfiguration-Extension is a viable solution attempt.
What I did was to create a new, custom LaunchConfiguration-Extension which is 99.999% build on the JUnitLaunchConfiguration. I only had to add a custom
BlaBlaJUnitPluginTestLauncher extends launching.JUnitLaunchConfigurationDelegate
which overrides the
launch(ILaunchConfiguration, String, ILaunch, IProgressMonitor)
method to adjust the application parameters according to our needs.
BlaBlaJUnitPluginTestTabGroup extends org.eclipse.pde.ui.launcher.JUnitTabGroup
To be able to initialize the LaunchConfig dialog with the default parameter, I had to:
Add a custom BlaBlaPluginJUnitMainTab extends PluginJUnitMainTab
Create a custom JUnitProgramBlock implementation (BlaBlaJUnitProgramBlock)
Creating an instance of BlaBlaJUnitProgramBlock in the BlaBlaJUnitPluginTestTabGroup.BlaBlaPluginJUnitMainTab.createProgramBlock() method
Overriding setDefaults-method (not sure if its really neccessary) in BlaBlaJUnitProgramBlock
Overriding initializeForm-method in the BlaBlaJUnitProgramBlock and adjust parameter there too.
Leading to the following result:
This answer is a near miss:
Try this:
Manually create and configure one "good" launch configuration.
Next time you want to launch a test that doesn't yet have a good launch configuration:
Select the file and invoke Run As > Run Configurations ... (i.e., don't yet select JUnit Plug-in Test!)
In that dialog select a good launch configuration of the same kind, and ...
Then click New Launch Configuration (upper-left corner)
Now the newly created configuration should "inherit" the configured values from the the good configuration.
Truth is:
You can duplicate an existing launch configuration (leaving you to manually select the test to launch)
The Debug team once had plans to support launch configuration templates.
Edit 2018:
Since Eclipse Photon, the Java debugger supports launch configuration prototypes. I just filed Bug 536728 to request this also for test launches. Feel free to chime in (or contribute) on that bug.
if u r looking for only shortcut for convenience then eclipse remembers last execution. After using run as and saving ur run config, just use "Run as" button in toolbar.
besides this eclipse comes with flavour for testers, u can check that out.
Also since you are talking about unit testing see if you can make use of ant build or even better converting to maven based project. Maven has integrated support for testing.
There seems to be a simple and effective heuristic in place, which decides whether or not a JUnit Plug-in Test should be run headlessly or with an application:
Make sure that the plug-in containing your tests has no dependencies on anything org.eclipse.ui.
Without that dependency [No Application - Headless Mode] is selected by default for newly created launch configurations.
With that dependency the default is Run a product, with s.t. like org.eclipse.platform.ide preselected.
I'm pretty new to Java and Eclipse coming from an iOS/xCode background. I have an iOS project that has 2 builds, 1 that uses a test server and 1 that uses a live server. In xCode this was simply a case of adding a new build target, a Preprocessor Macro, than using #ifdef in code to use separate url's for each build.
Porting this over to Android, I have this list of things I need to do each time I want to build/test between the 2 versions
TO SWITCH BETWEEN LIVE AND TEST
Rename Application Package com.mybus.myapp/com.mybus.myapptestserver (Right click, Android Tools, Rename Application Package).
Rename com.mybus.myapp folder to com.mybus.myapptestserver.
Change Map API key in manifest
Change SENDER_ID in BeginActivity.java (Notification app ID).
Search and change all references com.mybus.myapp/com.mybus.myapptestserver (Including SharedPreferences).
Change URL's in ConnectionHelper.java and PasswordResetConnection.java
Change icon and label in Manifest for Application & BeginActivity.
Remove crash reporter (ACRA) from MyApplication.java.
Change .setSmallIcon(R.drawable.ic_test_launcher) & .setContentTitle("myapptestserver") in GCMIntentService.java
Surely there is an easier way to build seperate builds and allow them both on a device at the same time?
You could use Ant script to do this. Once you customise your Ant script to handle all these changes, you can get the final output by running the ant release command.
An small example from where you could start with. I have written a post about it. This ant script, doesn't change any values in files, but what it does, is outputs the final apk, with a chosen name format, and puts it in a specified folder.
http://techdroid.kbeanie.com/2011/09/automating-builds-on-android-part-1.html
http://techdroid.kbeanie.com/2011/09/automating-builds-on-android-part-2.html
Disclaimer: These are links to my blog posts.
I have an application developed in Java that's almost ready for distribution. However, I have a problem switching from my development env to publishing env, and back to development. For instance, in Eclipse, if I just want to do a test run via the run button, I have to change the code so my JMenuItems show up.
In my development environment I had the following that worked well:
JMenuItem[] appItems = new JMenuItem[2];
appItems[0] = new JMenu("New");
appItems[0].setIcon(new ImageIcon(../POS_System/images/new_icon_sm.png")));
But, as I near deployment, to get this to work in the deployable JAR, I need to alter the code:
JMenuItem[] appItems = new JMenuItem[2];
appItems[0] = new JMenu("New");
appItems[0].setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/new_icon_sm.png")));
This is order to reach into the JAR and get the appropriate image.
I have a lot of these JMenuItems. I'd really like to be able to test the app via the run button in Eclipse, as well as create a JAR without changing the code.
Is there a simple way to do this? I thought the getResource method would still allow me to use the JMenus, JMenuItems etc, but they aren't available when I run the program from Eclipse. It seems silly that I would have to keep switching back and forth.
I appreciate any help here.
If you do not want to move your images into the src/ folder as you have suggested, then in Eclipse, you should update your Eclipse configuration under the Project Prooperties -> Java Build Path and add an additional source folder, this one pointing to where you keep your images. I believe this will fix it.