Haider
Haider

Reputation: 341

Integrating a Java Class into a PyDev Project (Jython) in Eclipse

I have a Java class that i would like to import into my Jython script. Unfortunately, eclipse won't let me create a Java class inside my Jython project.In the window, where you create and name your Java class, I get a message at the top (alongside a red cross) saying, "Source folder is not a Java project" when I type the name of the would be class. How do I rectify this? I need the Java Class to call C code using the JNI (declaring the native method,loading and then calling it). Thank You !!!!!!!

Upvotes: 0

Views: 1571

Answers (2)

Haider
Haider

Reputation: 341

So what nefo_x suggested is correct. You need to create a new Java project that will contain your Java class. Then import the Java package as you would a python module. But there are a few things to watch out for in eclipse to make it work. I list the whole process below:

  1. Your Java class (or classes) should not be in the default package. You need to create a new package and make/put your java class files there.

  2. Export the package as a jar file to some place on your computer.

  3. Add the jar file (located at some place on your computer) to your python path.

  4. Import the package by writing "import PackageName".

The problem for me was that I had my java class in the default package. That does not work due to some naming issues. Anyhow, hope that this helps.

Upvotes: 1

nefo_x
nefo_x

Reputation: 3088

What you can do is to create second module which would be java project. Anyhow, logically it should be that way. Please check out other similar question - PyDev: Jython modules & Java classes in the same project.

Other links that might help - http://pydev.org/manual_101_project_conf2.html

Upvotes: 2

Related Questions