Importing voce.jar into a java file properly - java

I have downloaded a voice/text API for java from
http://voce.sourceforge.net/
However being semi new to java I am unsure how to use all these jar files in my code, have tried several things like import voce, import java.voce, package (my folder name with the voce jar inside).
However I am getting no luck.
Code I am trying is
import java.voce;
public class SpeechInterface
{
public static void main(String[] args){
voce.SpeechInterface.synthesize("hello world");
}
}
Error I get is that it cant find voce(since I am obviously doing this wrong). Have looked through stackoverflow but was unable to find a question that answers this. I imagine there is one like this already but I can not find it. Closest I could find was the importing voce to C, but that wasn't to helpful.
The jar file is in same directory as the java file.

try using
import voce.*
If you look at http://voce.sourceforge.net/api/java/_speech_interface_8java-source.html
It mentions the package as (package voce).

Here under the Tab no 10. You can find how to add a Jar file to Dr.Java IDE,
Then as Kakarot Mention , you should to write
import.voce.*;
if you need all the classes of package voce,
or write
import.voce.classname
to import a specific class.

Related

How to import correct package for StdDraw?

I want to use the StdDraw package, and I've tried many different ways of importing it.
Of course I tried:
import StdDraw;
But, when I look at the documentation from Princeton here, it shows that StdDraw is part of Objects, so I try this:
import java.lang.Object.StdDraw;
However, this results in an error:
error: cannot find symbol in
import java.lang.Object.StdDraw;
I saw this question here but it does not answer this question either.
How do I import StdDraw? thank you.
if you want to use StdDraw you must have
either the sources
or the classes (best zipped up as jar)
as preferred way you use the sources (see http://introcs.cs.princeton.edu/java/15inout/). it says there "To use these libraries, download StdIn.java, StdOut.java, StdDraw.java, and StdAudio.java into the same directory as your program. "
once you did this the imports should be working.
NOTE: all four files are not in packages, so you should 'download' them into the 'standard' package. That means you have to download them to the root package of your project.
by the way: don't import import java.lang.Object.StdDraw; but do just import import StdDraw;
First of all check encoding of your IDE. It should be set to UTF-8. It is important if you are using MS Windows operating system.
Then create StdDraw.java class in the same package as the package of your program you are writing. Remove class declaration, leave only package declaration.
Then visit this page: https://introcs.cs.princeton.edu/java/stdlib/StdDraw.java .
Copy all its contents (Ctr-A, Ctrl-C) and then paste it into StdDraw.java file you created previously.
StdDraw.java has its own main method so try to run it in order to check that the library works correctly. You should see a window with four strange figures :) .
Don't touch StdDraw.java anymore. Now you can easily import StdDraw library and refer to its methods with name of the class.
Enjoy

I don't understand how to use an imported library in Java, in Netbeans

I have searched and read many similar questions here, but I could not figure it out using solutions others have posted. Hence the need to ask a new question.
I downloaded Apache Commons Math. I then installed the jar file to my libraries of the project I am working on (in Netbeans):
So in RSA.java, I would like to use the nextLong method, as seen here:
I have tried numerous import statements, such as:
import commons-math3-3.4.1.*;
or
import docs.apidocs.org.apache.commons.math3.*;
But regardless, it gives me "package does not exist" no matter what I try:
Use the javadoc to locate the correct name of the class
import org.apache.commons.math3.random.RandomDataGenerator;

Java Classes from WSDL and Eclipse

