Shann
Shann

Reputation: 690

Error while executing jar file

I'm trying to run a jar file which sends a mail, using this command:

java -jar sendmail.jar

When I run the code from NetBeans everything works fine, but when I export to a jar file and run the jar file I get the following error:

Error Sending mailjavax.mail.MessagingException: Could not connect to SMTP host:
 smtp.<xxx>.com, port: 25;
  nested exception is:
        java.net.SocketException: Permission denied: connect

After I got the error I executed the code from NetBeans, and the mail was sent. Thus I don't have any issue with SMTP or connection.

I think that the jar file cannot locate the mail.jar. Please advise.

Upvotes: 0

Views: 508

Answers (3)

Md. Abdul Bari
Md. Abdul Bari

Reputation: 116

Be sure to put your mail.jar file into lib folder and also ensure that your lib folder and sendmail.jar files are present in same directory.

Upvotes: 0

Simiil
Simiil

Reputation: 2311

Does your machine by any chance use ipv6? if it does, you can try to start your jar with the -Djava.net.preferIPV4Stack=true argument.

Upvotes: 1

JWqvist
JWqvist

Reputation: 717

Be sure that the mail.jar is probably imported under the libs and your not just referenced it.

Upvotes: 0

Related Questions