0

For an specific emailing functionality, I have a HelloWorld.java class, calling objects inside javax.mail.jar and javax.activation.jar, looking like this:

//SENDEMAIL JAVA CLASS
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeBodyPart;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.BodyPart;

public class HelloWorld{
    public HelloWorld(){
        setVersion(0);
    }
    public static void main(String[] args){
        System.out.println("Hello World!");
    }
    public void setVersion(int aVersion){
        version = aVersion;
    }
    public int getVersion(){
        return version;
    }
    private int version;
}

While compiling and exporting a jar file in Eclipse is done fine, I am now compiling it through command line, using these command:

>javac -target 1.7 -source 1.7 -bootclasspath "C:\Program Files\MATLAB\R2018a\sys\java\jre\win64\jre\lib\rt.jar" -cp "javax.activation.jar;javax.mail.jar" HelloWorld.java
>jar cfe "HelloWorld.jar" HelloWorld "HelloWorld.class"

Without the import and the -cp sentences, these command line compilation worked fine, for several other classes, but when I try to import these new javax.mail.jar and javax.activation.jar, I cannot set the proper -cp command and eventually the relative location of these packages for making the compilation work retaining all the rest structure.

How should I fix the command?

Brethlosze
  • 1,533
  • 1
  • 22
  • 41
  • 1
    As your code is not using any of these classes why are you even importing them? – Scary Wombat Apr 23 '19 at 01:39
  • This is only a template, the actual code use each of them. The unmodified code is [here](https://www.tutorialspoint.com/javamail_api/javamail_api_send_inlineimage_in_email.htm) – Brethlosze Apr 23 '19 at 01:40
  • 1
    This link will help you : https://stackoverflow.com/questions/9395207/how-to-include-jar-files-with-java-file-and-compile-in-command-prompt – Anish B. Apr 23 '19 at 01:42
  • 1
    `-cp` should be the name of the `jarFile` – Scary Wombat Apr 23 '19 at 01:44
  • Thanks my friends, i though it was something worst. I solved it. The right syntax was `-cp "jar1.jar;jar2.jar"`. I found so many different choices... – Brethlosze Apr 23 '19 at 01:58

0 Answers0