I was working on a text-analysis project in R and needed a stemmer. I found a JAR-file of a java compilation of a snowball stemmer. Documentation:
http://lucene.apache.org/core/3_0_3/api/contrib-snowball/
Download link (bottom link):
http://www.java2s.com/Code/JarDownload/snowball/
Now, as far as I could tell, this R code should make a new stemmer object:
library(rJava)
.jinit("D:\\myUser\\Documents\\snowball.jar")
stemmer <- .jnew("org.tartarus.snowball.ext.EnglishStemmer")
However the final line of code gives the following error:
Error in .jnew("org.tartarus.snowball.ext.EnglishStemmer") :
java.lang.ClassNotFoundException
After spending quite a lot of time on this (among others, reading the following post for help: https://darrenjw.wordpress.com/2011/01/01/calling-java-code-from-r/), I got stuck because I am not sure what the exact problem is. As far as I can tell, it could be in order of likelyhood:
1. a mistake in my code
2. an issues with dependancies
3. the JAR file is corrupted somehow
Can anyone give me some pointers on where the problem might lie?
Edit: answered, see comments. The class names in this specific jar-file are lowercase.
Related
I have received the task, at work, to find a way to use some methods from an existent jar file in a Python project. I have very limited experience in Python, but I have worked with that specific jar file before (it is part of a project we are working on). I am not allowed to modify much of both projects, and they are required to be as independent as possible.
I have researched multiple ways to include the jar methods in Python. So far, I have tried Jython (which I cannot use because the Python project uses PyQt among other libraries, which force the use of CPython, if my understanding is correct), Pyjnius and JPype. JPype seems the most promising, but I cannot get it working either. I have pasted the my code below, slightly censored because I don't know how much I am allowed to share.
from jpype import *
import jpype.imports
try:
jpype.addClassPath("jars/sdk.jar") #the relative path to the jar file
jpype.startJVM(convertStrings=False)
java.lang.System.out.println(jpype.getClassPath()) #printing the classpath to check, the path is correctly pointing to the sdk.jar file
java.lang.System.out.println("Hello world") #just to check if jpype is installed correctly, works
jpype.imports.registerDomain("a")
from a.b.c.d.e.f.g.h import SomeClass #fails here
except OSError as err:
print(err) # ToDo: Remove print when done
pass
The error I am getting is that the module a.b.c.d.e.f.g.h.SomeClass could not be found. I have tried different ways to give the path (absolute path, relative path, place the jar in different places in the project and outside of it), but that doesn't seem to be the problem, as the path printed is the correct absolute path to the jar file.
Also, the jar is used in other (Java) projects and it works. It is created using maven package (using IntelliJ, if it is relevant, and the same Java version as the one used by the JPype JVM). In the Java projects, the import would be:
import a.b.c.d.e.f.g.h.SomeClass;
I have copied this and just transformed the syntax into Python.
I have also tried to create the class with JObject (which I probably didn't do right anyway) and also tried the older syntax (to my understanding) with JPackage. For the JPackage way, I am getting the exception that the package a.b.c.d.e.f.g.h.SomeClass.someMethod is not Callable, which to my understanding is an equivalent exception to the one I'm getting using jpype imports. I have already gone through all the questions I could find here with similar problems, but none of those solutions have helped me.
Can anyone suggest some possible solution? Or can anyone see what I'm doing wrong? Suggestions of other possibilities to replace JPype are also welcomed. If there is any clarification needed, I will edit the question.
The only thing that seems likely if the jar is on the classpath and failed to import would be for there to be some missing dependency. You have two other ways to try loading the class which may provide additional diagnostics.
jpype.JClass("a.b.c.d.e.f.g.h.SomeClass")
and
jpype.JClass("java.lang.Class").forName("a.b.c.d.e.f.g.h.SomeClass")
The first is manually loading a class by full class specification. It is mechanically what is happening under the import. The second is calling for Java to load the class (bypassing all of JPype). It returns a java.lang.Class which can be passed to JClass to make a wrapper.
Common failures include missing a jar or native library, attempting to start JPype from within a module and having the wrong relative path, error in initialization of the class due to missing resource. JPype is just calling JNI calls, so if everything is fine on Java end it should work. Given that you checked the java.class.path System variable, it has to be something to do with class resources.
The JPype user manual has an alternatives section if you would like to try to find another package. Most of the alternatives with the exception of PyJnius appear to be unmaintained.
I have a file called MyFile.java and it contains multiple classes(none of them is public). Note that the file does not contain MyFile class. Apparently Javadoc is not happy about this and it generates a warning saying file does not contain class com.example.MyClass. A few solutions I looked into:
Move classes into their own files. This looks like the proper way of fixing the warnings, but the new files won't obliviously have the source control history, so I am trying to avoid it.
Create empty MyFile class. This is ugly.
Hide Javadoc warnings, preferably per file. There is a high chance that this is not possible.
A few questions that I have:
Why does Javadoc complain? I couldn't find any documentation, please point me to one. I think it is perfectly fine not to have a class with the same name as the file.
Any other suggestions I can look into?
Is it possible to hide warnings somehow? additionalparam="-Xdoclint:none" does not work.
Thank you all in advance
When building with maven from the command line, I encountered this error from maven-javadoc-plugin.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:3.2.0:jar (default) on project code-mapping-database: MavenReportException: Error while generating Javadoc:
... error: cannot access DataSourceWrapper
Eclipse IDE reported a similar error.
This occurred after I had copied DataSourceWrapper.java to another (dependent) project and commented out all lines of DataSourceWrapper.java in the original project. After deleting the commented out version, the error went away. The effectively empty DataSourceWrapper.java file must have caused maven-javadoc-plugin to stop looking for class DataSourceWrapper.
http://nlp.stanford.edu/software/openie.shtml generates compile time error :
SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation cannot be resolved to a type
I am running java-8 under eclipse 2016. corenlp-full-2015-12-01.zip, openie.jar, openie-models.jar are in included in my eclipse project.
Error generated by line of:
System.out.println(sentence.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class).toString(SemanticGraph.OutputFormat.LIST));
thanks
If I were to guess, this sounds like a classpath issue. What happens if you remove either openie.jar or the corenlp distribution? In theory, openie.jar should contain everything you need to run the Open IE system.
I have the same error.
What does this package edu.stanford.nlp.naturalli; in the first line of the code snippet mean?
I do not have much Java knowledge, I just created a Java project somewhere and included the same files as WH Sweet did.
I just found that within the corenlp project subfolder naturalli there is a OpenIEDemo.java already. Maybe the explanation for this would solve the initial problem..
Im trying to run this code at http://zetcode.com/tutorials/javagamestutorial/puzzle/
1 error found:
File: /Users/java/PuzzleEx.java [line: (no source location)]
Error: File is in the wrong directory or is declared part of the wrong package. Directory name 'java' does not match package name 'zetcode'.
Please help, how do I run it?
Well, first you need to compile it using javac, then you could run it. However, I'd suggest doing nothing of the sort. Just browsing through the link you provided, I'm seeing some bad practices, and outdated code (not declaring variables as interfaces, stuffing all the classes in one file, etc). Instead of following some third party, potentially outdated, tutorial, take a look at the official tutorials: https://docs.oracle.com/javase/tutorial/
Not only are the official tutorials always up to date, but they're also laid out in easy-to-follow trails and paths.
Edit:
Also, the reason it's not working is exactly as the error says: it's in a different folder than its package is declared to be. If you don't know what a package is, please take a step back and learn the basics first.
org.renjin.eval.EvalException: lubridate could not be found at
org.renjin.primitives.packaging.NamespaceRegistry.load(NamespaceRegistry.java:83) at
org.renjin.primitives.packaging.NamespaceRegistry.getNamespace(NamespaceRegistry.java:63)
...
I think the function lubridate is not implemented in renjin?
How can i know what functions are implemented?
Lubridate is actually an R package, not a function from R itself. You would need to include the jar for the lubridate package on your classpath.
Unfortunately, it appears that Renjin is not yet able to run this package: see http://packages.renjin.org/packages/lubridate.html for latest status of this and other packages.
Check back in a week or so for the next release candidate, we're fixing a lot of these problems.