jython ImportError: No module named - jar

I'm new to jython and failing utterly at importing a java class within a jar.
What I am trying to do is write a wrapper shell script which calls a jython script. I can not allowed to edit the jython at all, so adding jars to sys.path within that jython script is not possible.
Error
y", line 17, in
from com.polarland.testModule.cache import CacheInterface
ImportError: No module named polarland
I've added the jar which contains the above package with name of TestModule.jar to PATH, ClASSPATH and JYTHONPATH with no avail. I'm worried this is due to the name of the jar but am not sure.
Any advice would be greatly appreciated!!

In your shell script use:
export CLASSPATH=TestModule.jar:$CLASSPATH
jython ...
In my case setting CLASSPATH is enough. Remember to use full path name and remember to use good .jar name (testmodule.jar and TestModul.jar are different). Maybe you use wrong file rights. Try file command to check if you can read that file. Example for one of jars I use:
mn$ file junit-4.1.jar
junit-4.1.jar: Zip archive data, at least v2.0 to extract

I was getting same issue.
I tried below function and worked well!
>>> import sys
>>> sys.path.append('/path/to/helloworld.jar')
>>> from com.leosoto import HelloWorld
For more info:
http://blog.leosoto.com/2008/07/jython-import-logic.html

Related

airflow not recognize local directory ModuleNotFoundError: No module named

my project structure looks like :
my_project
-dags
-config
however on airflow dashboard I see an error Broken DAG pointing to this line : from config.setup_configs import somemethod
and yields this err:
Broken DAG: [/usr/local/airflow/dags/airflow_foo.py] No module named 'config'
although the directory exists
According to documentation Airflow has, by default, three directories to path
AIRFLOW_HOME/dags
AIRFLOW_HOME/config
AIRFLOW_HOME/plugins
Any other path has to be added to system path, as described in airflow module management
For sake of simplicity, I added my module mymodule.py to AIRFLOW_HOME/plugins and I can import them successfully.
from mymodule import my_method
So, in your case, if you rename configurations to plugins and update import statement into DAG,
from setup_configs import somemethod
it should work.
You need to move the config directory into the dags folder and create an empty __init__.py file within the config folder. Then, it should work.

BaseX: import xar file directly in .xqy file

I need to use some external module in BaseX. I install the package first with:
$ basex -c"REPO INSTALL http://files.basex.org/modules/expath/functx-1.0.xar"
So I wonder if there is a way not to install this package with the command above, but reference the module in .xqy like:
import module namespace functx="http://www.functx.com" at "functx-1.0.xar";
This is not possible. However, you can either specify your query as second argument after the REPO COMMAND call (in the same BaseX call) and drop it afterwards, similar to:
basex -c"REPO INSTALL http://files.basex.org/modules/expath/functx-1.0.xar"
your-query.xq -c"REPO DELETE functx-1.0.xar"
Or you’ll need to unzip the XAR file in advance and reference with the single functx library module file:
import module namespace functx = "http://www.functx.com"
at "./relative/or/absolute/path/to/functx.xq";

py2exe PyQt5 "ImportError: No module named 'Qt'"

im trying to use py2exe (0.9.2.0) to convert a python script into an executable.
I've failed so far because py2exe does not find the module Qt:
C:\Users\Tobias\eclipse\workspace\pydevTest>python setup.py py2exe
running py2exe
5 missing Modules
------------------
? Qt imported from __SCRIPT__
? WizardPage imported from __SCRIPT__
? readline imported from cmd, code, pdb
? win32api imported from platform
? win32con imported from platform
Building 'dist\Test.exe'.
Building shared code archive 'dist\library.zip'.
Copy c:\windows\system32\python34.dll to dist
Copy C:\Python34\DLLs\_hashlib.pyd to dist\_hashlib.pyd
Copy C:\Python34\lib\site-packages\PyQt5\QtGui.pyd to dist\PyQt5.QtGui.pyd
Copy C:\Python34\lib\site-packages\PyQt5\QtCore.pyd to dist\PyQt5.QtCore.pyd
Copy C:\Python34\DLLs\unicodedata.pyd to dist\unicodedata.pyd
Copy C:\Python34\DLLs\_ssl.pyd to dist\_ssl.pyd
Copy C:\Python34\DLLs\_elementtree.pyd to dist\_elementtree.pyd
Copy C:\Python34\DLLs\select.pyd to dist\select.pyd
Copy C:\Python34\lib\site-packages\sip.pyd to dist\sip.pyd
Copy C:\Python34\lib\site-packages\PyQt5\QtWidgets.pyd to dist\PyQt5.QtWidgets.pyd
Copy C:\Python34\DLLs\pyexpat.pyd to dist\pyexpat.pyd
Copy C:\Python34\DLLs\_lzma.pyd to dist\_lzma.pyd
Copy C:\Python34\DLLs\_socket.pyd to dist\_socket.pyd
Copy C:\Python34\DLLs\_bz2.pyd to dist\_bz2.pyd
Copy C:\Python34\DLLs\_ctypes.pyd to dist\_ctypes.pyd
Copy DLL C:\Python34\lib\site-packages\PyQt5\Qt5Core.dll to dist\
Copy DLL C:\Python34\lib\site-packages\PyQt5\icudt53.dll to dist\
Copy DLL C:\Python34\lib\site-packages\PyQt5\icuuc53.dll to dist\
Copy DLL C:\Python34\lib\site-packages\PyQt5\icuin53.dll to dist\
Copy DLL C:\Python34\lib\site-packages\PyQt5\Qt5Gui.dll to dist\
Copy DLL C:\Python34\lib\site-packages\PyQt5\Qt5Widgets.dll to dist\
My setup.py looks as follows:
import py2exe
from distutils.core import setup
setup(windows=["./src/Test.py"], options={"py2exe" : {"includes" : ["sip", "PyQt5.QtGui","PyQt5.QtWidgets","PyQt5.QtCore","PyQt5.QtCore"]}})
The script is rather simple. After getting rid of the first error, I might also help with the four other missing modules...
Thanks a lot!
you need to add the following dlls:
C:\Windows\SYSTEM32\msvcp100.dll
C:\Windows\SYSTEM32\msvcr100.dll
C:\Python34\Lib\site-packages\PyQt4\plugins\platforms\qwindows.dll
somethings like this:
data_files = (
('', glob(r'C:\Windows\SYSTEM32\msvcp100.dll')),
('', glob(r'C:\Windows\SYSTEM32\msvcr100.dll')),
('platforms', glob(r'C:\Python34\Lib\site-packages\PyQt4\plugins\platforms\qwindows.dll')),
),
Sorry, the previous answer did not work for me: https://stackoverflow.com/a/37622355/7426109
(and I have different versions)
What did work on the other hand is to add this to your path: "C:\Program Files (x86)\Python38-32\Lib\site-packages\PyQt5\Qt\bin".
My temporary fix:
You copy the "Qt" ("C:\Program Files (x86)\Python38-32\Lib\site-packages\PyQt5\Qt") folder to "dist", and use a batch script to add ".dist\Qt\bin" to PATH in the current CMD window. (of course, this is not perfect, but at least can be executed on another machine)
Info
Windows 10 x64, Python 3.8.6 x32, PyQt5==5.15.1, py2exe==0.10.0.2

