• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Classpath in Linux RedHat

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,

Anybody tell me how to set classpath in Linux environment .

I tried in linux Terminal to set classpath using command export CLASSPATH = "/lib/mail.jar" .

But is it is throwing "Not a Valid identifier".

and also i will provide windows environment its working fine.

Window : java -Djava.security.policy=".\java.POLICY" -classpath ".\lib\mail.jar";".\lib\activation.jar"; mail.MailServer

Can anyone convert to linux environment.?

and after set the CLASSPATH in linux. How to check if path is set or not.

I know this is basic question.


Kindly help me on this.


 
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vinoth sathiya wrote:HI,

Anybody tell me how to set classpath in Linux environment .

I tried in linux Terminal to set classpath using command export CLASSPATH = "/lib/mail.jar" .

But is it is throwing "Not a Valid identifier".


That is caused by the space between 'CLASSPATH' and '='.



and also i will provide windows environment its working fine.

Window : java -Djava.security.policy=".\java.POLICY" -classpath ".\lib\mail.jar";".\lib\activation.jar"; mail.MailServer

Can anyone convert to linux environment.?


Replace the semicolons by colons and get rid of the spaces between the class path terms. Also, I expected an '=' after -classpath !


and after set the CLASSPATH in linux. How to check if path is set or not.


Type

echo $CLASSPATH


Note - if you are using the '-classpath' you should not need to set the CLASSPATH environment variable since '-classpath' overrides CLASSPATH.
 
vinoth sathiya
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thank you for response.

i checked echo $CLASSPATH.

Its showing jar files.


After that while sending mail. it is showing below exception:

exception: Error occurred in server thread; nested exception is:
java.lang.NoClassDefFoundError: javax/mail/MessagingException
java.rmi.ServerError: Error occurred in server thread; nested exception is:
java.lang.NoClassDefFoundError: javax/mail/MessagingException
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:350)
at sun.rmi.transport.Transport$1.run(Transport.java:177)
at sun.rmi.transport.Transport$1.run(Transport.java:174)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:273)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:251)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:160)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)
at $Proxy0.sendInfo(Unknown Source)
at mail.MailClient.sendDtlServer(MailClient.java:24)
at panacea.mailAction.psmailThread.sendMail(psmailThread.java:191)
at panacea.mailAction.psmailThread.run(psmailThread.java:405)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NoClassDefFoundError: javax/mail/MessagingException
at mail.MailImpl.sendInfo(MailImpl.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322)
at sun.rmi.transport.Transport$1.run(Transport.java:177)
at sun.rmi.transport.Transport$1.run(Transport.java:174)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
at java.util.concurrent.ThreadPoolExecutor.runWorker(


Could you help?


 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Post the output of "echo $CLASSPATH".

By the way, I think it's much better to use the "-classpath" option rather the CLASSPATH environment variable. But then, I rarely use either, since I set up Ant build files for anything that goes beyond a single class.
 
Richard Tookey
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vinoth sathiya wrote:
Could you help?




The implication is that your mail jar is not on your effective classpath or is not where your classpath indicates it to be BUT since you have not posted the command line being used to run the program I can't help further.
 
vinoth sathiya
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Output of echo $CLASSPATH

:/lib/mail.jar:/lib/activation.jar
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's the first colon doing there? Remove that. Also, do you really have a root directory "lib" where you keep jar files?
 
vinoth sathiya
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Richard Tookey wrote:

vinoth sathiya wrote:
Could you help?




The implication is that your mail jar is not on your effective classpath or is not where your classpath indicates it to be BUT since you have not posted the command line being used to run the program I can't help further.




Hi,

Iam running using below cmd:

java mail.MailServer

 
vinoth sathiya
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:What's the first colon doing there? Remove that. Also, do you really have a root directory "lib" where you keep jar files?




Yes,

mail.jar and activation.jar are available in lib folder only
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And "lib" is in the root directory? Meaning, if you type "ls /lib" exactly, those jar files are listed?
 
Richard Tookey
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vinoth sathiya wrote:

Ulf Dittmer wrote:What's the first colon doing there? Remove that. Also, do you really have a root directory "lib" where you keep jar files?




Yes,

mail.jar and activation.jar are available in lib folder only



I'm not convinced . Post the result of

ls -al /lib/*.jar

Also, I see nothing in your class path to indicate where your main class is being picked up from. Post the result of

ls -al *.jar

and

ls -al *.class

 
vinoth sathiya
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Richard Tookey wrote:

vinoth sathiya wrote:
Ulf Dittmer]What's the first colon doing there? Remove that. Also, do you really have a root directory "lib" where you keep jar files?


Yes,

mail.jar and activation.jar are available in lib folder only



I'm not convinced . Post the result of

ls -al /lib/*.jar

Also, I see nothing in your class path to indicate where your main class is being picked up from. Post the result of

ls -al *.jar

and

ls -al *.class





Hi


[root@localhost mailpro]# ls -al /lib/*.jar
ls: cannot access /lib/*.jar: No such file or directory
[root@localhost mailpro]# ls -al /lib/*.jar
ls: cannot access /lib/*.jar: No such file or directory
[root@localhost mailpro]# ls -al *.jar
ls: cannot access *.jar: No such file or directory
[root@localhost mailpro]# ls -al *.class
ls: cannot access *.class: No such file or directory
[root@localhost mailpro]#
 
vinoth sathiya
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vinoth sathiya wrote:Hi,

Output of echo $CLASSPATH

:/lib/mail.jar:/lib/activation.jar





Hi,

When i remove colon in classpath like

/lib/mail.jar:/lib/activation.jar



Now when i execute the program it is throwing exeception:

Error: Could not find or load main class mail.MailServer


after change to CLASSPATH=:/lib/mail.jar:/lib/activation.jar

only able to execute the program. but it showing NoClassDefFoundError : javax/mail/MessaginException
 
Richard Tookey
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vinoth sathiya wrote:
[root@localhost mailpro]# ls -al /lib/*.jar
ls: cannot access /lib/*.jar: No such file or directory
[root@localhost mailpro]# ls -al /lib/*.jar
ls: cannot access /lib/*.jar: No such file or directory
[root@localhost mailpro]# ls -al *.jar
ls: cannot access *.jar: No such file or directory
[root@localhost mailpro]# ls -al *.class
ls: cannot access *.class: No such file or directory
[root@localhost mailpro]#



So the mail.jar and activation.jar are not in /lib and you don't have any class files or jar files in your current directory!

Post the result of

ls -al *
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So your classpath is wrong - you do not have a root directory called "lib". My guess is that "lib" is actually in your current directory - is that correct? If so, "ls lib" should show it, and CLASSPATH should be something like ".:lib/mail.jar:lib/activation.jar". Note the leading dot for picking up loose class files as well. The "mail" directory with the MailServer.class file in it also needs to be in your current directory
 
vinoth sathiya
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:So your classpath is wrong - you do not have a root directory called "lib". My guess is that "lib" is actually in your current directory - is that correct? If so, "ls lib" should show it, and CLASSPATH should be something like ".:lib/mail.jar:lib/activation.jar". Note the leading dot for picking up loose class files as well. The "mail" directory with the MailServer.class file in it also needs to be in your current directory




Hi,

i copied the two jars into mail directory and set the classpath (:mail/mail.jar:mail/activation.jar

After that executed mail.MailServer. still it throwing.


When i use ls -al /mail/*.jar
ls: cannot access /mail/*.jar: No such file or directory




 
Richard Tookey
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vinoth sathiya wrote:
i copied the two jars into mail directory and set the classpath (:mail/mail.jar:mail/activation.jar

After that executed mail.MailServer. still it throwing.


When i use ls -al /mail/*.jar
ls: cannot access /mail/*.jar: No such file or directory



Do you mean the root directory /mail or the local directory ./mail (i.e. a directory called 'mail' in your current working directory? If you mean your current working directory then you need

ls -al mail/*.jar

and your class path should reference the mail directory in the current working directory and not the root directory /mail .
 
vinoth sathiya
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Richard Tookey wrote:

vinoth sathiya wrote:
i copied the two jars into mail directory and set the classpath (:mail/mail.jar:mail/activation.jar

After that executed mail.MailServer. still it throwing.


When i use ls -al /mail/*.jar
ls: cannot access /mail/*.jar: No such file or directory



Do you mean the root directory /mail or the local directory ./mail (i.e. a directory called 'mail' in your current working directory? If you mean your current working directory then you need

ls -al mail/*.jar

and your class path should reference the mail directory in the current working directory and not the root directory /mail .



I have mailpro folder

in that two folder is there

one is "lib" containing mail.jar and activation.jar
second is "mail" containing main class and supported class files are there.

 
vinoth sathiya
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
while am using below command it is showing all files

[root@localhost mailpro]# ls -al lib/*.jar
-rw-r--r--. 1 root root 54665 Oct 7 2005 lib/activation.jar
-rw-r--r--. 1 root root 327603 Oct 7 2005 lib/mail.jar
[root@localhost mailpro]# ls -al mail/*.class
-rw-r--r--. 1 root root 1390 Sep 6 2011 mail/MailClient.class
-rw-r--r--. 1 root root 1703 Sep 6 2011 mail/MailImpl.class
-rw-r--r--. 1 root root 263 Sep 6 2011 mail/MailInterface.class
-rw-r--r--. 1 root root 1090 Sep 6 2011 mail/MailServer.class
-rw-r--r--. 1 root root 669 Oct 7 2013 mail/MyPasswordAuthenticator.class
-rw-r--r--. 1 root root 5062 Jun 24 12:36 mail/SendMail.class
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does "java -cp .:lib/*.jar mail.MailServer" work?
 
Richard Tookey
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Does "java -cp .:lib/*.jar mail.MailServer" work?



I don't think this can work since the main class is contained in subdirectory 'mail' . I would expect

"java -cp mail:lib/*.jar mail.MailServer"
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, the root of the class file hierarchy needs to be in the classpath, not any subdirectory of it.
 
Richard Tookey
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:No, the root of the class file hierarchy needs to be in the classpath, not any subdirectory of it.



Sorry! You are right. I was assuming his classes were in the default package but the main class has package 'mail' !
 
vinoth sathiya
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Does "java -cp .:lib/*.jar mail.MailServer" work?




Hi,

Sorry for the late reply.

I have checked the below path:

[root@localhost mailpro]# java -cp mail:lib/*.jar mail.MailServer

Error: Could not find or load main class mail.MailServer


Then i changed the below path and got below exception :

[root@localhost mailpro]# java -cp :lib/*.jar mail.MailServer
Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingException
at MailServer.<init>(MailServer.java:22)
at MailServer.main(MailServer.java:522)
Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 2 more



Is linux system have problem to setting classpath?


 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Neither "java -cp mail:lib/*.jar mail.MailServer" nor "java -cp :lib/*.jar mail.MailServer" is what I suggested to try. Programming is all about paying attention to detail - reread my post, and let us know how that works out.
 
This guy is skipping without a rope. At least, that's what this tiny ad said:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic