Update jython.jar in PyDev - eclipse

What is the proper way to apply a new jython.jar to PyDev?
I expect this option to be available since I have to supply a Jython interpreter at startup. Using mixed versions would likely cause issues. I expected the jython.jar for that interpreter to be used for everything, not just running standalone Jython, but that doesn't appear to be the case.
I believe org.python.pydev.jython provides a version of jython.jar. The version of this plugin in PyDev 2.7.1 has a pydev-jython.jar that is on the runtime classpath when I import this plugin. (The import also makes a copy of the directory of my configured Jython interpreter.)
How do I get PyDev to use a different jython.jar?
Here is some more background information.
I have followed the instructions on the PyDev website for installing PyDev in Eclipse. I have configured Jython 2.5.3 to be the interpreter.
I can open a Jython console and run the following:
>>> import org.python.core.PySystemState as pss
>>> st = pss()
>>> st.getBuiltins
<bound method <reflected field public org.python.core.PyObject org.python.core.PySystemState.__name__ at 0x1>.getBuiltins of <module 'sys' (built-in)>>
I also have no problem doing this from a python module that I run as a Jython Run.
However, when I try to access getBuiltins from java, I get a compile-time error stating that the method getBuiltins is not defined for PySystemState. As I have fought with this problem extensively, I believe what is going on is that org.python.pydev.jython is providing jython.jar whereas the interpreter configuration is only used to run the Jython interpreter.
Clearly, some jython.jar is in my classpath because I don't get a complaint when I import org.python.core.PySystemState. The symptoms are consistent with an older jython.jar that didn't have the full API of Jython 2.5.3.
Any help would be appreciated -- I'd prefer not to earn another tumbleweed bronze! :-)

It turns out that what I was trying to do required access to a new jython.jar. It had nothing to do with PyDev. I just created a plugin from jython.jar and referenced it.
I thought there were issues with PyDev because classpath and jythonpath worked automatically from the java app but not from a plugin product configuration. It turns out Eclipse was handling it for me in one case and not the other. PyDev simply wasn't invovled.

Related

Grails create-controller fails (inside Eclipse)

first off: sorry if the question should not belong here.
I am fairly new to grails and wanted to set it up with eclipse (Spring Tool Suite + Grails/Groovy plugin).
But already the creation of a HelloWord controller fails with huge exeptions.
I did set JAVA_HOME and GRAILS_HOME in my environment variables in windows.
I keep it short I uploaded it to pastebin: http://pastebin.com/aesgcyP7
As you can see it fails with:
\HelloWorldController.groovy: 1: unexpected token: package # line 1,
column 1.
package 7daystobuild
Background Info: I also tried newer grails versions (2.2.4, since the plugin uses 2.2.3) and both jdk 1.7 and 1.6)
Thanks
I don't think your package name is valid. I've never officially looked it up for Groovy, but I believe Groovy follows Java naming conventions for packages, which states you can't have package names start with a digit.

Class not being built using Scala Eclipse plug-in

