Trying to inject jcifs and UniAddress and get a NoClassDefFoundError?

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; } } 

Compilation is done if I do this:

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

However, if I ran 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 downloaded the full source code here:

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

Note. I do all this on Windows.

+4
source share
3 answers

It seems that your class myJavaApp is in some kind of package, and you did not specify the package name in addition to the lack of setting the class path.

My directory structure for testing:

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

I compiled it as follows:

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

which gave myJavaApp.class in the testapp folder as expected. I ran it on linux as follows:

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

and in such windows:

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

He threw away

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

which means myJavaApp was working successfully.

If we remove the testapp directive, for example.

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

It compiles with:

  javac -cp jcifs-1.3.17.jar myJavaApp.java 

and on linux it works 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 the root directory (.) / testing

EDIT ^ 2:

I downloaded your code and put myself in the netp directory. Compiled the code as follows:

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

and successfully execute it as follows:

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

output:

 START END 
+2
source

When you start the program, you need to provide jar in the class path:

 java -cp jcifs_1.3.17/jcifs-1.3.17.jar myJavaApp 
+1
source

Try adding the current directory to the class path:

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

If you are on Windows, replace the colon with a half-colon: java -cp .;jcifs-krb5-1.3.17/jcifs-krb5-1.3.17.jar myJavaApp

Greetings

+1
source

Source: https://habr.com/ru/post/1439391/


All Articles