Class EmailAddressCriteria not found (SimpleJavaMail) - java

I try to use the SimpleJavaMail library, but I think I missed something when importing the JAR of the API and it's dependencies. I use Java 8 (openjdk), and here is a list of the external JARs I added in my Eclipse Oxygen project configuration :
slf4j-api-1.7.13.jar (the 1.7.13 version seems to be the version of SLF4J used in SimpleJavaMAil since version 2.5.1 according to its GitHub)
slf4j-simple-1.7.13.jar
javax.mail.jar version 1.6.1
simple-java-mail-5.0.3.jar
Here is a code sample:
import org.simplejavamail.email.Email;
import org.simplejavamail.email.EmailBuilder;
import org.simplejavamail.mailer.Mailer;
import org.simplejavamail.mailer.MailerBuilder;
import org.simplejavamail.mailer.config.TransportStrategy;
public class Main {
public static void main(String[] args) throws Exception {
Email notif = EmailBuilder.startingBlank()
.to("someone#somewhere.fr")
.withSubject("Bla")
.withPlainText("Lorem ipsum\nLorem ipsum")
.buildEmail();
Mailer mailer = MailerBuilder
.withSMTPServer("smtp.gmail.com", 587, "foo#gmail.com", "bar")
.withTransportStrategy(TransportStrategy.SMTP_TLS)
.withSessionTimeout(10 * 1000)
.clearEmailAddressCriteria() // turns off email validation
.withDebugLogging(true)
.buildMailer();
mailer.sendMail(notif);
}
}
The exception I have running that code trought Eclipse on my Linux is:
Exception in thread "main" java.lang.NoClassDefFoundError: org/hazlewood/connor/bottema/emailaddress/EmailAddressCriteria
at org.simplejavamail.mailer.MailerGenericBuilder.<init>(MailerGenericBuilder.java:152)
at org.simplejavamail.mailer.MailerBuilder$MailerRegularBuilder.<init>(MailerBuilder.java:136)
at org.simplejavamail.mailer.MailerBuilder.withSMTPServer(MailerBuilder.java:49)
at Main.main(Main.java:18)
Caused by: java.lang.ClassNotFoundException: org.hazlewood.connor.bottema.emailaddress.EmailAddressCriteria
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 4 more
Any idea on how to fix this?

Looking at Maven Central's pom.xml for simple-java-mail-5.0.3 you are missing the following dependency
<dependency>
<groupId>com.github.bbottema</groupId>
<artifactId>emailaddress-rfc2822</artifactId>
<version>1.0.1</version>
<scope>compile</scope>
</dependency>
I think you should use a build tool like Maven or Gradle to set up your project instead of adding the JAR files manually to avoid problems with missing dependencies.

Related

Why maven recognize dependencies and allows me to import but I cannot instantiate objects?

I just installed maven, and tried to use a dependency called Jsoup:
mvn archetype:generate "-DgroupId=com.example" "-DartifactId=Foo" "-DarchetypeArtifactId=maven-archetype-quickstart" "-DarchetypeVersion=1.4" "-DinteractiveMode=false"
cd Foo > mvn package
added these lines to the pom.xml:
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.15.3</version>
</dependency>
and then tried
mvn package
java -cp target\Foo-1.0-SNAPSHOT.jar com.example.App
the build was successful, but when the program runs it gives me this error:
C:\Users\brand\Desktop\java_misc\Foo>java -cp target\Foo-1.0-SNAPSHOT.jar com.example.App
Exception in thread "main" java.lang.NoClassDefFoundError: org/jsoup/Jsoup
at com.example.App.main(App.java:16)
Caused by: java.lang.ClassNotFoundException: org.jsoup.Jsoup
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 1 more
I have done the same in eclipse with the exact same code and it works, which means that the XML dependency works, but I don't understand why it does not work when using just the command prompt. any help is appreciated thanks.
java code used to test was:
package com.example;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
public class App
{
public static void main( String[] args )
{
try {
String url = "https://www.stackoverflow.com";
Document document = Jsoup.connect(url).get();
System.out.println(document);
}catch(IOException e){
System.out.println(e);
}
}
}

How do I configure my Eclipse project to use the log4j 1.2 to 2.16 bridge

