Results 1 to 9 of 9
  1. #1
    Leroy is offline Member
    Join Date
    Nov 2010
    Posts
    5
    Rep Power
    0

    Default java.lang.ClassNotFoundException: com.sun.star.lang.XEventListener

    Hi, I already have searched the forum and find a similar error, but the thread is from 2008 and the solution doesn't work for me. I'm having the error described in the title in the following servlet

    code:
    import com.sun.star.lang.XEventListener;

    import java.io.File;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.Iterator;
    import java.util.List;
    import java.util.StringTokenizer;

    import javax.servlet.ServletConfig;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import org.apache.commons.fileupload.FileItem;
    import org.apache.commons.fileupload.FileUploadException;
    import org.apache.commons.fileupload.disk.DiskFileItemFac tory;
    import org.apache.commons.fileupload.servlet.ServletFileU pload;

    import com.artofsolving.jodconverter.DocumentConverter;
    import com.artofsolving.jodconverter.openoffice.connectio n.OpenOfficeConnection;
    import com.artofsolving.jodconverter.openoffice.connectio n.SocketOpenOfficeConnection;
    import com.artofsolving.jodconverter.openoffice.converter .OpenOfficeDocumentConverter;


    public class CommonsFileUploadServlet extends HttpServlet {
    private String host = "localhost";
    private int port = 8100;
    private static String TMP_DIR_PATH = "C:\\tmp";
    private File tmpDir;
    private static String DESTINATION_DIR_PATH ="C:\\tmp";
    private File destinationDir;

    /*public void init(ServletConfig config) throws ServletException {
    super.init(config);
    tmpDir = new File(TMP_DIR_PATH);
    if(!tmpDir.isDirectory()) {
    throw new ServletException(TMP_DIR_PATH + " is not a directory");
    }
    //String realPath = getServletContext().getRealPath(DESTINATION_DIR_PA TH);
    String realPath= DESTINATION_DIR_PATH;
    destinationDir = new File(realPath);
    if(!destinationDir.isDirectory()) {
    throw new ServletException(DESTINATION_DIR_PATH+" is not a directory");
    }

    }*/

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    System.setProperty("java.io.tmpdir",this.getServle tContext().getRealPath("TempFiles"));
    String servlet_context=System.setProperty("java.io.tmpdir ",this.getServletContext().getRealPath("TempFiles" ));
    System.out.println("context " + System.setProperty("java.io.tmpdir",this.getServle tContext().getRealPath("TempFiles")));
    tmpDir= new File(servlet_context);
    destinationDir=new File(servlet_context);
    PrintWriter out = response.getWriter();
    response.setContentType("text/plain");
    out.println("<h1>Servlet File Upload Example using Commons File Upload</h1>");
    out.println();

    DiskFileItemFactory fileItemFactory = new DiskFileItemFactory ();
    /*
    *Set the size threshold, above which content will be stored on disk.
    */
    fileItemFactory.setSizeThreshold(1*1024*1024); //1 MB
    /*
    * Set the temporary directory to store the uploaded files of size above threshold.
    */
    fileItemFactory.setRepository(tmpDir);

    ServletFileUpload uploadHandler = new ServletFileUpload(fileItemFactory);
    try {
    /*
    * Parse the request
    */
    List items = uploadHandler.parseRequest(request);
    Iterator itr = items.iterator();
    while(itr.hasNext()) {
    FileItem item = (FileItem) itr.next();
    /*
    * Handle Form Fields.
    */
    if(item.isFormField()) {
    out.println("File Name = "+item.getFieldName()+", Value = "+item.getString());
    } else {
    //Handle Uploaded files.
    out.println("Field Name = "+item.getFieldName()+
    ", File Name = "+item.getName()+
    ", Content type = "+item.getContentType()+
    ", File Size = "+item.getSize());
    /*
    * Write file to the ultimate location.
    */
    File file = new File(destinationDir,removeSpaces(item.getName()));
    item.write(file);
    System.out.println("Starting conversion");
    convert(file.getAbsolutePath());
    }
    out.close();
    }
    }catch(FileUploadException ex) {
    log("Error encountered while parsing the request",ex);
    } catch(Exception ex) {
    log("Error encountered while uploading file",ex);
    }

    }


    public boolean convert(String fileName) {
    System.out.println("filename " + fileName);
    String servlet_context=this.getServletContext().getRealPa th("TempFiles") + "\\rfxview.swf";
    System.out.println("servlet_context " + servlet_context);
    //TODO linux version String temp = "sudo pdf2swf @src -o @dst -s insertstop --viewer=servlet_context";
    String temp = "pdf2swf @src -o @dst -s insertstop --viewer="+servlet_context;
    //log.debug("Inizio conversione di:" +folder+fileName);
    //String temp = command;
    File inputFile = new File(fileName);
    System.out.println("inputFile has been created in folder " + inputFile.getAbsolutePath());
    if (!inputFile.exists())
    return false;
    try {
    //log.debug("Controllo il file di output: " + folder + fileName.substring(0,fileName.lastIndexOf("."))+". pdf");
    File outputFile = new File(fileName.substring(0,fileName.lastIndexOf("." ))+".pdf");
    if (!fileName.endsWith(".pdf")){
    OpenOfficeConnection connection = new SocketOpenOfficeConnection(host,port);
    connection.connect();

    //log.debug("Connesso a openoffice");
    System.out.println("Connesso a openoffice");
    DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
    converter.convert(inputFile, outputFile);
    connection.disconnect();
    System.out.println("Conversione in pdf terminata");
    }

    //log.debug("inizio la conversione in swf.");
    temp = temp.replace("@src", outputFile.getAbsolutePath());
    System.out.println("src is " + outputFile.getAbsolutePath());
    String swfFilepath=removeSpaces(fileName.substring(0,file Name.lastIndexOf("."))+".swf");
    temp = temp.replace("@dst", swfFilepath);
    System.out.println("dst is " + swfFilepath);
    System.out.println("Command line to be executed is " + temp);

    System.out.println("Starting the process");

    Process p = Runtime.getRuntime().exec(temp);
    //log.info(temp);

    //Codice per evitare starvation in Windows
    StreamGobbler errorGobbler = new
    StreamGobbler(p.getErrorStream(), "ERROR");

    // any output?
    StreamGobbler outputGobbler = new
    StreamGobbler(p.getInputStream(), "OUTPUT");

    // kick them off
    errorGobbler.start();
    outputGobbler.start();

    // any error??? // Fine codice starvation
    int exitVal=p.waitFor();
    System.out.println("ExitValue: " + exitVal);
    System.out.println("Process completed");

    } catch (IOException e) {
    //log.info("IOException: " +e.toString());
    e.printStackTrace();
    return false;
    } catch (InterruptedException e) {
    e.printStackTrace();
    return false;
    }

    return true;
    }

    public static String removeSpaces(String s) {
    StringTokenizer st = new StringTokenizer(s," ",false);
    String t="";
    while (st.hasMoreElements()) t += st.nextElement();
    return t;
    }
    }

    You can se a StreamGobbler class in the code, it's a class that I use to clean the stream on windows.

    Now, I'll describe what i do to get this error:
    -First I launch soffice via cmd using soffice.exe -headless -nofirststartwizard -accept="socket,host=localhost,port=8100;urp;StarOf fice.Service"
    And it works 'cause i see the service is listening on port 8100

    -Then i try to upload a file by a html page and the, i get the error, printstack is the following:
    GRAVE: Servlet.service() for servlet CommonsFileUploadServlet threw exception
    java.lang.ClassNotFoundException: com.sun.star.lang.XEventListener
    at org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1438)
    at org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1284)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at org.apache.catalina.loader.WebappClassLoader.findC lassInternal(WebappClassLoader.java:1960)
    at org.apache.catalina.loader.WebappClassLoader.findC lass(WebappClassLoader.java:933)
    at org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1405)
    at org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1284)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at org.apache.catalina.loader.WebappClassLoader.findC lassInternal(WebappClassLoader.java:1960)
    at org.apache.catalina.loader.WebappClassLoader.findC lass(WebappClassLoader.java:933)
    at org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1405)
    at org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1284)
    at CommonsFileUploadServlet.convert(CommonsFileUpload Servlet.java:126)
    at CommonsFileUploadServlet.doPost(CommonsFileUploadS ervlet.java:97)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:729)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:172)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:117)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:108)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:174)
    at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:879)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11 ConnectionHandler.processConnection(Http11BaseProt ocol.java:665)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:528)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThr ead.runIt(LeaderFollowerWorkerThread.java:81)
    at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:689)
    at java.lang.Thread.run(Unknown Source)

    Other details:
    The imports on java project are fine and I'm using Oo 3.2

    Hope I'm doing thing right with this post, thanks in advance =)

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,165
    Rep Power
    20

    Default

    Please post code using the CODE tags.
    I can't read any of that.

    And also, if possible, pont out where that exception is being thrown.

    Anyway, where does that class reside? What jar file is it in? Is that jar file deployed with your servlet?

  3. #3
    Leroy is offline Member
    Join Date
    Nov 2010
    Posts
    5
    Rep Power
    0

    Default

    Ok, sorry for that

    Java Code:
    import com.sun.star.lang.XEventListener;
    
    import java.io.File;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.Iterator;
    import java.util.List;
    import java.util.StringTokenizer;
     
    import javax.servlet.ServletConfig;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
     
    import org.apache.commons.fileupload.FileItem;
    import org.apache.commons.fileupload.FileUploadException;
    import org.apache.commons.fileupload.disk.DiskFileItemFactory;
    import org.apache.commons.fileupload.servlet.ServletFileUpload;
    
    import com.artofsolving.jodconverter.DocumentConverter;
    import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
    import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
    import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;
    
     
    public class CommonsFileUploadServlet extends HttpServlet {
    	private String host = "localhost";
    	private int port = 8100;
    	private static String TMP_DIR_PATH = "C:\\tmp";
    	private File tmpDir;
    	private static String DESTINATION_DIR_PATH ="C:\\tmp";
    	private File destinationDir;
     
    	/*public void init(ServletConfig config) throws ServletException {
    		super.init(config);
    		tmpDir = new File(TMP_DIR_PATH);
    		if(!tmpDir.isDirectory()) {
    			throw new ServletException(TMP_DIR_PATH + " is not a directory");
    		}
    		//String realPath = getServletContext().getRealPath(DESTINATION_DIR_PATH);
    		String realPath= DESTINATION_DIR_PATH;
    		destinationDir = new File(realPath);
    		if(!destinationDir.isDirectory()) {
    			throw new ServletException(DESTINATION_DIR_PATH+" is not a directory");
    		}
     
    	}*/
    	
    	public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
    		System.out.println("Acquisendo la stringa");
    		String Url=request.getParameter("Insert Url");
    		Url=makeURL(Url);
    		response.sendRedirect(Url);
    	}
    	
    	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		System.setProperty("java.io.tmpdir",this.getServletContext().getRealPath("TempFiles"));
    		String servlet_context=System.setProperty("java.io.tmpdir",this.getServletContext().getRealPath("TempFiles"));
    		System.out.println("context " + System.setProperty("java.io.tmpdir",this.getServletContext().getRealPath("TempFiles")));
    		tmpDir= new File(servlet_context);
    		destinationDir=new File(servlet_context);
    		PrintWriter out = response.getWriter();
    	    response.setContentType("text/plain");
    	    out.println("<h1>Servlet File Upload Example using Commons File Upload</h1>");
    	    out.println();
     
    		DiskFileItemFactory  fileItemFactory = new DiskFileItemFactory ();
    		/*
    		 *Set the size threshold, above which content will be stored on disk.
    		 */
    		fileItemFactory.setSizeThreshold(1*1024*1024); //1 MB
    		/*
    		 * Set the temporary directory to store the uploaded files of size above threshold.
    		 */
    		fileItemFactory.setRepository(tmpDir);
     
    		ServletFileUpload uploadHandler = new ServletFileUpload(fileItemFactory);
    		try {
    			/*
    			 * Parse the request
    			 */
    			List items = uploadHandler.parseRequest(request);
    			Iterator itr = items.iterator();
    			while(itr.hasNext()) {
    				FileItem item = (FileItem) itr.next();
    				/*
    				 * Handle Form Fields.
    				 */
    				if(item.isFormField()) {
    					out.println("File Name = "+item.getFieldName()+", Value = "+item.getString());
    				} else {
    					//Handle Uploaded files.
    					out.println("Field Name = "+item.getFieldName()+
    						", File Name = "+item.getName()+
    						", Content type = "+item.getContentType()+
    						", File Size = "+item.getSize());
    					/*
    					 * Write file to the ultimate location.
    					 */
    					File file = new File(destinationDir,removeSpaces(item.getName()));
    					item.write(file);
    					System.out.println("Starting conversion");
    					convert(file.getAbsolutePath());
    				}
    				out.close();
    			}
    		}catch(FileUploadException ex) {
    			log("Error encountered while parsing the request",ex);
    		} catch(Exception ex) {
    			log("Error encountered while uploading file",ex);
    		}
    		
    	}
    	
    	
    	public  boolean convert(String fileName) {
    		System.out.println("filename " + fileName);
    		String servlet_context=this.getServletContext().getRealPath("TempFiles") + "\\rfxview.swf";
    		System.out.println("servlet_context " + servlet_context);
    		//TODO linux version String temp = "sudo pdf2swf @src -o @dst -s insertstop --viewer=servlet_context";
    		String temp = "pdf2swf @src -o @dst -s insertstop --viewer="+servlet_context;
    		//log.debug("Inizio conversione di:" +folder+fileName);
    		//String temp = command;
    		File inputFile = new File(fileName);
    		System.out.println("inputFile has been created in folder " + inputFile.getAbsolutePath());
    		if (!inputFile.exists())
    			return false;
    		try {
    			//log.debug("Controllo il file di output: " + folder + fileName.substring(0,fileName.lastIndexOf("."))+".pdf");
    			File outputFile = new File(fileName.substring(0,fileName.lastIndexOf("."))+".pdf");
    			if (!fileName.endsWith(".pdf")){
    				OpenOfficeConnection connection = new SocketOpenOfficeConnection(host,port);
    				connection.connect();
    
    				//log.debug("Connesso a openoffice");
    				System.out.println("Connesso a openoffice");
    				DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
    				converter.convert(inputFile, outputFile);
    				connection.disconnect();
    				System.out.println("Conversione in pdf terminata");
    			}
    			
    			//log.debug("inizio la conversione in swf.");
    			temp = temp.replace("@src", outputFile.getAbsolutePath());
    			System.out.println("src is " + outputFile.getAbsolutePath());
    			String swfFilepath=removeSpaces(fileName.substring(0,fileName.lastIndexOf("."))+".swf");
    			temp = temp.replace("@dst", swfFilepath);
    			System.out.println("dst is " + swfFilepath);
    			System.out.println("Command line to be executed is " + temp);
    			
    			System.out.println("Starting the process");
    			
    			Process p = Runtime.getRuntime().exec(temp);
    			//log.info(temp);
    	        
    			//Codice per evitare starvation in Windows
    	        StreamGobbler errorGobbler = new 
                StreamGobbler(p.getErrorStream(), "ERROR");            
            
    	        // any output?
    	        StreamGobbler outputGobbler = new 
                StreamGobbler(p.getInputStream(), "OUTPUT");
                
    	        // kick them off
    	        errorGobbler.start();
    	        outputGobbler.start();
                                    
    	        // any error??? // Fine codice starvation
    	        int exitVal=p.waitFor();
    	        System.out.println("ExitValue: " + exitVal);        
    	        System.out.println("Process completed");
    			
    		} catch (IOException e) {
    			//log.info("IOException: " +e.toString());
    			e.printStackTrace();
    			return false;
    		} catch (InterruptedException e) {
    			e.printStackTrace();
    			return false;
    		}
    
    		return true;
    	}
    	
    	public static String removeSpaces(String s) {
    		  StringTokenizer st = new StringTokenizer(s," ",false);
    		  String t="";
    		  while (st.hasMoreElements()) t += st.nextElement();
    		  return t;
    		}
    	
    	public static String makeURL(String Url){
    		System.out.println(Url);
    		String delims="[http://]";
    		String [] tokens= Url.split(delims);
    		for(int i=0; i<tokens.length; i++){
    			if(tokens[i].equals("http://"))
    				return Url;
    			}
    		return("http://" + Url);
    	}
    }
    The exception is thrown at
    OpenOfficeConnection connection = new SocketOpenOfficeConnection(host,port); (line 133)


    The class is in jodconverter 2.2 jar, a library I'm using for doing the conversion in pdf. I imported that library on the project the normal way (add external jar -> jodconverter). I donwloaded the jar files from sourceforge, that host jodconverter project.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,165
    Rep Power
    20

    Default

    Is that library being deployed to the server?
    It's the server that's having problems finding it.

  5. #5
    Leroy is offline Member
    Join Date
    Nov 2010
    Posts
    5
    Rep Power
    0

    Default

    Sorry for the newbish question, but it's the very first time that I develop a servlet...for "deployed on the server" you mean that the jar files need to appear under the Web App Libraries? If that's the case, mine doesn't

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,165
    Rep Power
    20

    Default

    At a guess, yes.
    Not sure what web server you are deploying to (Tomcat?), but the jars need to be deployed with your app.
    Normally you'd get a war file (Web Archive) which is plonked in the relevant directory on the server (tomcat/something or other).

  7. #7
    Leroy is offline Member
    Join Date
    Nov 2010
    Posts
    5
    Rep Power
    0

    Default

    Yes I'm deployng on Tomcat, sorry for not mentioning it.

    I founded the .war file, how can I deploy it on Tomcat?

    Sorry for being so newbie =(

  8. #8
    Leroy is offline Member
    Join Date
    Nov 2010
    Posts
    5
    Rep Power
    0

    Default

    Sorry for double posting.

    Resolved, i just copied the jar into the default Web Inf lib that eclipse create in the project.

    Thanks for all the support =)

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,165
    Rep Power
    20

    Default

    I'm presuming since you;re getting this error you're actually deploying already, otherwise how are you running this?

    ETA: Serves me right for posting without actually reading the latest post!
    :)

Similar Threads

  1. Replies: 5
    Last Post: 06-02-2010, 02:05 PM
  2. Replies: 3
    Last Post: 06-01-2010, 04:01 PM
  3. java.lang.ClassNotFoundException
    By ravian in forum New To Java
    Replies: 1
    Last Post: 01-07-2008, 11:31 AM
  4. Replies: 1
    Last Post: 07-24-2007, 12:54 AM
  5. Replies: 1
    Last Post: 06-27-2007, 06:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •