OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Configuring OPen Office SDK in Linux

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> Setup and Troubleshooting
View previous topic :: View next topic  
Author Message
ammameiya
Newbie
Newbie


Joined: 29 Dec 2007
Posts: 3

PostPosted: Sat Dec 29, 2007 5:53 am    Post subject: Configuring OPen Office SDK in Linux Reply with quote

i did a JAVA system using eclipse and this system needs me to configure open office in my PC ( using windows).
this system has a features that user can convert a word document to pdf.
i'm not having problem with ooo in my windows pc.. but when i tried to deploy the ear file in a Linux server, i encountered this error

java.lang.UnsatisfiedLinkError: com.sun.star.lib.connections.pipe.PipeConnection.createJNI(Ljava/lang/String;)


my SE did install the JRE, and configured the SDK (in the linux ).. but the same problem occured.
do we need to install JAVA SDK in that linux server?
does anyone knows exactly how to configure open office in Linux ( i'm using CentOS and open office SDK 2.3).

thank you in advanced
Back to top
View user's profile Send private message
hol.sten
Super User
Super User


Joined: 14 Nov 2004
Posts: 3533
Location: Hamburg, Germany

PostPosted: Sat Dec 29, 2007 6:35 am    Post subject: Re: Configuring OPen Office SDK in Linux Reply with quote

ammameiya wrote:
java.lang.UnsatisfiedLinkError: com.sun.star.lib.connections.pipe.PipeConnection.createJNI(Ljava/lang/String;)

I have no idea how you try to connect from your Java application to OOo. I have no idea which application server you are using. I have no idea which (JAR) files are in your EAR file. So it is hard to guess why your code works on Windows but not on CentOS.

Before I would try to deploy an EAR file on a new environment, I would try to get a simple Java application running there. Try the following thread which covers two simple Java examples (BootstrapConnectionOdtToPdfQuickAndDirty, InterprocessConnectionOdtToPdfQuickAndDirty) on how to connect to OOo and use it to convert a file to a PDF: http://www.oooforum.org/forum/viewtopic.phtml?t=66424

Try first to get this examples running. If they run, give your ear another try.

ammameiya wrote:
do we need to install JAVA SDK in that linux server?

No, I don't think so.

ammameiya wrote:
does anyone knows exactly how to configure open office in Linux ( i'm using CentOS and open office SDK 2.3).

Install the downloaded file the way your Linux distribution provides and run it at least once as the user, which executes your EAR file. That should suffice.

Regards
hol.sten
Back to top
View user's profile Send private message
ammameiya
Newbie
Newbie


Joined: 29 Dec 2007
Posts: 3

PostPosted: Mon Dec 31, 2007 2:43 am    Post subject: Reply with quote

thanks for the reply

i tried to run the ear that being compiled in Windows in Linux.
i'm using JBOSS , Open Office 2.3, and JDK 1.6 for both platform..

actually my system works fine in Windows..but the problem happens when i tried to run the system form the server.. (same ear file for both platform)
i already tried all the solution that you suggested, but it won't work.. I'm not sure whether i missed out anything.. i paste my codes here..






Quote:


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Hashtable;
import java.util.Random;

import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet;
import com.sun.star.bridge.UnoUrlResolver;
import com.sun.star.bridge.XUnoUrlResolver;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.comp.helper.BootstrapException;
import com.sun.star.comp.helper.ComponentContext;
import com.sun.star.comp.helper.ComponentContextEntry;
import com.sun.star.comp.loader.JavaLoader;
import com.sun.star.connection.NoConnectException;
import com.sun.star.container.XSet;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XStorable;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XInitialization;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XSingleComponentFactory;
import com.sun.star.lib.util.NativeLibraryLoader;
import com.sun.star.loader.XImplementationLoader;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.util.XCloseable;

import org.apache.log4j.Logger;

public class CallingConverter {

static XComponentLoader xCompLoader = null;

// convert document to pdf
static String sConvertType = "writer_pdf_Export";


// containing source file
static String sInputFile = null;

// containing target file
static String sOutputFile = null;

public static int i = 0;


private static final Logger log = Logger.getLogger(CallingConverter.class);

public CallingConverter(String sInputFile, String sOutputFile) {

this.sInputFile = "usr/test_linux/attachment_1.odt";
this.sOutputFile = "usr/test_linux/attachment_1.pdf";


}

public static int convertDocument(){
XComponentContext xContext = null;
try {

// get the remote office component context

String ooBaseDirectory = "/opt/openoffice.org2.3/program";
URL[] jarList = new URL[] {new File(ooBaseDirectory).toURL()};

URLClassLoader loader = new URLClassLoader(jarList);
xContext =(XComponentContext) bootstrap(loader);


Runtime.getRuntime().exec(ooBaseDirectory + "/soffice -accept=socket,host=localhost,port=8100\\;urp;StarOffice.ServiceManager");
Thread.sleep(10000);

XMultiComponentFactory xLocalServiceManager = xContext.getServiceManager();
Object urlResolver = xLocalServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", xContext);
XUnoUrlResolver xUrlResolver = (XUnoUrlResolver) UnoRuntime.queryInterface(XUnoUrlResolver.class, urlResolver);

Object initialObject = xUrlResolver.resolve("uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager");
XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, initialObject);
Object context = xPropertySet.getPropertyValue("DefaultContext");
XComponentContext xRemoteContext = (XComponentContext)UnoRuntime.queryInterface(XComponentContext.class, context);
XMultiComponentFactory mxRemoteServiceManager = xRemoteContext.getServiceManager();

Object desktop = mxRemoteServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", xRemoteContext);
xCompLoader = (XComponentLoader)UnoRuntime.queryInterface(XComponentLoader.class, desktop);


// starting conversion
traverse();

} catch (Exception e) {
e.printStackTrace(System.err);

}

return i;
}

// converting document to favoured type
static int traverse() {
try {

log.info("inside traverse() ");
// loading wanted document
PropertyValue propertyValues[] = new PropertyValue[2];
propertyValues[0] = new PropertyValue();
propertyValues[0].Name = "Hidden";
propertyValues[0].Value = new Boolean(true);
propertyValues[1] = new PropertyValue();
propertyValues[1].Name = "Hidden";
propertyValues[1].Value = new Boolean(true);

Object oDocToStore = xCompLoader.loadComponentFromURL(sInputFile, "blank", 0, propertyValues);


// getting object to store a document to url
XStorable xStorable = (XStorable) UnoRuntime.queryInterface(XStorable.class, oDocToStore);

// set pdf property
PropertyValue pVal[] = new PropertyValue[5];
pVal[0] = new PropertyValue();
pVal[0].Name = "RestrictPermissions";
pVal[0].Value = new Boolean(true);

pVal[1] = new PropertyValue();
pVal[1].Name = "PermissionPassword";
pVal[1].Value = "1234";

pVal[2] = new PropertyValue();
pVal[2].Name = "EnableCopyingOfContent";
pVal[2].Value = new Boolean(false);

pVal[3] = new PropertyValue();
pVal[3].Name = "Changes";
pVal[3].Value = new Integer(0);

pVal[4] = new PropertyValue();
pVal[4].Name = "EnableTextAccessForAccessibilityTools";
pVal[4].Value = new Boolean(false);


// preparing properties for converting document
propertyValues = new PropertyValue[3];
// setting the flag for overwriting
propertyValues[0] = new PropertyValue();
propertyValues[0].Name = "Overwrite";
propertyValues[0].Value = new Boolean(true);

// setting the filter name
propertyValues[1] = new PropertyValue();
propertyValues[1].Name = "FilterName";
propertyValues[1].Value = sConvertType;

propertyValues[2] = new PropertyValue();
propertyValues[2].Name = "FilterData";
propertyValues[2].Value = pVal;

// storing and converting the document

xStorable.storeToURL(sOutputFile, propertyValues);
// xStorable.storeAsURL(sOutputFile, propertyValues);


// closing converted document
XCloseable xCloseable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, xStorable);
i = 1;
if (xCloseable != null) {
xCloseable.close(false);
} else {
XComponent xComp = (XComponent) UnoRuntime.queryInterface(XComponent.class, xStorable);
xComp.dispose();
}
} catch (Exception e) {
i=-1;
log.info("-----> Conversion failed.");
e.printStackTrace();
}
return i;
}



public static void insertBasicFactories(XSet xset, XImplementationLoader ximplementationloader)
throws Exception
{
log.info("inside insertBasicFactories() ");
xset.insert(ximplementationloader.activate("com.sun.star.comp.loader.JavaLoader", null, null, null));
xset.insert(ximplementationloader.activate("com.sun.star.comp.urlresolver.UrlResolver", null, null, null));
xset.insert(ximplementationloader.activate("com.sun.star.comp.bridgefactory.BridgeFactory", null, null, null));
xset.insert(ximplementationloader.activate("com.sun.star.comp.connections.Connector", null, null, null));
xset.insert(ximplementationloader.activate("com.sun.star.comp.connections.Acceptor", null, null, null));
}

public static final XComponentContext bootstrap(URLClassLoader loader)
throws BootstrapException
{

log.info("inside bootstrap() ");
XComponentContext xcomponentcontext = null;
try
{

XComponentContext xcomponentcontext1 = createInitialComponentContext(null);
if(xcomponentcontext1 == null)
throw new BootstrapException("no local component context!");
//ai
String vOs = System.getProperty("os.name");
boolean vIsLinux = vOs.startsWith("Linux");
boolean vIsWin = vOs.startsWith("Windows");


String sOffice = vIsWin ? "soffice.exe" : (vIsLinux ? "soffice.bin" : "soffice");
File file = NativeLibraryLoader.getResource(loader, sOffice);


if(file == null)
throw new BootstrapException("no office executable found!");
String s1 = "uno" + Long.toString((new Random()).nextLong() & 0x7fffffffffffffffL);
String as[] = new String[7];
as[0] = file.getPath();
as[1] = "-nologo";
as[2] = "-nodefault";
as[3] = "-norestore";
as[4] = "-nocrashreport";
as[5] = "-nolockcheck";
as[6] = "-accept=pipe,name=" + s1 + ";urp;";
Process process = Runtime.getRuntime().exec(as);
pipe(process.getInputStream(), System.out, "CO> ");
pipe(process.getErrorStream(), System.err, "CE> ");
XMultiComponentFactory xmulticomponentfactory = xcomponentcontext1.getServiceManager();
if(xmulticomponentfactory == null)
throw new BootstrapException("no initial service manager!");
XUnoUrlResolver xunourlresolver = UnoUrlResolver.create(xcomponentcontext1);
String s2 = "uno:pipe,name=" + s1 + ";urp;StarOffice.ComponentContext";
do
try
{
Object obj = xunourlresolver.resolve(s2);
xcomponentcontext = (XComponentContext)UnoRuntime.queryInterface(com.sun.star.uno.XComponentContext.class, obj);
if(xcomponentcontext == null)
throw new BootstrapException("no component context!");
break;
}
catch(NoConnectException noconnectexception)
{
Thread.currentThread();
Thread.sleep(500L);
}
while(true);
}
catch(BootstrapException bootstrapexception)
{
throw bootstrapexception;
}
catch(RuntimeException runtimeexception)
{
throw runtimeexception;
}
catch(Exception exception)
{
throw new BootstrapException(exception);
}
return xcomponentcontext;
}

public static void pipe(InputStream inputstream, PrintStream printstream, String s)
{
log.info("inside pipe");

(new Thread(s) {

public void run()
{
BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in));
try
{
do
{
String s1 = bufferedreader.readLine();
if(s1 == null)
break;
int prefix = 0;
log.info(prefix + s1);
} while(true);
}
catch(IOException ioexception)
{
ioexception.printStackTrace(System.err);
}
}

}).start();
}

public static XComponentContext createInitialComponentContext(Hashtable hashtable)
throws Exception
{

log.info("inside createInitialComponentContext");
XImplementationLoader ximplementationloader = (XImplementationLoader)UnoRuntime.queryInterface(com.sun.star.loader.XImplementationLoader.class, new JavaLoader());
XSingleComponentFactory xsinglecomponentfactory = (XSingleComponentFactory)UnoRuntime.queryInterface(com.sun.star.lang.XSingleComponentFactory.class, ximplementationloader.activate("com.sun.star.comp.servicemanager.ServiceManager", null, null, null));
XMultiComponentFactory xmulticomponentfactory = (XMultiComponentFactory)UnoRuntime.queryInterface(com.sun.star.lang.XMultiComponentFactory.class, xsinglecomponentfactory.createInstanceWithContext(null));
XInitialization xinitialization = (XInitialization)UnoRuntime.queryInterface(com.sun.star.lang.XInitialization.class, ximplementationloader);
Object aobj[] = {
xmulticomponentfactory
};
xinitialization.initialize(aobj);
if(hashtable == null)
hashtable = new Hashtable(1);
hashtable.put("/singletons/com.sun.star.lang.theServiceManager", new ComponentContextEntry(null, xmulticomponentfactory));
ComponentContext componentcontext = new ComponentContext(hashtable, null);
xinitialization = (XInitialization)UnoRuntime.queryInterface(com.sun.star.lang.XInitialization.class, xmulticomponentfactory);
aobj = (new Object[] {
null, componentcontext
});
xinitialization.initialize(aobj);
XSet xset = (XSet)UnoRuntime.queryInterface(com.sun.star.container.XSet.class, xmulticomponentfactory);
xset.insert(xsinglecomponentfactory);
insertBasicFactories(xset, ximplementationloader);
return componentcontext;
}


}