I am trying to create and use a set of Java classes from WSDL using Apache Axis 2. I’ve successfully generated the class files using the approach described here:
http://www.gerd-riesselmann.net/scala/creating-java-classes-wsdl-file-using-apache-axis-2
I have copied the generated class files into my eclipse development environment. I have obtained all the necessary jar files and I have added them to my environment.
A single (source) problem remains that I don’t understand. The code section looks like this:
...
public org.tempuri.PreprocessingIncidentImportServiceStub.ImportResponse
import (org.tempuri.PreprocessingIncidentImportServiceStub.Import import0)
throws java.rmi.RemoteException
{
org.apache.axis2.context.MessageContext _messageContext = null;
...
Eclipse is reporting: Syntax error on token "import", expected identifier.
I don't understand the function definition that includes the "import" statement, and I am wondering if there's some eclipse setting that I must use to resolve this problem.
Thanks in advance for any help.
It seems that the method is named import. Import is a reserved word in Java so you can't name a method with it.
Assume that you have imported the classes and doesn't need to use the full qualified name of them. This is what you have:
public ImportResponse import (Import import0) throws RemoteException{
//...
}

GeoGoogle(Java) - How to import the file?

I'm trying to use GeoGoogle for geocoding purposes from http://geo-google.sourceforge.net/
When I tried to use this line of code:
import geo.google.GeoAddressStandardizer;
GeoAddressStandardizer st = new GeoAddressStandardizer("AABBCC");
It says GeoAddressStandardizer and the import cannot be resolved, I also added the JAR to the build path already.
Has anyone met this issue before? Thanks
Solution: Get the geoGoogle-1.5.0.jar Instead inside https://www.cs.drexel.edu/~zl25/maven2/repo/geoGoogle/geoGoogle/1.5.0/
having a quick look through the geo-google source, this does exist as a constructor here.
public GeoAddressStandardizer(String apiKey)
So the problem has to lie in the way your application is using the jar. Are you deploying to a web server or something like that (although I'd expect a classNotFoundException)?
If you look at the build config in your IDE, does the jar exist? How did you add it?

Using the Stanford NLP libraries from within R, using the rJava package

Does anybody have any experience with using StanfordCoreNLP ( http://nlp.stanford.edu/software/corenlp.shtml through rJava in R? I’ve been struggling to get it to work for two days now, and think I’ve exhausted Google and previous questions on StackOverflow.
Essentially I’m trying to use the StanfordNLP libraries from within R. I have zero Java experience, but experience with other languages, so understand the basics about classes and objects etc.
From what I can see, the demo .java file that comes with the libraries seems to show that to use the classes from within Java, you’d import the libraries and then create a new object, along the lines of:
import java.io.*;
import java.util.*;
import edu.stanford.nlp.io.*;
import edu.stanford.nlp.ling.*;
import edu.stanford.nlp.pipeline.*;
import edu.stanford.nlp.trees.*;
import edu.stanford.nlp.util.*;
public class demo {
etc.
etc.
StanfordCoreNLP pipeline = new StanfordCoreNLP();
etc.
From within R, I’ve tried calling some standard java functions; this works fine, which makes me think it’s the way I’m trying to access the Stanford libraries that’s causing the issue.
I extracted the Stanford ZIP to h:\stanfordcore, so the .jar files are all in the root of this directory. As well as the various other files contained in the zip, it contains the main .jar files:
joda-time.jar
stanford-corenlp-1.3.4.jar
stanford-corenlp-1.3.4-javadoc.jar
stanford-corenlp-1.3.4-models.jar
joda-time-2.1-sources.jar
jollyday-0.4.7-sources.jar
stanford-corenlp-1.3.4-sources.jar
xom.jar
jollyday.jar
If I try to access the NLP tools from the command line, it works fine.
From within R, I initalized the JVM and set the classpath variable:
.jinit(classpath = " h:/stanfordcore", parameters = getOption("java.parameters"),silent = FALSE, force.init = TRUE)
After this, if I use the command
.jclassPath()
This shows that the directory containing the required .jar files has been added and gives this output in R:
[1] "H:\RProject-2.15.1\library\rJava\java" "h:\ stanfordcore"
However, when I try create a new object (not sure if this is the right Java terminology) I get an error.
I’ve tried creating the object in dozens of different ways (basically shooting in the dark though), but the most promising (simply because it seems to actually find the class is):
pipeline <- .jnew(class="edu/stanford/nlp/pipeline/StanfordCoreNLP",check=TRUE,silent=FALSE)
I know this finds the class, because if I change the class parameter to something not listed in the API, I get a cannot find class error.
As it stands, however, I get the error:
Error in .jnew(class = "edu/stanford/nlp/pipeline/StanfordCoreNLP", check = TRUE, :
java.lang.NoClassDefFoundError: Could not initialize class edu.stanford.nlp.pipeline.StanfordCoreNLP
My Googling indicates that this might be something to do with not finding a required .jar file, but I’m completely stuck. Am I missing something obvious?
If anyone can point me even a little in the right direction, I’d be incredibly grateful.
Thanks in advance!
Peter
Your classpath is wrong - you are using a directory but you have JAR files. You have to either unpack all JAR files in the directory you specify (unusual) or you have to add all the JAR files to the class path (more common). [And you'll have to fix your typos, obviously, but I assume those come form the fact that you were not using copy/paste]
PS: please use stats-rosuda-devel mailing list if you want more timely answers.
Success!
After hours of tinkering, I managed to find a work-around. If anyone is interested, this is what I did:
Using Eclipse, I started a new project.
I then created a directory called ‘lib’ under the root of the project and copied all the Stanford .jar files into this directory.
After this, I edited the properties of the project in Eclipse, went to ‘Java Build Path’, clicked the libraries tab.
I then choose to import the Java system libraries.
I also clicked ‘Add External Jars’ and selected all the Stanford jars from the lib directory.
I then created intetermediary Java classes to call the Stanford classes (rather than trying to call them directly from R).
Example:
import java.lang.Object;
import java.util.Properties;
import java.io.*;
import java.util.*;
import edu.stanford.nlp.io.*;
import edu.stanford.nlp.ling.*;
import edu.stanford.nlp.pipeline.*;
import edu.stanford.nlp.trees.*;
import edu.stanford.nlp.util.*;
public class NLP {
public static void main(String[] args) {
Properties props = new Properties();
props.put("annotators", "tokenize");
StanfordCoreNLP coreNLP = new StanfordCoreNLP(props);
}
}
This doesn’t return anything, but shows how a Stanford object can be created.
Build the project using Eclipse.
From within R, then set the working directory to the Java project's /bin directory (this isn’t strictly necessary, as you can add the classpath directory instead, but it simplifies things).
Then the object can be created in R with:
.jinit(classpath = ".") // This initilizes the JVM
obj = .jnew("NLP")
After this any methods you’ve created within the intermediary java classes can be called with:
Name_of_var_to_store_return_value = . jcall(class name, signature type, method, paramters)
I still didn’t figure out why I can’t call the Stanford classes directly from R, but this method works. I suspect that #ChristopherManning is right and my problem is down to calling the external jar from R. By building it from scratch, the Stanford jars are linked during the build, so I guess that’s what fixed it.

Categories