Created a plugin, works in developer but not in smart clien

Questions and answers on developing, deploying and using plugins and JavaBeans

Created a plugin, works in developer but not in smart clien

Postby Grimbert » Tue Jan 26, 2021 10:51 am

Hi,
I created a plugin for the first time, so I probably am missing something obvious.
It's a very simple plugin which returns a QR code and it works great in developer version 8.1.4.
When I try it on my live server (also 8.1.4) and start a smart client I get the following error:
Code: Select all
SEVERE: Error occured loading client plugin class com.fkplugins.QRcode.QRcode
java.lang.ClassNotFoundException: com.fkplugins.QRcode.QRcode
   at java.net.URLClassLoader.findClass(Unknown Source)
   at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at com.sun.jnlp.JNLPClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at java.lang.Class.forName0(Native Method)
   at java.lang.Class.forName(Unknown Source)
   at com.servoy.j2db.plugins.PluginManager.loadClientPlugins(PluginManager.java:409)
   at com.servoy.j2db.plugins.PluginManager.initClientPlugins(PluginManager.java:359)
   at com.servoy.j2db.smart.J2DBClient$13.run(J2DBClient.java:1173)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)


I have two class files in my package "com.fkplugins.QRcode", QRcode.java and QRcodeProvider.java

This is the code in the file "QRcode.java"
Code: Select all
package com.fkplugins.QRcode;

import java.beans.PropertyChangeEvent;
import java.net.URL;
import java.util.Properties;

import javax.swing.Icon;
import javax.swing.ImageIcon;

import com.servoy.j2db.plugins.IClientPlugin;
import com.servoy.j2db.plugins.IClientPluginAccess;
import com.servoy.j2db.plugins.PluginException;
import com.servoy.j2db.scripting.IScriptable;

public class QRcode implements IClientPlugin{

   
   
   @Override
   public Properties getProperties() {
      Properties props = new Properties();
      props.put(DISPLAY_NAME, getName());
      return props;
   }

   @Override
   public void load() throws PluginException {
      // TODO Auto-generated method stub
      
   }

   @Override
   public void unload() throws PluginException {
      //provider = null;
   }

   @Override
   public void propertyChange(PropertyChangeEvent evt) {
      // TODO Auto-generated method stub
      
   }

   @Override
   public IScriptable getScriptObject() {
      
      return QRcodeProvider.getInstance();
   }

   @Override
   public Icon getImage() {
      URL iconUrl = getClass().getResource("logo.png");
      if (iconUrl != null) {
         return new ImageIcon(iconUrl);
      } else {
         return null;
      }
   }

   @Override
   public String getName() {
      // TODO Auto-generated method stub
      return "QRcode";
   }

   @Override
   public void initialize(IClientPluginAccess arg0) throws PluginException {
      // TODO Auto-generated method stub
      
   }

}


And the code in "QRcodeProvider.java"
Code: Select all
package com.fkplugins.QRcode;

import com.servoy.j2db.documentation.ServoyDocumented;
import com.servoy.j2db.scripting.IReturnedTypesProvider;
import com.servoy.j2db.scripting.IScriptable;
import javax.imageio.ImageIO;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.client.j2se.MatrixToImageConfig;
import com.google.zxing.client.j2se.MatrixToImageWriter;

import org.mozilla.javascript.annotations.JSFunction;

import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;



@ServoyDocumented(publicName = QRcode.DISPLAY_NAME, scriptingName = "QR code plugin")
public class QRcodeProvider implements IScriptable, IReturnedTypesProvider {

   @Override
    public Class<?>[] getAllReturnedTypes() {
        return new Class[]{QRcodeProvider.class};
    }

   
    private static final QRcodeProvider instance = new QRcodeProvider();
   
   
   
    @JSFunction
    public static QRcodeProvider getInstance() {
        return instance;
    }

   
   
    /**
     * Generate a QR code byte array with your text and color as parameter
     *
     * @sample
     * var result = plugins.QRcode.generateQRCode('servoy.com');
     *
     * @param barcodeText
     * @param color
     * @return
     */
    @JSFunction
    public byte[] generateQRCode(String barcodeText, String color) {
       try {
          QRCodeWriter barcodeWriter = new QRCodeWriter();
           BitMatrix bitMatrix = null;
           bitMatrix = barcodeWriter.encode(barcodeText, BarcodeFormat.QR_CODE, 200, 200);
           MatrixToImageConfig conf = new MatrixToImageConfig(-16736285,-1);
           BufferedImage image = MatrixToImageWriter.toBufferedImage(bitMatrix, conf);
           ByteArrayOutputStream baos = new ByteArrayOutputStream();
           try {
            ImageIO.write(image, "jpg", baos);
         } catch (IOException e1) {
            // TODO Auto-generated catch block
         }
           byte[] bytes = baos.toByteArray();
           return bytes;
        }catch(Exception e) {
           return null;
        }
    }
}


I am currently at a loss at what is going wrong here, I hope anyone here can help me out.
User avatar
Grimbert
 
Posts: 20
Joined: Wed Apr 15, 2009 3:48 pm

Re: Created a plugin, works in developer but not in smart cl

Postby ptalbot » Tue Jan 26, 2021 11:05 pm

Did you add the jars for your com.google.zxing classes and any dependencies that these classes or yours might use?
Did you create a jnlp for Smart client to know to load these jars?
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1654
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: Created a plugin, works in developer but not in smart cl

Postby Grimbert » Wed Jan 27, 2021 10:28 am

Ah yes, I forgot to add this line :P
Code: Select all
<jar href="/plugins/QRcode.jar" download="%%loadmethod%%" version="%%version%%"/>

It now works, thanks!
User avatar
Grimbert
 
Posts: 20
Joined: Wed Apr 15, 2009 3:48 pm


Return to Plugins and Beans

Who is online

Users browsing this forum: No registered users and 6 guests