I am trying to use the log4j 1.2 to 2.16 bridge - log4j-1.2-api-2.16.0.jar
I thought that by using the bridge jar I would not have to change my code.
I am using these three jars in my classpath:
log4j-1.2-api-2.16.0.jar
log4j-core-2.16.0.jar
log4j-api-2.16.0.jar
In the Eclipse project properties Java Build Path, Libraries tab, I see:
Modulepath
>log4j-1.2-api-2.16.0.jar - Log4jBridgeExample/lib
>log4j-api-2.16.0.jar - Log4jBridgeExample/lib
>log4j-core-2.16.0.jar - Log4jBridgeExample/lib
>JRE System Library [JavaSE-9]
Classpath
Here is the the one class definition.
package test;
import org.apache.log4j.Logger;
public class MyClass {
//Here we use old log4j syntax like exists in thousands
//of other classes in our other projects.
private static Logger logger = Logger.getLogger(MyClass.class);
public static void main(String[] args) {
logger.info("Howdy");
}
}
When I run it, I get the following runtime error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/logging/log4j/Logger
at Log4jBridgeExample/test.MyClass.<clinit>(MyClass.java:6)
Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.Logger
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 1 more

Could not load FFI provider when using module-info.java

my Linux Java application uses bluetooth devices. I use this library in order to communicate with bluez stack : https://github.com/hypfvieh/bluez-dbus.
It worked very well until I added module-info.java to my client code. Suddenly I got this error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: could not load FFI provider jnr.ffi.provider.jffi.Provider
at jnr.ffi#2.1.15/jnr.ffi.provider.InvalidRuntime.newLoadError(InvalidRuntime.java:101)
at jnr.ffi#2.1.15/jnr.ffi.provider.InvalidRuntime.findType(InvalidRuntime.java:42)
at jnr.ffi#2.1.15/jnr.ffi.Struct$NumberField.(Struct.java:872)
at jnr.ffi#2.1.15/jnr.ffi.Struct$Unsigned16.(Struct.java:1240)
at jnr.unixsocket#0.33/jnr.unixsocket.SockAddrUnix$DefaultSockAddrUnix.(SockAddrUnix.java:209)
at jnr.unixsocket#0.33/jnr.unixsocket.SockAddrUnix.create(SockAddrUnix.java:174)
at jnr.unixsocket#0.33/jnr.unixsocket.UnixSocketAddress.(UnixSocketAddress.java:53)
at dbus.java#3.2.3/org.freedesktop.dbus.connections.transports.UnixSocketTransport.(UnixSocketTransport.java:32)
at dbus.java#3.2.3/org.freedesktop.dbus.connections.transports.TransportFactory.createTransport(TransportFactory.java:37)
at dbus.java#3.2.3/org.freedesktop.dbus.connections.AbstractConnection.(AbstractConnection.java:161)
at dbus.java#3.2.3/org.freedesktop.dbus.connections.impl.DBusConnection.(DBusConnection.java:334)
at dbus.java#3.2.3/org.freedesktop.dbus.connections.impl.DBusConnection.getConnection(DBusConnection.java:149)
at dbus.java#3.2.3/org.freedesktop.dbus.connections.impl.DBusConnection.getConnection(DBusConnection.java:169)
at dbus.java#3.2.3/org.freedesktop.dbus.connections.impl.DBusConnection.getConnection(DBusConnection.java:219)
at dbus.java#3.2.3/org.freedesktop.dbus.connections.impl.DBusConnection.getConnection(DBusConnection.java:184)
at bluez.dbus#0.1.3/com.github.hypfvieh.bluetooth.DeviceManager.createInstance(DeviceManager.java:74)
at ...
Caused by: java.lang.UnsatisfiedLinkError: could not get native definition for type POINTER, original error message follows: java.lang.UnsatisfiedLinkError: could not locate stub library in jar file. Tried [jni/x86_64-Linux/libjffi-1.2.so, /jni/x86_64-Linux/libjffi-1.2.so]
at jffi#1.2.23/com.kenai.jffi.internal.StubLoader.getStubLibraryStream(StubLoader.java:450)
at jffi#1.2.23/com.kenai.jffi.internal.StubLoader.loadFromJar(StubLoader.java:375)
at jffi#1.2.23/com.kenai.jffi.internal.StubLoader.load(StubLoader.java:278)
at jffi#1.2.23/com.kenai.jffi.internal.StubLoader.(StubLoader.java:487)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:427)
at jffi#1.2.23/com.kenai.jffi.Init.load(Init.java:68)
at jffi#1.2.23/com.kenai.jffi.Foreign$InstanceHolder.getInstanceHolder(Foreign.java:49)
at jffi#1.2.23/com.kenai.jffi.Foreign$InstanceHolder.(Foreign.java:45)
at jffi#1.2.23/com.kenai.jffi.Foreign.getInstance(Foreign.java:103)
at jffi#1.2.23/com.kenai.jffi.Type$Builtin.lookupTypeInfo(Type.java:242)
at jffi#1.2.23/com.kenai.jffi.Type$Builtin.getTypeInfo(Type.java:237)
at jffi#1.2.23/com.kenai.jffi.Type.resolveSize(Type.java:155)
at jffi#1.2.23/com.kenai.jffi.Type.size(Type.java:138)
at jnr.ffi#2.1.15/jnr.ffi.provider.jffi.NativeRuntime$TypeDelegate.size(NativeRuntime.java:178)
at jnr.ffi#2.1.15/jnr.ffi.provider.AbstractRuntime.(AbstractRuntime.java:48)
at jnr.ffi#2.1.15/jnr.ffi.provider.jffi.NativeRuntime.(NativeRuntime.java:57)
at jnr.ffi#2.1.15/jnr.ffi.provider.jffi.NativeRuntime.(NativeRuntime.java:41)
at jnr.ffi#2.1.15/jnr.ffi.provider.jffi.NativeRuntime$SingletonHolder.(NativeRuntime.java:53)
at jnr.ffi#2.1.15/jnr.ffi.provider.jffi.NativeRuntime.getInstance(NativeRuntime.java:49)
at jnr.ffi#2.1.15/jnr.ffi.provider.jffi.Provider.(Provider.java:29)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:124)
at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:346)
at java.base/java.lang.Class.newInstance(Class.java:604)
at jnr.ffi#2.1.15/jnr.ffi.provider.FFIProvider$SystemProviderSingletonHolder.getInstance(FFIProvider.java:68)
at jnr.ffi#2.1.15/jnr.ffi.provider.FFIProvider$SystemProviderSingletonHolder.(FFIProvider.java:57)
at jnr.ffi#2.1.15/jnr.ffi.provider.FFIProvider.getSystemProvider(FFIProvider.java:35)
at jnr.ffi#2.1.15/jnr.ffi.Runtime$SingletonHolder.(Runtime.java:82)
at jnr.ffi#2.1.15/jnr.ffi.Runtime.getSystemRuntime(Runtime.java:67)
at jnr.unixsocket#0.33/jnr.unixsocket.SockAddrUnix.(SockAddrUnix.java:46)
at jnr.unixsocket#0.33/jnr.unixsocket.SockAddrUnix$DefaultSockAddrUnix.(SockAddrUnix.java:208)
at jnr.unixsocket#0.33/jnr.unixsocket.SockAddrUnix.create(SockAddrUnix.java:174)
at jnr.unixsocket#0.33/jnr.unixsocket.UnixSocketAddress.(UnixSocketAddress.java:53)
at dbus.java#3.2.3/org.freedesktop.dbus.connections.transports.UnixSocketTransport.(UnixSocketTransport.java:32)
at ...
I tried to require everything related to this error in the module-info.java without success:
module org.example {
requires dbus.java;
requires dbus.java.nativefd;
requires bluecove.linux.custom;
requires bluez.dbus;
requires jnr.ffi;
requires jnr.x86asm;
requires jnr.posix;
requires jnr.enxio;
requires jnr.unixsocket;
requires jnr.constants;
requires jnr.a64asm;
}
Thank you in advance.
TL;DR
This worked for me…
java --patch-module jffi={{your.own.location}}/com/github/jnr/jffi/1.3.0/jffi-1.3.0-native.jar …
The long version
I downloaded this example project. It's not a JPMS project. But I added module-info.java files to each of the four sub-projects.
I updated the project's com.github.jnr:jnr-ffi dependency from 2.0.9 to 2.1.5 to match the version I see in your stack trace. And I added the following dependencies…
…
<dependency>
<groupId>com.github.hypfvieh</groupId>
<artifactId>dbus-java</artifactId>
<version>3.2.3</version>
</dependency>
<dependency>
<groupId>com.github.hypfvieh</groupId> <artifactId>bluez-dbus</artifactId>
<version>0.1.3</version>
</dependency>
<dependency>
<groupId>com.rm5248</groupId>
<artifactId>dbus-java-nativefd</artifactId>
<version>1.0</version>
</dependency>
…
Those were added so that I could then define each one of my four module-info.java descriptors to be pretty much exactly like yours…
module get.pid{
exports getpid;
requires dbus.java;
requires dbus.java.nativefd;
requires bluez.dbus;
requires jnr.ffi;
requires jffi;
requires jnr.x86asm;
requires jnr.posix;
requires jnr.enxio;
requires jnr.unixsocket;
requires jnr.constants;
requires jnr.a64asm;
}
Before I did the --patch-module, I ran one of the example projects and got the exact same error you got.
But with the following command, all the example applications ran perfectly fine as modules…
java --patch-module jffi={{your.own.location}}/com/github/jnr/jffi/1.3.0/jffi-1.3.0-native.jar --add-modules org.objectweb.asm --add-exports org.objectweb.asm/org.objectweb.asm=jnr.ffi --add-exports org.objectweb.asm/org.objectweb.asm.signature=jnr.ffi --module-path {{path.to.all.the.jars}} -m get.pid/getpid.Getpid
The add-modules and add-exports are crucial too. So don't leave those out.

Geb NoClassDefFoundError: geb/error/UnableToLoadException

I've ben having trouble setting up and testing Geb.
I have a simple Groovy script:
import geb.Browser;
println("Test 11")
Browser.drive {
go "http://www.google.com"
}
and I always get the following error:
Caught: java.lang.NoClassDefFoundError: geb/error/UnableToLoadException
java.lang.NoClassDefFoundError: geb/error/UnableToLoadException
at geb.Browser.<init>(Browser.groovy:61)
at geb.Browser.drive(Browser.groovy:1028)
at geb.Browser$drive.call(Unknown Source)
at Main.run(Main.groovy:8)
I wrote a Class.forName("geb.error.UnableToLoadException") which changed the error to
java.lang.NoClassDefFoundError: geb/error/GebException
at Main.run(Main.groovy:10)
Caused by: java.lang.ClassNotFoundException: geb.error.GebException
... 1 more
It seems to me that Geb is searching for a class GebException, which is not inside the geb-core-2.1.jar I've downloaded! Next to this jar, I also added the selenium-server-standalone-3.9.1.jar. Am I doing something wrong? Did I install some wrong geb-core library? I am using IntelliJ IDEA as the IDE. Thank you for your help
Best regards
If this is a maven project where yourfile is in, I suggest to check your dependency list in pom.xml first.
As I tested in my env, it is executing perfectly

