How to set up RJava in Eclipse

Here is a more detailed tutorial on how to set up RJava using the RJava Eclipse plugin.
The full tutorial is on the studytrails website: http://www.studytrails.com/RJava-Eclipse-Plugin/

Open R. Choose the menu Packages -> Install package(s):

Open R and choose the menu Packages/Install package(s)

Open R. Choose the menu Packages -> Install package(s)

Choose the CRAN mirror:

Choose the CRAN mirror

Choose the CRAN mirror.

Choose the RJava package:

Choose the RJava package

Choose the RJava package

Type library() in the RConsole to find the path to the library.
We’ll need that later in Eclipse Preferences.

Type library() in the RConsole to find the path to the library

Type library() in the RConsole to find the path to the library. We’ll need that later in Eclipse Preferences.

Here is the path to the R library.
Of course, it will be different on your computer.
Remember this path:

Here is the path to the R library

Here is the path to the R library. Of course, it will be different on your computer. Remember this path.

On the library path, we find the RJava folder

On the library path, we find the RJava folder

On the library path, we find the RJava folder

In Eclipse -> Window -> Preferences -> RJava, we fill in the Path to JRI DLL Dir:

In Eclipse -> Window -> Preferences -> RJava, we fill in the Path to JRI DLL Dir

In Eclipse -> Window -> Preferences -> RJava, we fill in the Path to JRI DLL Dir

We fill in the Path To JRI JARS:

We fill in the Path To JRI JARS

We fill in the Path To JRI JARS

We fill in the Path To R Dll Dir.
This depends on the type of machine you have.
For a x32 machine, the R.dll is in the bin\i386 folder.
For a x64 machine, the R.dll is in bin\x64 folder.

We fill in the Path To R Dll Dir

We fill in the Path To R Dll Dir. This depends on the type of machine you have. For a x32 machine, the R.dll is in the bin\i386 folder. For a x64 machine, the R.dll is in bin\x64 folder.

We fill in the path to the jvm.dll dir.
This depends on where you have installed your JDK.

We fill in the path to the jvm.dll dir

We fill in the path to the jvm.dll dir. This depends on where you have installed your JDK.

We run the test. You can copy a Java test file from the rJava\jri\examples folder.
Right-click the R_prj and choose Run configurations… -> rJava -> New…
The press Run.

We run the test

We run the test

Check out the Console

Check out the Console

It works

It works

You can type in license() to see the R license:

You can type in license() to see the R license

You can type in license() to see the R license

Get started with Hibernate with Postgres – tutorial

Installation

You need:
Java SDK
Postgres
PgAdmin
Hibernate
Hibernate Annotations
JDBC driver for Postgres

I’m going to try IntellijIDEA with this.

In PgAdmin, create a new Database. I’m naming it cakesdb.

Screen Shot 2014-06-04 at 16.05.03

Screen Shot 2014-06-04 at 16.05.50

Screen Shot 2014-06-04 at 16.06.39

Screen Shot 2014-06-04 at 16.07.20

Create a hibernate.cfg.xml file in a folder called Plumbing.

Screen Shot 2014-06-04 at 16.08.00

<!DOCTYPE hibernate-configuration PUBLIC
	"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
	"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
	<session-factory>
        <property name="connection.url">
            jdbc:postgresql://localhost/cakesdb
        </property>
        <property name="connection.username">
            yourconnectionusername
        </property>
        <property name=“connection.password">
	yourpassword
	</property>
        <property name="connection.driver_class">
            org.postgresql.Driver
        </property>
        <property name="dialect">org.hibernate.dialect.PostgreSQL9Dialect</property>
        <property name="transaction.factory_class">
            org.hibernate.transaction.JDBCTransactionFactory
        </property>
        <property name="current_session_context_class">
            thread
        </property>
		<property name="show_sql">true</property>
	</session-factory>
</hibernate-configuration>

Make sure the configuration file is on the classpath and available to the class loader.
As my hibernate.config.xml file is in the plumbing folder, I just needed to select the plumbing folder and mark it as “Resources”.

Screen Shot 2014-06-04 at 16.08.27

Create now a Cake class:

package com.cakes.model;

import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;


@Entity
public class Cake {
    private Long id;
    private String name;