Package does not exist - error

I am trying to compile a .java file (TransformRTDE.java) that uses several import statements. These statements import .class files present in five external JAR files: dataextract.jar, jna.jar, JRI.jar, JRIEngine.jar and REngine.jar. I have read documentation on how to deal with these import statements while trying to compile your .java file from the command line. However, I do not seem to succeed.
I set up the directory in the command line to be the folder in which my .java file resides. In that same folder, I have put the JAR files. When I try to compile the code using java -cp dataextract.jar jna.jar JRI.jar JRIEngine.jar REngine.jar TransformRTDE.java, I get a package does not exist error. I have set up the class path to include the folder in which all my .java and .jar files reside.
I have searched for hours on this without success. Any ideas what I'm doing wrong?
Thanks in advance!
EDIT: I forgot to mention I also get an error related to annotation processing.
Picture can be found here: https://www.dropbox.com/s/p9ul0olydzmkl6s/error.png

Java compile error. servlet-api.jar

I created simple Java Servlet: WelcomeServlet.java.
Than, I tried compile this file via:
javac WelcomeServlet.java
In result I see compile error:
package javax.servlet doesn't exit
I try find solution for this error with Google. And I find first part of answer: java compiler doesnt see servlet-api.jar file.
I know, that Apache Tomcat in it lib folder contains servlet-api.jar file.
So, I have this file, but where I must copy this file??
I try different folders:
echo %JAVA_HOME%
C:\Program Files\Java\jdk1.6.0_26
%PATH% contains this line: C:\Program Files\Java\jdk1.6.0_26\bin
So, I copy in:
%JAVA_HOME%\bin
%JAVA_HOME%\lib
%JAVA_HOME%\jre\lib
And in result same error.
And only after I copy servlet-api.jar in directory:
%JAVA_HOME%\jre\lib\ext
compilation complite sucessful.
My question: Why? Why I must copy in folder %JAVA_HOME%\jre\lib\ext ??
Where This moment describe in documentation?
And other question we have some official docs or specifications that describe folder structure for jdk folder??
You'll need to specify the directory or directories you want the compiler to search by using the -classpath command line option when running javac. The reason the compiler found your .jar in %JAVA_HOME%\jre\lib\ext is because it searches the extension directories by default.
This is for Java 1.5, but I believe it is more or less still correct:
http://docs.oracle.com/javase/1.5.0/docs/tooldocs/findingclasses.html
The link Shaun provides is a more complete answer. But in short, using the classpath is the best way to introduce 3rd party or external (to the JDK/JRE) libraries. The classpath is a concept much like the %PATH% or the $PATH variables, but specifies locations for java to use for lookup rather than the shell to use for lookup of executables.
The classpath provides the java compiler or java virtual machine a list of items to use when searching for resources. This "path" may include directories or files. It will typically include jar files and sometimes locations of configuration files. Many Java based lookup schemes for files configuration or otherwise use some variant of what is accomplished by [Class#getResourceAsStream()][1]'s use of walking the Classpath.
I have rarely seen an incident where putting a jar file in the lib/ext location was preferred to utilizing the Classpath.
The classpath is typically an environment variable (%CLASSPATH% or $CLASSPATH) or specified on the command line when running java or javac (e.g. -cp or -classpath see the help from the executable you are running).
Build tools such as Ant and Maven will also provide abstractions to defining the list of jars to be utilized by your applications and are highly recommended to be used for any length of repetitive change code, build, test, run cycles.

Resources