4

I am using JCIFS (http://jcifs.samba.org/). My code is simple and taken from the Login.java example:

import jcifs.*;
import jcifs.smb.*;

public class netp {
    public static void main( String argv[] ) throws Exception {
     System.out.println("START");

     String ip = "10.0.0.1";
     String domain = "domain";
     String user = "user";
     String pass = "pass";

    UniAddress dc = UniAddress.getByName( ip );
    NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication( domain + ";" + user + ":" + pass );
    SmbSession.logon( dc, auth );

     System.out.println("END");

     return;
    }
}

Compiling this works if I do this:

javac -cp jcifs-krb5-1.3.17.jar netp.java

However, if I run it like this:

java -cp jcifs-1.3.17.jar netp

I get:

Error: Could not find or load main class netp

What am I doing wrong?

I've uploaded the complete source code here:

https://www.box.com/s/po4frdmy0obqiroy9anp

Note: I am doing this all in Windows.

rockstardev
  • 13,479
  • 39
  • 164
  • 296

3 Answers3

2

It seems that your myJavaApp class is in some package and you have omitted the package name in addition to not setting class path at all.

My directory structure for testing:

.
\--- jcifs-1.3.17.jar
\--- testapp
     \--- myJavaApp.java  

I compiled it like this:

javac -cp jcifs-1.3.17.jar testapp/myJavaApp.java

which gave myJavaApp.class in testapp folder as expected. I have run it on linux like this:

java -cp .:jcifs-1.3.17.jar testapp.myJavaApp

and on windows like this:

java -cp .;jcifs-1.3.17.jar testapp.myJavaApp

It throwed

jcifs.util.transport.TransportExceptionjava
java.net.NoRouteToHostException: No route to host

which means that the myJavaApp had run succesfully.

If we remove the testapp directoy, e.g.

.
\--- jcifs-1.3.17.jar
\--- myJavaApp.java 

it compiles with:

 javac -cp jcifs-1.3.17.jar myJavaApp.java

and on linux runs with:

java -cp .:jcifs-1.3.17.jar myJavaApp

for windows

java -cp .;jcifs-1.3.17.jar myJavaApp

EDIT:

all java[c] commands were run from root(.) / testing directory

EDIT^2:

I have downloaded your code and placed myself in netp directory. Compiled the code like this:

C:\netp>"C:\Program Files\Java\jdk1.6.0_25\bin\javac.exe" -cp jcifs-krb5-1.3.17.jar netp.java

and succesfully run it like this:

C:\netp>"C:\Program Files\Java\jdk1.6.0_25\bin\java.exe" -cp .;jcifs-krb5-1.3.17.jar netp

it outputs:

START
END
linski
  • 5,046
  • 3
  • 22
  • 35
  • Will try all of this now, but as an FYI, here is my code --> https://www.box.com/s/po4frdmy0obqiroy9anp – rockstardev Oct 15 '12 at 11:54
  • I've now changed what I had and I am running it exactly like this, but I still get: Error: Could not find or load main class netp.java ... for some reason it's not picking it up and I can't see why. – rockstardev Oct 15 '12 at 12:02
  • 2
    "Could not find or load main class netp.java" when you compile you put ".java". when you run there is no file type just full class name (in your case - just netp) see my last update – linski Oct 15 '12 at 12:10
  • So the problem has to do with PATH issues. If I run it the way you suggested, it works. I will keep investigating and post the final cause of the problem when I'm done! But thank you Linski! You helped a lot! – rockstardev Oct 15 '12 at 12:17
  • in order too run just "java[c]" from your command line you must have some jre[jdk] pointed at in your [PATH variable](http://www.computerhope.com/issues/ch000549.htm) see what's in there, you may be pointing at "wrong" jdk. – linski Oct 15 '12 at 12:21
1

You need to provide the jar on class path too when you run the program:

java -cp jcifs_1.3.17/jcifs-1.3.17.jar myJavaApp
Adam Dyga
  • 8,666
  • 4
  • 27
  • 35
1

Try adding current directory to the classpath as well:

java -cp .:jcifs-krb5-1.3.17/jcifs-krb5-1.3.17.jar myJavaApp

If you're on Windows, replace the colon with semi-colon: java -cp .;jcifs-krb5-1.3.17/jcifs-krb5-1.3.17.jar myJavaApp

Cheers,

Anders R. Bystrup
  • 15,729
  • 10
  • 59
  • 55