Jython 2.7.0 "Final Release" on Windows - difficulty including jars - command-line

I have a few projects which run using Jython 2.7b1 where I add the jars (in fact all the jars in a directory) by doing this:
set CLASSPATH=.;"%SYSADMIN%\resources\java jar files/*"
set JYTHONPATH=...
C:\jython2.7b1\jython myproj\__main__.py
But my latest project is using 2.7.0FR and this "set CLASSPATH" approach doesn't seem to work. I then tried this:
D:\apps\jython2.7.0\bin\jython -Dpython.path="%SYSADMIN%\resources\java jar files/*" my_latest_proj\__main__.py
... but it didn't work. Then I wanted to see whether I could load an individual .jar:
D:\apps\jython2.7.0\bin\jython -Dpython.path="%SYSADMIN%\resources\java jar files\lucene-analyzers-common-4.6.0.jar" my_latest_proj\__main__.py
This didn't work either: the following line
from org.apache.lucene.analysis.fr import FrenchAnalyzer
leads to the following error: "No module named apache"... nor is there any "unpacking" of the jar as you typically see with Jython the first time you use a jar.
Finally I tried this:
set CLASSPATH=.;"%SYSADMIN%\resources\java jar files\lucene-analyzers-common-4.6.0.jar"
... same thing: "No module named apache"
NB I have no trouble getting jars to work from within my project when running it under Eclipse.
Can anyone tell me what I'm doing wrong?

Aha...!
1) It appears that with Jython2.7.0FR you have to use forward slashes in paths in the CLASSPATH, even in a Windows OS. This appears to be a change relative to 2.7b1...
2) I also seem to find that paths with spaces are to be avoided... previously I could enclose such a path in quotes and it would work OK. This seems not to work any more.
Any comments from the Jython "High Command" would be welcome...

Related

Keep Getting Error When Trying to Run Javafx on Eclipse with Mac

So I keep getting this error when trying to run my program:
Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.controls not found
I'm using a mac with eclipse, and my VM argument is:
--module-path /Users/myname/Desktop/javafx-sdk-11.0.2_3/lib --add-modules javafx.controls,javafx.fxml
I've tried everything, javafx.controls.jar and the other .jar file are in my lib folder. I've reinstalled the javafx program, changed my file path around hundreds of times, and I've tried to install plugins. Does anyone have any idea as too what can be happening? JavaFX is also an added library in my project, and all the .jar files assocated with it are added to it. Please let me know if anyone has an idea. Best!
I had success with the following additional step.
In the Run Configuration->Dependencies tab, click the "ModulePath" and then add the JavaFX JDK's jars (or the /lib folder that holds the jars) to the list.
You can inspect the generated command line, and check that these are included in the -p option.
IDK why this step should be needed. I would think Eclipse should be smart enough to include something on the dependency module path if it were in the project's Build Path Library list.
I have questions about this at eclipse.org and gluon. Maybe there will be an explanation, or fix so that this step isn't needed, or an edit to the documentation to let us know we need to do this.

Program runs in eclipse, but not in .jar form

I ran it in cmd and it said no main manifest attribute in, JGame2.jar
how do i show it where the main is?? it works fine in eclipse.
For
java -jar x.jar
to work, the jar file must contain a META-INF/MANIFEST.MF file, and this file must contain an entry for the main class. You can add a manifest in Eclipse. Note that any dependencies must also be accounted for, either by:
a class path in the manifest
-cp on the command line
use of some tool to combine to one jar
Eclipse is just an IDE, you might consider learning to use an actual build tool such as Maven or Gradle or Ant to allow you to repeatably build usable results.

Groovy:unable to resolve class org.apache.commons.lang.time.DateFormatUtils

I have a Groovy script in Eclipse and I get the following at the import statement:
Groovy:unable to resolve class org.apache.commons.lang.time.DateFormatUtils
When I add the external commons-lang-2.4.jar to the Libraries in the build path, the error message goes away. But if I remove it and instead add the external Class Folder that contains this and other jars, then I get the error message.
Try adding the jar by navigating to Preferences->Java Build Path->Libraries and using add External JARs. I don't believe Eclipse will pick up the various jar files in a folder for compilation - you may need to be explicit with each JAR, and I don't think it supports wildcards for those as command-line javac does these days. (See aspects of this answer for some treatment of this, and a potentially interesting plugin).

How do I get my java program written with NetBeans to compile with javac?

I have two java files. They run fine in NetBeans, but I have to compile them in javac, and run them on a unix machine since I'm connecting to a database on my school's server.
I've been searching online but everything is too specific, and I'm not too familiar with NetBeans.
What I'm doing is copying those two java files, and a .form file to a directory on my school's server, and then try to compile the two java files using javac. However, I'm assuming that it doesn't compile because it's missing all the information from the .form file?
I'm getting 100 errors when compiling the one of the java files, and they look something like this:
CARTSJFrame.java:380: package org.jdesktop.layout does not exist
.add(jPanel9, org.jdesktop.layout.GroupLayout.PREFERRED_ SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLay
My guess was that it has something to do with the .form file that I can see in my NetBeans project directory.
I've looked at previous questions about this but still haven't been able to figure this out. Any help is appreciated.
You are running into compilation errors because NetBeans includes a jar in your project's classpath automagically when you compile and run the project.
NetBeans uses the dot-form file to help it generate code for the layout. It is not used at compilation time.
There are a couple strategies that you can follow to resolve this problem:
Get the jar that has the classes...
http://www.findjar.com/jar/net.java.dev.swing-layout/jars/swing-layout-1.0.1.jar.html;jsessionid=252692AC0FBE9421C9436A748744ACED... and include that jar in your
classpath at compile and runtime.
Convert the code in your project to
use the javax.swing.GroupLayout.
This is a 'standard part' of Java SE 6. This SO answer covers how to convert between
org.jdesktop.layout.GroupLayout and
javax.swing.GroupLayout in
NetBeans.
I think your problem is that javac doesn't know where to find that library.
A typical Java project uses many libraries. Netbeans uses a folder "lib" to store those libraries and also some configuration files to automatically set the classpath. The classpath is a environment variable that Javac uses to 'know' where are the libraries.
When you use javac to compile the java files you need to provide the CLASSPATH variable first. Write all you dependencies.
An example:
Project/compile_all.sh
export CLASSPATH=$CLASSPATH:"lib/jopt-simple-3.2.jar":"lib/commons-io-2.0.jar"
javac src/*.java
Now you just need to run
sh compile_all.sh
And it compiles all you .java files

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