Error running AWS SES sample - amazon-web-services

I'm trying to run the sample program here http://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-smtp-java.html
here's the command output...
$ java AmazonSESSample -cp "javamail-1.4.3/mail.jar"
java.lang.NoClassDefFoundError: javax/mail/Address
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
atsun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: javax.mail.Address
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main"
I tried to Google for answers by using this search string...
search string = java mail.jar "Error: A JNI error has occurred, please check your installation and try again"
i didn't see anything useful in the search results :-(
Any ideas?

I think the JAR file (javamail-1.4.3/mail.jar) you indicated is not being found..
java AmazonSESSample -cp "javamail-1.4.3/mail.jar"
Try providing the full path like below (below is an example only)
java AmazonSESSample -cp "/usr/lib/javamail-1.4.3/mail.jar"
UPDATE: On Windows try the below
java AmazonSESSample -classpath "C:\Users\MichaelDocuments\GitHub\guesstimate\scratch\javamail-1.4.3\mail.jar"

Ok so the answer is that the classpath option was AFTER the main class. So the -cp and jar value are being passed as 'args' to the 'main' method - doh!!!!!!!!!!!!!!
By simply moving this option as shown below, the jar is loaded and the class is found as expected..
A useful outcome of this frustrating puzzle is that i discovered '-verbose:class' which will be useful for other problems in the future i'm sure :)
$ java -verbose:class -cp '.;mail.jar' AmazonSESSample | grep Session
[Loaded javax.mail.Session from file:/C:/Users/Michael/Documents/GitHub/guesstimate/scratch/mail.jar]
[Loaded javax.mail.Session$1 from file:/C:/Users/Michael/Documents/GitHub/guesstimate/scratch/mail.jar]
[Loaded javax.mail.Session$3 from file:/C:/Users/Michael/Documents/GitHub/guesstimate/scratch/mail.jar]
[Loaded javax.mail.Session$5 from file:/C:/Users/Michael/Documents/GitHub/guesstimate/scratch/mail.jar]
[Loaded javax.mail.Session$4 from file:/C:/Users/Michael/Documents/GitHub/guesstimate/scratch/mail.jar]
[Loaded javax.mail.Session$2 from file:/C:/Users/Michael/Documents/GitHub/guesstimate/scratch/mail.jar]
Michael#mikeToshSpare /cygdrive/c/Users/Michael/Documents/GitHub/guesstimate/scratch
$ java -verbose:class AmazonSESSample -cp '.;mail.jar' | grep Session
Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/Session
at AmazonSESSample.main(AmazonSESSample.java:56)
Caused by: java.lang.ClassNotFoundException: javax.mail.Session
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more

Related

Error: it/crs4/pydoop/mapreduce/pipes/Submitter : Unsupported major.minor version 52.0 CentOS6 , Pydoop, Hue , Cloudera

