I have a class Test.java
import com.sun.star.bridge.XUnoUrlResolver;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
public class Test {
XMultiServiceFactory ooConnect() {
final String sConnectionString = "uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager";
// create the initial component context
XComponentContext rComponentContext = null;
try {
rComponentContext = Bootstrap
.defaultBootstrap_InitialComponentContext();
} catch (Exception e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
// retrieve the servicemanager from the context
XMultiComponentFactory rServiceManager = rComponentContext
.getServiceManager();
Object objectUrlResolver = null;
try {
objectUrlResolver = rServiceManager.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", rComponentContext);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// Create a new url resolver
XUnoUrlResolver xurlresolver = (XUnoUrlResolver) UnoRuntime
.queryInterface(XUnoUrlResolver.class, objectUrlResolver);
XMultiServiceFactory rOfficeServiceManager = null;
try {
// resolve the uno-url
Object objectInitial = xurlresolver.resolve(sConnectionString);
rOfficeServiceManager = (XMultiServiceFactory) UnoRuntime
.queryInterface(XMultiServiceFactory.class, objectInitial);
} catch (Exception e) {
e.printStackTrace();
return rOfficeServiceManager;
}
return rOfficeServiceManager;
}
public static void main (String [] args)
{
Test test = new Test();
XMultiServiceFactory serviceFactory = test.ooConnect();
if(serviceFactory != null)
{
System.out.println("YEYEYEYEY");
}
}
}
why I try to compile this I use this command
javac -cp java_uno.jar;juh.jar;jurt.jar;ridl.jar;unoil.jar Test.java
it successfully compiles and give me a class.
but When I try to execute the class with below command
java Test, I get below error
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/star/comp/helper/Bootstrap
at Test.ooConnect(Test.java:18)
at Test.main(Test.java:64)
Caused by: java.lang.ClassNotFoundException: com.sun.star.comp.helper.Bootstrap
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 2 more
or if I use this command
java -cp .:java_uno.jar;juh.jar;jurt.jar;ridl.jar;unoil.jar Test
I get this error Error: Could not find or load main class Test
any help will be appreciated.
as suggested I changed the run command to
java -cp .;java_uno.jar;juh.jar;jurt.jar;ridl.jar;unoil.jar Test
now I get this exception
Exception in thread "main" java.lang.UnsatisfiedLinkError: no juh in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1886)
at java.lang.Runtime.loadLibrary0(Runtime.java:849)
at java.lang.System.loadLibrary(System.java:1088)
at com.sun.star.lib.util.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:65)
at com.sun.star.comp.helper.Bootstrap.defaultBootstrap_InitialComponentContext(Bootstrap.java:199)
at com.sun.star.comp.helper.Bootstrap.defaultBootstrap_InitialComponentContext(Bootstrap.java:167)
at Test.ooConnect(Test.java:18)
at Test.main(Test.java:64)
On Windows class separator in classpath is semicolon (;). For UNIX it is colon (:). You are using both separators in one command line:
Since your compilation was good I assume you are on Windows. So, use semicolon for whole path: