I’m trying to make Microsoft translator API in my java (windows form) application. I registered in windows azure market place and I registered my Microsoft Translate application so I have these ClientId and Client Secret keys but still it doesn’t work. I can’t find what I am doing wrong.
Here is my code:
import com.memetix.mst.language.Language;
import com.memetix.mst.translate.Translate
public class Main {
public static void main(String[] args) {
try{
Translate.setClientId(/* my Client Id */);
Translate.setClientSecret(/* my Client Secret */);
String translatedText = Translate.execute("Bonjour le monde", Language.FRENCH, Language.ENGLISH);
System.out.println(translatedText);
}
catch(Exception e) {
System.err.println("Exception: " + e.getMessage());
}
}
}
And this is the error I’m getting:
Exception in thread "main" java.lang.NoClassDefFoundError: com/memetix/mst/translate/Translate
at Main.main(Main.java:9)
Caused by: java.lang.ClassNotFoundException: com.memetix.mst.translate.Translate
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 1 more
You should have that Microsoft’s Translation Library on the Classpath for Linux/Solaris.
If this is a standalone program, you could try out the following command:
java -classpath "%classpath%;.;<path_to_the_translation_library.jar>" MainThis
<path_to_the_translation_library.jar>should be the same Library or JAR you used to compile thisMainclass.