the error that i got when tried run the system from linux is :

java.lang.UnsatisfiedLinkError: com.sun.star.lib.connections.pipe.PipeConnection.createJNI(Ljava/lang/String;)

thanks
Back to top
View user's profile Send private message
hol.sten
Super User
Super User


Joined: 14 Nov 2004
Posts: 3533
Location: Hamburg, Germany

PostPosted: Mon Dec 31, 2007 3:17 am    Post subject: Reply with quote

ammameiya wrote:
i already tried all the solution that you suggested

So "BootstrapConnectionOdtToPdfQuickAndDirty" and "InterprocessConnectionOdtToPdfQuickAndDirty" are running as expected on your Linux server?

ammameiya wrote:
i paste my codes here..

I take a quick look...

Code:
...
import java.net.URLClassLoader;
...

         URLClassLoader loader = new URLClassLoader(jarList);
         xContext =(XComponentContext) bootstrap(loader);
...

Sorry, but I never worked with the URLClassLoader. Why are you using it?

Code:
...
         Runtime.getRuntime().exec(ooBaseDirectory + "/soffice -accept=socket,host=localhost,port=8100\\;urp;StarOffice.ServiceManager");
...
            Object initialObject = xUrlResolver.resolve("uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager");
...

So here you are using a socket connection.

