trying to compile and run java through the terminal


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers trying to compile and run java through the terminal
# 1  
Old 05-06-2009
trying to compile and run java through the terminal

Hey everybody,

Ok here is my problem. I have this code that that compiles, but when i go to run it it gives me errors.

I stored my simple java class here:
/user/workspace/getMailFromSafeDoc/src

I store my mail.jar file here:
/user/workspace/getMailFromSafeDoc/lib/javaMail/javaMail.jar

In my terminal i go to that folder and i compile it by:
javac -classpath ../lib/javaMail/javaMail.jar javaMail.java

..... this works and products a class file with no errors.

when i go to complile it by:
java javaMail

i get:
Exception in thread "main" java.lang.NoClassDefFoundError:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/NoSuchProviderException
Caused by: java.lang.ClassNotFoundException: javax.mail.NoSuchProviderException
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:336)


When i take out all the try and catch, it works fine.


Here is my code:

Code:
import javax.mail.*;
public class getMail 

{
    
private String userName;
    
private String userPassword;
    
private String mailServer;
    
public getMail(String inputUserName, String inputPassword, String inputMailServer)
    
{
        
    userName = inputUserName;
    
    userPassword = inputPassword;
    
    mailServer =inputMailServer;
    
    processMail(userName, userPassword, mailServer);
    
}
    
    

public static void main(String[] args) 

{
        
// TODO Auto-generated method stub
        
//System.out.println("Hi");
        
getMail getSafedocMail = new getMail("dcm", "dcm01", "mail.safedoc.ie");
    
}
    
    
    


private void printData(String inputString)
    
{   
    System.out.println(inputString);   
}
    
    
    


private void processMail(String inputUserName, String inputPassword, String inputMailServer)
    
{
    
    Session session = null;
    
    Store store = null;
    
    printData("-------------connecting to mail-----------------");
        
    session = Session.getDefaultInstance(System.getProperties(), null);
    

    try 
        
    {
            

        store = session.getStore("pop3");
        
    } 
        
    catch (NoSuchProviderException e) 
    
    {
    
        e.printStackTrace();
    
    }
    
}


Any idea lads?
# 2  
Old 05-06-2009
Run with classpath to JavaMail specified also. JavaMail is NOT part of Java SE.

java -cp ../lib/javaMail/javaMail.jar javaMail
# 3  
Old 05-06-2009
got it working

Cheers man.

Your right, it is wrong.

Ithis is the command that worked:

java -classpath ../../lib/mail.mail.jar:./ getMailPackage.getMail

(The character ':' seperates the classpathes.)
I needed to include the .jar file and also the current directory './'

Because my class 'getMail' was in the package 'getMailPackage' I had to call it from that package directory.

Hopes this solves a few problems as i've been stuck on it for at least a day Smilie

.... ...now onto creating and running .jar files!!!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Using basic UNIX commands to make/compile JAVA files

Hello! This is my first post, and I just learned what UNIX was this week. For a JAVA programming class I am taking, I must be able to create a directory in UNIX, use the nano command to create a JAVA program, compile it, and then run it on the command prompt using the java command. For some... (5 Replies)
Discussion started by: UNdvoItX
5 Replies

2. UNIX for Dummies Questions & Answers

How to compile and run java in UNIX?

Hi Im using MobaXterm Unix on my windows XP.I want to compile java in unix.I have installed java to the following path C:\Program Files\Java\jdk1.7.0_09\bin In order to compile the java prog im typing the following command after entering into the bin directory: C:\Program... (2 Replies)
Discussion started by: ak3141
2 Replies

3. Shell Programming and Scripting

Who -u gives different output if run from cron than if run from terminal?

If I run 'who -u' interactively or from a script invoked through bash in a tty on my Ubuntu 12LTS box I get an output like this: testuser pts/0 Dec 9 02:32 . 2163 (host.xx.yy) running the same through cron I get: testuser pts/0 2012-12-09 02:32 00:05 2163... (2 Replies)
Discussion started by: latimer
2 Replies

4. UNIX for Advanced & Expert Users

java compile and run program help

What is the trick to get a java program to run and compile? I can't even get a basic skeleton to run and compile. What packages do I need? I figured the java-gcj and gcc-java packages was enough. Do I need any other packages? I thought I had to do this and it would work but its not. javac... (1 Reply)
Discussion started by: cokedude
1 Replies

5. Programming

Can someone compile and run a program on AIX 6.1 please?

Hi, I have a program which collects performance data from AIX. It works fine on older releases (< 5.3) but I fail to get data from /proc. I would really appreciate it if someone could compile (using ANSI compat C compiler), run the program (for 30-40 minutes) on AIX 6.1 and send me the... (2 Replies)
Discussion started by: StuBob
2 Replies

6. UNIX for Dummies Questions & Answers

Compile & Run Java Code

The java program is a part of speech tagger -> The Stanford NLP (Natural Language Processing) Group The goal is to use this script as part of a webpage to tag parts of speech based on a user-inputted string. I have no idea what to do with the files - I'm a complete *nix noob. I tried running... (4 Replies)
Discussion started by: tguillea
4 Replies

7. HP-UX

Compile .java

How would I go about compiling a .java file into a .class file? (1 Reply)
Discussion started by: Tecron
1 Replies

8. Solaris

how to compile and run java programs

Hi, I have installed Solaris 10 on a VMware. How to compile a java program as there is no javac in 'bin' directory. Thanks in advance for answers and sorry if the question is soo basic. (3 Replies)
Discussion started by: mayahari
3 Replies

9. Programming

how can compile cpp code containing references to java classes

hi there is example (on link given below )of such code that contains java class reference in c++ program. http://slackware.cs.utah.edu/pub/slackware/slackware-7.1/docs/Linux-HOWTO/Process-Monitor-HOWTO I am new in linux environment. and not able to compile it. when i compile it through... (1 Reply)
Discussion started by: surinder
1 Replies

10. Programming

compile java with GUI on unix system/putty

is it possible in the first place? if so, how should I go about it? (0 Replies)
Discussion started by: finalight
0 Replies
Login or Register to Ask a Question