1

I have a Class written which imports some classes from JavaMail. When the application runs, it downloads the file automatically and saves it in a directory called depend. But I can't get it to import the classes from the Javamail jar I downloaded. For Example, I have:

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

At the top of the file, these classes are located in (Path to program/depend/javax.mail.jar)

teunw
  • 11
  • 1
  • 2

2 Answers2

3

You must ensure that the javamail.jar file is on the classpath.

You can do this using -classpath arg or by setting the CLASSPATH env var.

  • Here is documentation from Oracle describing java -classpath command line arg
  • Here is documentation describing how to set CLASSPATH environment var.
cmd
  • 11,622
  • 7
  • 51
  • 61
  • How do I do that?, getClass().getResource(filePath) didn't work. – teunw Dec 01 '13 at 22:28
  • @user3055476 Maybe this question helps: http://stackoverflow.com/questions/252893/how-do-you-change-the-classpath-within-java – PoByBolek Dec 01 '13 at 22:34
  • 1
    Your FilePath is about setting the path of some file *your prog* is working with. It won't help Eclipse or JVM. Classpath that you need is about where the classes you want the *JVM* to work with lies. You won't use it in your code, unless you are making plugins. – Gangnus Dec 01 '13 at 22:35
0

It sounds like you want to load classes over the network.

This can only be done using a ClassLoader. It cannot be done any other way.

It can be done using RMI - but that uses a ClassLoader internally.

Robin Green
  • 32,079
  • 16
  • 104
  • 187