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.