I'm trying to use the Scala Eclipse plug-in (version 1.1.0, which appears to be the most current) with version 3.7 of Eclipse on Mac OS X 10.6.8. I've copied the "Hello, World" program from a tutorial website. I was able to build the program successfully using the command-line scalac compiler. However, when I attempt to run the project as a Scala application from within Eclipse, I get an error like so:
Exception in thread "main" java.lang.NoClassDefFoundError: de/vogella/scala/first/Hello
with a bunch more stuff following. Looking in the relevant directory structure in my Eclipse workspace directory shows that the associated bin directory is completely empty. However, there are no errors (and indeed no messages of any sort) when I select "Build Project" from the menu.
As far as I can tell, my Eclipse installation is otherwise functional. I can, for instance, successfully build and run Java projects.
Any tips on where to start with troubleshooting would be greatly appreciated. Trying the suggested solutions in the most relevant-seeming existing question didn't work.
EDIT to add: There isn't anything in the Error Log window except this:
System property http.nonProxyHosts has been set to
local|*.local|169.254/16|*.169.254/16 by an external source. This value will be
overwritten using the values from the preferences
which doesn't strike me as terribly relevant. The full text, as copied from the tutorial, of the Hello.scala file, is
package de.vogella.scala.first
object Hello {
def main (args: Array[String]) {
println("Hello, world!")
}
}
and the package the file is a part of is called de.vogella.scala.first.
I followed Kipton Barros' suggestion from the comments, and installed the 2.0.0 beta of the Scala IDE plug-in for Eclipse. While I find it slightly strange that switching from a final release to a beta release resolved the issue, resolve the issue it did.
(Too bad I can't accept a comment as the answer.)
Check if the package declaration in your scala file match the packages in eclipse.

How do I get the Jython PythonPath to reliably include java class paths?

Question
Is there a way to reliably ensure that both the python source paths and compiled java class paths are added to the Jython PythonPath when running unit tests under eclipse?
If not, is there a better workaround than adding absolute paths to the PyDev PythonPath, External Libraries list?
Background
I have been having a strange problem with running Jython unit tests on a Jython class which inherits from a Java class.
We have an eclipse RCP application with a structure (simplified) like this:
Config project (Pydev nature only)
scripts
src
classes.py
test
classesTest.py
Core project (Both Java & Pydev natures)
scripts
src
baseClass.java
classes
baseClass.java
Library project (Both Java & Pydev natues, but no Jython scripts)
src
interface.java
classes
interface.class
In classes.py I import baseClass, which implements an interface defined in interface.java. I then create a Jython class which inherits from baseClass.
In my classesTest.py, I import classes and define the unit tests.
The problems come when I try to run the unit tests using "Project explorer > classesTest.py > Run as > Jython unit-test":
Sometimes it is unable to find the baseClass (I think it fails with an ImportError, but I can't reproduce this right now).
At other times it finds the baseClass, but then can't find the interface, so it fails with a java.lang.NoClassDefFoundError.
If I pprint the sys.path at the start of the test module, then I can see that:
While core/scripts is on the python path, neither core/classes nor library/classes are on the path.
Both core/scripts and core/classes are on the python path, but library/classes still is not.
Sometimes, very rarely, both classes paths are added to the python path and the unit tests work fine, without the workaround below. Unfortunately, I haven't worked out how to reproduce this and can see no difference in the files in the source tree between it working and it not working.
Current Workaround
My current workaround is to explicitly add in "External Libraries" for library/classes and core/classes explicitly. Unfortunately it appears that these have to be absolute paths, which means I have to set them differently for every trunk, branch or computer that I use. As such, I don't want to commit these into revision control and it is a pain having to set them up every time.
Notes
Note that the Config project only references the core project, but referencing the library project explicitly makes no difference to the class path.
Also, while trying to find a reliable method to reproduce this problem, I had other libraries inexplicably disappear from the python path and then just as mysteriously reappear, the most recent example being Mock!
Update
I haven't seen this problem recently (currently using Eclipse 3.7.1 & PyDev 2.2.2) so it may have been an aberration with the combination of Eclipse/PyDev I was using at the time.
For a java project, you have to explicitly add the folder with the .class files to the PYTHONPATH.
The recommended organization would be:
java_project/bin <- this folder should be set as a source folder within PyDev (to be added to the PYTHONPATH).
java_project/src <- this folder should be added to the jdt classpath, but should not have any reference in PyDev
python_project/src <- this folder should be set as a source folder within PyDev (to be added to the PYTHONPATH).
And the python_project should have a reference to the java_project.
See the last part of http://pydev.org/manual_101_project_conf2.html as a reference.
I had a similar problem. Recently resolved by accordingly modifying the python.path field in the Jython registry file.
It looks like the Pydev plugin cannot modify the sys.path to be able to import the Python module from a Java project in Eclipse.
More details at Adding in a python module to the sys.path for a Java project in pydev, Eclipse

How to use Scala in IntelliJ IDEA (or: why is it so difficult to get a working IDE for Scala)?

I recently gave up trying to use Scala in Eclipse (basic stuff like completion doesn't work). So now I'm trying IntelliJ. I'm not getting very far.
I've been able to edit programs (within syntax highlighting and completion... yay!). But I'm unable to run even the simplest "Hello World". This was the original error:
Scala signature Predef has wrong version
Expected 5.0
found: 4.1 in .... scala-library.jar
But that was yesterday with IDEA 9.0.1. See below...
UPDATE
Today I uninstalled IntelliJ 9.0.1, and installed 9.0.2 Early Availability, with the 4/14 stable version of the Scala plug-in.
Then I setup a project from scratch through the wizards:
new project from scratch
JDK is 1.6.u20
accept the default (project) instead of global / module
accept the download of Scala 2.8.0beta1 into project's lib folder
Created a new class:
object hello {
def main(args: Array[String]) {
println("hello: " + args);
}
}
For my efforts, I now have a brand-new error :)
Here it is:
Scalac internal error: class java.lang.ClassNotFoundException [java.net.URLClassLoader$1.run(URLClassLoader.java:202), java.security.AccessController.doPrivileged(Native Method), java.net.URLClassLoader.findClass(URLClassLoader.java:190), java.lang.ClassLoader.loadClass(ClassLoader.java:307), sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301), java.lang.ClassLoader.loadClass(ClassLoader.java:248), java.lang.Class.forName0(Native Method), java.lang.Class.forName(Class.java:169), org.jetbrains.plugins.scala.compiler.rt.ScalacRunner.main(ScalacRunner.java:72)]
FINAL UPDATE
I uninstalled 9.0.2 EA and reinstalled 9.0.1, but this time went with the 2.7.3 version of Scala rather than the default 2.7.6, because 2.7.3 is the one shown in the screen-shots at the IntelliJ website (I guess the screen-shots prove that they actually tested this version!). Now everything works!!!
I have encountered the same scalac error when trying to run a Scala project in Intellij Idea 9.0.2 and I've managed to find a solution by chance :). These are the steps I took in creating the project and running it.
I have created a Scala project in Intellij Idea 9.0.2 final (it was released today). I have installed the Scala plugin, restarted the IDE and created a new Scala project (with the name "TestScala") with scala-2.8.0.Beta1 as project library. Once the project is created and the scala libraries downloaded, I have created a Test.scala file with the following content:
object Test {
def main(args:Array[String]){
println("hello")
}
}
After that, I created a launch configuration ("Edit Configurations"), choosing the "Application" template. I set as main class Test and choose the project name ("TestScala") in the "Use classpath and JDK of module" combo box. When I run the configuration I get the same error as you reported ("Scalac internal error: class java.lang.ClassNotFoundException") .
Now comes the freaky part :). I right click on the project, choose "Module Settings", have a look on all settings but I don't change anything . Click "apply" and "ok", try to run configuration again and it works :) .
I use Intellij Idea 9.0.2 the final release (build 95-66); Ubuntu 9.10 and JDK 1.6.0_18. I also have to mention that I had a JDK configured in Intellij, otherwise there is an extra step to configure it.
UPDATE:
When checking the setting of the module, one needs to click on the Module->Scala and Facets->Scala (expand it and click on Scala(ProjectName)) . Both of these settings are about the scala compiler and scala library location. I would guess these values are not properly set when the project is created but are saved once the user touches them and saves the settings.
To answer your question, it's difficult to get a working IDE for Scala for two reasons:
(a) Scala is only just beginning to reach a wide audience and
(b) due to (a), there is no business case for spending time on a Scala IDE.
Also, if you are old enough to cast your mind back and young enough to still remember, you would know that for the first five or more years of Java, we were stuck with okay-ish tools like JBuilder that did little more than compile your code when you said so - no error highlighting, no auto-importing, and the word refactoring didn't even exist. If you want to pioneer, you need to be prepared to cut some of the road yourself, or at least bush-bash.
I know it won't help you, but I have successfully used IDEA for Scala on Linux, Mac and Windows. I typically have the Scala SDK installed somewhere locally and point IDEA at that rather than using the 'download' option.
Presently, I am mostly using an EAP version of IDEA 9 on Mac OS X with Scala 2.8.0.Beta1-RC5 and it's working well (except that fsc doesn't seem to worked with mixed sources).
You could try your luck over at the IDEA Scala Plugin Discussion Forum, though I haven't had a great lot of responses to my own postings there.
Installing the plug-in is prerequisite one.
The next thing you should do is define a library (global or project-specific; I use global) that holds the Scala library and compiler JAR files (at a minimum, that's scala-compiler.jar and scala-library.jar). Adding source JARs and a documentation JAR or URLs is a good idea, too. Then make this library a dependency of any modules in your project that include Scala code.
Lastly, find the Scala facets in those modules and de-select both check-boxes there.
I just did a fresh install and had exactly this same problem myself.
It turned out that, because I had created the file in the root package, IDEA had added a package statement at the top with naming a package. I assume that this then got compiled as "package object Main" - valid syntax in 2.8? Anyway, I deleted the line that said package and it all worked fine.
I had the same problem yesterday while trying to set it up. Solution is pretty simple, you just have to set scala somewhere in project settings.
You are mixing code compiled with two different Scala versions.
I use Netbeans to write scala programs. So far it works very well with my codes. You can try the plugin here: http://wiki.netbeans.org/Scala68v1.
I was getting this error and also had to right click on the project and "Open Module Settings". However, it was more than just hitting apply. I had to make sure that my Content Root was correct for each project. For some reason, there were some incorrect Source and Test Folders.
My project uses maven as the main build tool and importing the project into Intellij is probably what created these incorrect settings.
I had similar problem, following this blog post instructions solved the problem for me

How does Eclipse compile classes with only a JRE?

I need to batch a compilation with a special JRE which has been "customized".
Eclipse is able to compile the classes with this JRE, but I need to make a build script outside of Eclipse.
What is the method used by Eclipse to generate the .class files without a JDK?
Eclipse comes with its own compiler for the following reasons:
Incremental compilation (can compile just the changed parts of the project which can mean more than the amount of files you just saved, for example, when you changed some global)
The Eclipse compiler can create a class file even when the code contains errors. This allows to run the project even though not everything compiles.
The compiler provides Eclipse with an AST so it can do all kinds of fancy stuff (like the outline, show you all the places where the variable under the cursor is used, etc) at no extra cost (i.e. it doesn't have to run the compiler and another parser).
I believe Eclipse comes with internal compilers, and you can choose the compatibility to Java 1.3 through 1.6 (check the Preferences menu, under Java->Compiler). So Eclipse doesn't need an external JDK to compile, because it comes with it is self-sufficient.
If you want to create a build script outside of Eclipse, you're gonna need an external compiler, like the one that comes with the real JDK.
For the case one is interested: Eclipse's compiler is part of JDT core.
Eclipse was originally created by IBM. Eclipse has its own built-in Java compiler which is based on IBM's Java compiler, Jikes.