Error when using StanfordCoreNLP

I'm trying to use Stanford CoreNLP as a library in my java program. I use IntelliJ as the IDE.
I was trying to test the library, so I wrote this code:
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import java.util.Properties;
/**
* Created by Benjamin on 15/5/4.
*/
public class SentimentAnaTest {
public static void main(String[] args) {
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
}
}
and it shows the error like this:
Adding annotator tokenize
TokenizerAnnotator: No tokenizer type provided. Defaulting to PTBTokenizer.
Adding annotator ssplit
Adding annotator pos
Exception in thread "main" java.lang.RuntimeException: edu.stanford.nlp.io.RuntimeIOException: Unrecoverable error while loading a tagger model
at edu.stanford.nlp.pipeline.AnnotatorFactories$4.create(AnnotatorFactories.java:292)
at edu.stanford.nlp.pipeline.AnnotatorPool.get(AnnotatorPool.java:85)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(StanfordCoreNLP.java:289)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:126)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:122)
at SentimentAnaTest.main(SentimentAnaTest.java:12)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: edu.stanford.nlp.io.RuntimeIOException: Unrecoverable error while loading a tagger model
at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:770)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:298)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:263)
at edu.stanford.nlp.pipeline.POSTaggerAnnotator.loadModel(POSTaggerAnnotator.java:97)
at edu.stanford.nlp.pipeline.POSTaggerAnnotator.<init>(POSTaggerAnnotator.java:77)
at edu.stanford.nlp.pipeline.AnnotatorImplementations.posTagger(AnnotatorImplementations.java:59)
at edu.stanford.nlp.pipeline.AnnotatorFactories$4.create(AnnotatorFactories.java:290)
... 10 more
Caused by: java.io.IOException: Unable to resolve "edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger" as either class path, filename or URL
at edu.stanford.nlp.io.IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(IOUtils.java:481)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:765)
... 16 more
I read a solution here but couldn't figure out what the problem was, because I added the library from the Maven Central Repository which already included the "stanford-corenlp-3.5.2-models.jar".
From the error message it seemed like the program was trying to load a file from edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger so I download the tagger file from here and put it into /edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger. However it still didn't work.
Can someone tell me whats this error is about and help me to solve it? Thank you!
I had the same problem. Fixed using:
<dependencies>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.5.2</version>
<classifier>models</classifier>
</dependency>
</dependencies>
or for SBT:
"edu.stanford.nlp" % "stanford-corenlp" % "3.5.2",
"edu.stanford.nlp" % "stanford-corenlp" % "3.5.2" classifier "models",
The tagger file has to be placed into your project root.
project
-- src --> SentimentAnaTest
-- english-left3words/english-left3words-distsim.tagger
Tested in Eclipse project.
I faced the same error and took me a long time to figure it out. Essentially there are two main jar files we will be needing to solve the error. One is the stable version 3.6.0 and the current version 3.7.0
So, download both jar files from the following link and link. Now extract both the jar files. The extracted folder of the 3.7.0 jar file does not have the models folder as of now. You can find this folder in the 3.6.0 jar file extracted folder.
Copy that folder from 3.6 version to 3.7 version.
Now from the root folder run the following command:
java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000
It should run perfectly. In order to use the server, follow this py-corenlp
The problem could be that you are starting server via the jar file that you must have created from the compiled classed, so make sure you re-create the jar after putting in the required file to the folder location as can be seen on the error console.
Once you re-create the jar, start the server.

Categories