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 !!!!!!!
2 Answers
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
-
1So, I tried what I think you are suggesting. I made a separate Java project. Then, I imported the Java class as an external library to my PyDev project. Then I typed import NameofTheClass in my main jython script. And it says unresolved import. Did I miss something? I think this should have worked. – Haider Oct 07 '14 at 00:21
-
1hm, it's strange with eclipse then. in IDEA approach is to create separate modules within same project and each one of those have their own SDK/Language. Anyhow, working that way with Java/Python platform for a long time now. – nefo_x Oct 07 '14 at 00:37
-
I still haven't fixed the problem. Should I switch to IntelliJ IDEA or Netbeans? Which one would you recommend? – Haider Oct 07 '14 at 16:06
-
1i would just recommend IDEA as i'm the most comfortable with it working on mixed Java/Python projects. You can try requesting student license. Of course, others might be more comfortable with Eclipse as well. – nefo_x Oct 07 '14 at 16:38
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:
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.
Export the package as a jar file to some place on your computer.
Add the jar file (located at some place on your computer) to your python path.
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.

- 341
- 3
- 18