When I try to run the script, I get this error. This is a Python script. Does anyone have this problem?
[cloudera-scm#ivana-namenode2 /opt/MapReduce/wordcount]$ pydoop script wc.py /user/cloudera-scm/MapReduce/wordcount/data/text /user/cloudera-scm/MapReduce/wordcount/output
Exception in thread "main" java.lang.UnsupportedClassVersionError: it/crs4/pydoop/mapreduce/pipes/Submitter : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
ERROR - RunCmdError: command exited with 1 status
When you turn to this existing question you find the explanation for the error message: you have some java class that was compiled for Java8.
But the JVM asked to execute that class is older than Java8.
In other words: you have an inconsistent setup. Some part of your environment wants to use something build for Java8, but that part that executes things is running an older version of Java.
So, the answer here is that you have to understand better what your setup is composed of, to either use an "older" version of the underlying library/tool, or to make sure that a Java8 JVM is available to run classes.

Jetty 9 stop port and key in command line arguments

In Jetty 8 I was passing values like -Djetty.port=8888 -DSTOP.PORT=8887 -DSTOP.KEY=STOP but in Jetty 9 these don't seem to work.
I am able to set the port with --module=http jetty.port=8888 but am not sure how to set the other values?
Also, I used to use the command java -DSTOP.PORT=8887 -DSTOP.KEY=STOP -jar start.jar --stop but am not sure how to run the stop command now?
The docs at http://www.eclipse.org/jetty/documentation/current/start-jar.html#d0e8360 suggest that stopping hasn't changed, but when I try that I get
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at org.eclipse.jetty.start.Main.stop(Main.java:761)
at org.eclipse.jetty.start.Main.stop(Main.java:740)
at org.eclipse.jetty.start.Main.start(Main.java:648)
at org.eclipse.jetty.start.Main.main(Main.java:103)
Usage: java -jar start.jar [options] [properties] [configs]
java -jar start.jar --help # for more information
TIA
I have experienced the same problem, but found it has always been an overlooked mistake on my part. With that being said, I think you are actually on the right track.
This should work
With
jetty-distribution-9.2.7.v20150116
the following sequence does work:
# setting up jetty config
java -jar mypath/start.jar --add-to-startd=http,deploy
# check to see if the ports are available
netstat -tapn | grep "808[07]"
# starting server
java -DSTOP.PORT=8087 -DSTOP.KEY=STOP -jar mypath/start.jar
# check to see if the ports are now monitored
netstat -tapn | grep "808[07]"
# starting server
java -DSTOP.PORT=8087 -DSTOP.KEY=STOP -jar mypath/start.jar --stop
# check to see if the ports are now free
netstat -tapn | grep "808[07]"
Preferred syntax
The above -D syntax works, but the following syntax is better supported:
java -jar mypath/start.jar STOP.PORT=8087 STOP.KEY=STOP
java -jar mypath/start.jar STOP.PORT=8087 STOP.KEY=STOP --stop
java -jar mypath/start.jar STOP.PORT=8087 STOP.KEY=STOP --list-config
java -jar mypath/start.jar STOP.PORT=8087 STOP.KEY=STOP --dry-run
You can easily confirm that this syntax does work by trying it.
Additional steps
Those last two commands (--list-config and --dry-run) can be very handy for checking a variety of problems.
The --help command is also very useful to sanity checking odd problems like this. It does reveal nuances like the above preferred syntax that you found difficult to find:
java -jar mypath/start.jar --help
If you've already tried these steps, try upgrading to a newer version of Jetty in case the problem you experienced was an actually bug that was subsequently fixed.
If it still doesn't work, I'll try to help you and update this "answer" appropriately.

jetty throws exception after `java -jar start.jar`

I get the following error when I run java -jar start.jar. sudo service jetty start works just fine. What seems to be the problem? There are no webapps deployed, its a new install. I have changed the /etc/default/jetty file to enable the service to start.
wissen12#wissen12:/usr/share/jetty$ java -jar start.jar
7 [main] INFO org.mortbay.util.FileResource - Checking Resource aliases
396 [main] WARN org.mortbay.xml.XmlConfiguration - EXCEPTION
java.lang.NoSuchMethodException: class org.mortbay.jetty.Server.setThreadPool(class org.mortbay.thread.QueuedThreadPool)
at org.mortbay.xml.XmlConfiguration.set(XmlConfiguration.java:417)
at org.mortbay.xml.XmlConfiguration.configure(XmlConfiguration.java:231)
at org.mortbay.xml.XmlConfiguration.newInstance(XmlConfiguration.java:198)
at org.mortbay.xml.XmlConfiguration.main(XmlConfiguration.java:880)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.mortbay.start.Main.invokeMain(Main.java:194)
at org.mortbay.start.Main.start(Main.java:534)
at org.mortbay.start.Main.start(Main.java:441)
at org.mortbay.start.Main.main(Main.java:119)
Thanks.
I had the exact same problem. Upgrading from Jetty 7.1.x to 7.4.x solved it. Looking at the source code, it looks like Jetty's XML bean handling added a lot more fallback cases for non-exact type matching in setters.
There are 2 possibilities that stand out as the most likely cause:
The server configuration file (jetty.xml) that you're using does not match the version of Jetty that you're using.
The versions do match, but the setThreadPool method is throwing an exception which is being lost
The 2nd seems more likely, so you should follow the instructions on this page
http://docs.codehaus.org/display/JETTY/Debugging
to turn on "ignored exception" logging.
I expect you'll find that an exception is being throw during the call to "Server.setThreadPool" and that is being "ignored" and treated as a "NoSuchMethod" exception.

How to run clojure on Mac OS X?

I'm following the examples from the book 'Programming Clojure', and I'm at page
17 to run (require 'example.introduction).
I have set clojure at ~/bin/clojure as follows
java -server \
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8888 -cp ... clojure.lang.Repl
The -cp contains . (current directory). When I try it with clojure, I get the following error message.
Exception in thread "main" java.lang.ExceptionInInitializerError
at clojure.lang.Repl.(Repl.java:23)
Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodError: clojure.lang.MultiFn.(Ljava/lang/String;Lclojure/lang/IFn;Ljava/lang/Object;Lclojure/lang/IRef;)V (utils.clj:0)
at clojure.lang.RT.(RT.java:290)
... 1 more
Caused by: java.lang.NoSuchMethodError: clojure.lang.MultiFn.(Ljava/lang/String;Lclojure/lang/IFn;Ljava/lang/Object;Lclojure/lang/IRef;)V (utils.clj:0)
at clojure.lang.Compiler.eval(Compiler.java:4153)
at clojure.lang.Compiler.load(Compiler.java:4470)
at clojure.lang.RT.loadResourceScript(RT.java:327)
at clojure.lang.RT.loadResourceScript(RT.java:316)
at clojure.lang.RT.load(RT.java:406)
at clojure.lang.RT.load(RT.java:376)
at clojure.core$load__4557$fn__4559.invoke(core.clj:3427)
at clojure.core$load__4557.doInvoke(core.clj:3426)
at clojure.lang.RestFn.invoke(RestFn.java:413)
at clojure.core$load_one__4520.invoke(core.clj:3271)
...
at clojure.lang.RT.loadResourceScript(RT.java:327)
at clojure.lang.RT.loadResourceScript(RT.java:312)
at clojure.lang.RT.maybeLoadResourceScript(RT.java:308)
at clojure.lang.RT.doInit(RT.java:430)
at clojure.lang.RT.(RT.java:286)
... 1 more
Caused by: java.lang.NoSuchMethodError: clojure.lang.MultiFn.(Ljava/lang/String;Lclojure/lang/IFn;Ljava/lang/Object;Lclojure/lang/IRef;)V
at clojure.contrib.duck_streams__init.load(Unknown Source)
at clojure.contrib.duck_streams__init.(Unknown Source)
...
at clojure.lang.Compiler.eval(Compiler.java:4142)
... 28 more
I tried to run clojure as follows.
alias clojure='java -jar $JARDIR/clojure.jar '
But it doesn't have the CLASSPATH that I setup in .bashrc correctly, when I run the command as follows.
(println (seq (.getURLs (java.lang.ClassLoader/getSystemClassLoader))))
What might be wrong?
The easiest way is to use Stuart Halloway's code that accompanies the book:
Clone Stu's code from GitHub: $ git clone http://github.com/stuarthalloway/programming-clojure.git
cd into the programming-clojure directory that was created: $ cd programming-clojure
Run the repl.sh script in the bin/ directory: $ ./bin/repl.sh (make sure you run it from the repo root, not the bin/ directory, otherwise it won't work).
The script will set up all the necessary paths, including the paths to the examples in the book.
(You can do it manually, of course, but at any rate, you have to download or clone the programming-clojure source code anyway for the examples to work.)

How to install clojure-contrib on Windows?

I can't seem to find a way to launch the Clojure REPL with the contrib library included. If I understood the documentation correctly then this command should do it:
C:\clojure-1.1.0>"%ProgramFiles%\Java\jre6\bin\java.exe" -cp clojure.jar:clojure
-contrib.jar clojure.main
Exception in thread "main" java.lang.NoClassDefFoundError: clojure/main
Caused by: java.lang.ClassNotFoundException: clojure.main
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: clojure.main. Program will exit.
But as you can see, it fails. I did copy the clojure-contrib.jar to the C:\clojure-1.1.0 folder.
Can someone help me get it right?
Update
Thanks to MichaƂ's post I noticed that my error was using a colon where I had to use a semi-colon. This works:
C:\clojure-1.1.0>"%ProgramFiles%\Java\jre6\bin\java.exe" -cp clojure.jar;clojure-contrib.jar clojure.main
Clojure 1.1.0
user=>
(Answer updated to make the actual solution explicit, whereas it was somewhat hidden in the original...)
The classpath string on Windows uses ; as the separator. E.g.
java.exe -cp "C:\clojure-1.1.0\clojure.jar;C:\clojure-1.1.0\clojure-contrib.jar" clojure.main
Alternatively, you can use a wildcard to include all jars in the given directory in the classpath (that's a JDK 1.6 addition, wouldn't work with 1.5):
java.exe -cp "C:\clojure-1.1.0\*" clojure.main
(I think using double quotes here is ok in Windows, can't check though...)