Code:
...
         Thread.sleep(10000);
...

Perhaps 10 seconds are to short?

Code:
...
         // loading wanted document
         PropertyValue propertyValues[] = new PropertyValue[2];
         propertyValues[0] = new PropertyValue();
         propertyValues[0].Name = "Hidden";
         propertyValues[0].Value = new Boolean(true);
         propertyValues[1] = new PropertyValue();
         propertyValues[1].Name = "Hidden";
         propertyValues[1].Value = new Boolean(true);
...

I think this is not related to your problem, but why are you trying to hide twice?

Code:
...
            String s1 = "uno" + Long.toString((new Random()).nextLong() & 0x7fffffffffffffffL);
            String as[] = new String[7];
            as[0] = file.getPath();
            as[1] = "-nologo";
            as[2] = "-nodefault";
            as[3] = "-norestore";
            as[4] = "-nocrashreport";
            as[5] = "-nolockcheck";
            as[6] = "-accept=pipe,name=" + s1 + ";urp;";
...
String s2 = "uno:pipe,name=" + s1 + ";urp;StarOffice.ComponentContext";
...

Here you are preparing a pipe connection. What for? Why are you using a pipe connection AND a socket connection?

ammameiya wrote:
the error that i got when tried run the system from linux is :

java.lang.UnsatisfiedLinkError: com.sun.star.lib.connections.pipe.PipeConnection.createJNI(Ljava/lang/String;)

In which line of your code?

My advice: Don't use the pipe connection, use the socket connection only. Change your code and use the Interprocess connection mechanism.

Regards
hol.sten
Back to top
View user's profile Send private message
ammameiya
Newbie
Newbie


Joined: 29 Dec 2007
Posts: 3

PostPosted: Mon Dec 31, 2007 8:08 pm    Post subject: Reply with quote

well..my mistakes actually.. because i mixed your code with mine.. Sad
so, i just use InterprocessConnectionOdtToPdfQuickAndDirty and it works fine in both linux and windows..

my system can convert the doc file to pdf now. thanks Very Happy
Back to top
View user's profile Send private message
hol.sten
Super User
Super User


Joined: 14 Nov 2004
Posts: 3533
Location: Hamburg, Germany

PostPosted: Tue Jan 01, 2008 4:29 am    Post subject: Reply with quote

ammameiya wrote:
i just use InterprocessConnectionOdtToPdfQuickAndDirty and it works fine in both linux and windows..

my system can convert the doc file to pdf now. thanks Very Happy

Posting your now working code might help others having the same problem.

Thanks to add '[Solved]' in your first post title (edit button).
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> Setup and Troubleshooting All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group