    @Id
    @GeneratedValue
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static void main(String args[]) {
        Configuration config = new Configuration();
        config.addAnnotatedClass(Cake.class);
        config.configure();
        new SchemaExport(config).create(true, true);
    }
}

Now you can run it and you should have this as output:

Screen Shot 2014-06-04 at 16.09.46

P.S.: You can use this code for whatever you want.

How to install/uninstall plugins at runtime? (Eclipse RCP)

In the Activator class of your product plugin, implements something like this:

private Bundle bundleToInstall;

/*

* (non-Javadoc)

*

* @see

* org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext

* )

*/

@Override

public void start(BundleContext context) throws Exception {

super.start(context);

plugin = this;

Bundle[] bundles = context.getBundles();

for (Bundle bundle : bundles) {

if (bundle.getSymbolicName().equals("my.bundle.to.uninstall")) {

bundle.uninstall();

}

}

boolean doInstall = false;

if (doInstall) {

bundleToInstall = context

.installBundle("http://blabla.bla/my.bundle.to.install.jar ");


bundleToInstall.start();

}

bundles = context.getBundles();

for (Bundle bundle : bundles) {

System.out.println(bundle.getSymbolicName());

}

}

/*

* (non-Javadoc)

*

* @see

* org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext

* )

*/

@Override

public void stop(BundleContext context) throws Exception {

if (bundleToInstall != null) {

bundleToInstall.stop();

bundleToInstall.uninstall();

}

plugin = null;

super.stop(context);

}

Groovy in Eclipse RCP projects

I’ve done a little research on the Internet and it’s not difficult to get started.

Here are two links that put together, give you a working environment.

http://contraptionsforprogramming.blogspot.be/2010/08/groovy-pde-redux.html

http://stackoverflow.com/questions/4514173/eclipse-rcp-with-groovy-cannot-create-a-groovy-class

Summed up, here are the steps:

1) install the plugin Groovy-Eclipse (from Eclipse/Help/Marketplace)

2) as Andrew Eisenberg said, add these lines to your build file

sourceFileExtensions=*.java, *.groovy
compilerAdapter=org.codehaus.groovy.eclipse.ant.GroovyCompilerAdapter
compilerAdapter.useLog=true  # this ensures that exceptions are logged to the proper log file.

3) make sure you have these jars on your classpath or as a dependency or in your Target Platform&nbsp(you find them in the binaries here http://groovy.codehaus.org/Download):

groovy-all-2.1.1.jar,asm-4.0.jar,asm-analysis-4.0.jar,asm-commons-4.0.jar,asm-tree-4.0.jar,asm-util-4.0.jar,ant-antlr-1.8.4.jar,antlr-2.7.7.jar

What I did here was Eclipse/New/Project/Plugin from existing jars and there I have added all these jars. Then I added this plugin as a dependency for the plugins where I need to use Groovy.

4) then right-click on your project and choose Configure/Convert to Groovy project

After that, you can just use Groovy in Java and Java in Groovy seamlessly.

For example, I created a Cat.groovy with just a getName() method.

And from my MyView.java, I just called Groovy like it was java.

Cat cat = new Cat();

String catName = cat.getName();

Pretty cool!

How to replace the default binding scheme?

Step 1: create your scheme

custom_scheme

Step 2: Set your scheme as the scheme of your keybindings

step 2

Step 3: Modify your plugin_customization.ini file by adding

org.eclipse.ui/KEY_CONFIGURATION_ID=my.default.scheme

Step 4: Modify your Application class

public Object start(IApplicationContext context) throws Exception {
 PlatformUI.getPreferenceStore().setDefault(
 IWorkbenchPreferenceConstants.KEY_CONFIGURATION_ID,
 "my.default.scheme");
 // whatever was there before
 }

Reference:
http://www.eclipsezone.com/eclipse/forums/t115602.html
http://www.vogella.com/articles/EclipseCommandsKeybindings/article.html

How to get a service from anywhere? (Eclipse RCP)

ICommandService commandService = (ICommandService) PlatformUI
.getWorkbench().getActiveWorkbenchWindow()
.getService(ICommandService.class);

Or, if you have access to a IWorkbenchPartSite (in this example returned by getSite()):

		IWorkbenchSiteProgressService service = (IWorkbenchSiteProgressService) getSite()
				.getService(IWorkbenchSiteProgressService.class);