Spigot Minecraft plugin coding NoClassDefFound error mysql - java

When i start the server this error comes :
I am using IntelliJ Idea and MySQL jar is added to the src and in the project modules.
Error pastebin
Here is my code
package com.okaam.jaajhome;
import org.bukkit.plugin.java.JavaPlugin;
import pro.husk.mysql.MySQL;
import java.sql.Connection;
import java.sql.SQLException;
public class JaaJHome extends JavaPlugin {
static JaaJHome instance = null;
MySQL MySQL = new MySQL("address", "port", "schema", "user", "password", "");
static Connection c = null;
#Override
public void onEnable() {
System.out.println("Plugin JaaJHome active");
getCommand("sethome").setExecutor(new SetHomeExecutor());
getCommand("home").setExecutor(new HomeExecutor());
try {
c = MySQL.getConnection();
} catch (SQLException e) {
e.printStackTrace();
}
instance = this;
}
public static JaaJHome getInstance() {
return instance;
}
}

It seems like you're missing on some dependencies, make sure you have them either in the plugins folder as a non plugin or in the classpath to make sure they're loaded.

Related

How to use classes from one project on another project in java?

Basically I have two different projects, and I need to call some of these methods on class B from class A.
I've tried to make a jar of class B and to put it on the dependencies of class A, but it didn't work.
Is there a way to do this?
Edit:
Class B: Contains a FTP User utilities:
package br.com.consiste.FtpConnector;
import java.io.IOException;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
public class FTPConnection {
public FTPClient createConnection() {
String server = System.getenv("FTP_HOST");
String user = System.getenv("FTP_USER");
String pass = System.getenv("FTP_PASSWORD");
int port = 21;
FTPClient ftpClient = new FTPClient();
try {
ftpClient.connect(server, port);
showServerReply(ftpClient);
int replyCode = ftpClient.getReplyCode();
if (!FTPReply.isPositiveCompletion(replyCode)) {
System.out.println("Operation failed. Server reply code: " + replyCode);
}
boolean success = ftpClient.login(user, pass);
showServerReply(ftpClient);
if (!success) {
System.out.println("Could not login to the server");
} else {
System.out.println("LOGGED IN SERVER");
}
} catch (IOException ex) {
System.out.println("Oops! Something wrong happened");
ex.printStackTrace();
}
return ftpClient;
}
private static void showServerReply(FTPClient ftpClient) {
String[] replies = ftpClient.getReplyStrings();
if (replies != null && replies.length > 0) {
for (String aReply : replies) {
System.out.println("SERVER: " + aReply);
}
}
}
}
I have written these methods on other class of this same project.
Basically I want to call these methods, for example, FTPClient.getHost() or whatever, in class A.
To use a class of another project you can:
import the jar containing the class using a maven dependency
import the jar containing the class using a gradle dependency
import the jar containing the class adding it in the classpath manually
import the jar containing the class adding it to the existing classpath (for example the directory lib of tomcat) - Note that in this case you can't see the class from the ide, but only at runtime (it is how it works a jdbc driver for example, using the reflection)
Obviously you have to make a jar containg the class, and the class must have the right visibility modifiers.

MyObjectBox is red/not found but Java app still works

I'm trying to use ObjectBox in a simple java server side app.
Everything is working fine, I'm putting things in boxes etc, but the MyObjectBox class is always red when I use it.
I can see the generated .class and .java files, along with the meta _ classes, in build/classes/main/db (db is the package name I have in my actual code), but for some reason I can't import MyObjectBox.
Because of this, I also can't import the _ classes for use in Queries, which now kind of prevents me from getting any further.
My code to use objectBox is inside a class called DB which I have copied below, in case there's anything I'm doing wrong with that.
But as it actually works, I'm very confused!!
Thanks
UPDATE: if I run gradle clean build, my app runs fine, if I run Build->Build Project in intelliJ then I get the error
Error:(27, 21) java: cannot find symbol
symbol: variable MyObjectBox
location: class DB
.
package db;
import java.io.File;
import java.io.IOException;
import io.objectbox.Box;
import io.objectbox.BoxStore;
public class DB {
private File boxStoreDir;
private static BoxStore store;
public DB() {
try {
createMyObjectBox();
} catch (IOException e) {
e.printStackTrace();
}
}
private void createMyObjectBox() throws IOException {
File objectstorefile = new File("../objectBox/objectstorefile");
if(!objectstorefile.isDirectory()) {
objectstorefile.mkdirs();
}
boxStoreDir = objectstorefile;
if(store == null) {
store = MyObjectBox.builder().directory(boxStoreDir).build();
}
}
public<T> Box<T> getBox(Class<T> object) {
if(store == null) {
try {
createMyObjectBox();
} catch (IOException e) {
e.printStackTrace();
}
}
return store.boxFor(object);
}
}
Forget the apply plugin: 'net.ltgt.apt-idea' in build.gradle

DataSource without servlet not working - NoInitialContextException

This is the actual error I'm getting:
NoInitialContextException: Need to specify class name in environment or system property
I'm trying to have a datasource connection working on a project without servlet but just a main to launch.
This is the main class:
package pacchetto;
import java.sql.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class testIt {
public static void main(String[] args) throws SQLException, NamingException {
Context ctx = new InitialContext();
javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("java:comp/env/jdbc/datasource");
Connection con = ds.getConnection();
try {
con = ds.getConnection();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (con != null)
System.out.println("Connessione riuscita");
}
}
}
In the same project I also have a servlet file and using it everything works fine. This led me to thinking that the problem must be in this class and not in the servlet.xml or any other configuration file. Should I be wrong and should you need the whole scene I'll be happy to paste them here along with the main.
What am I doing wrong?

Error connecting to a share folder from java

I am working at an application in java which gets files from a share folder. For 2 days, i got same error trying to connect to the share folder. Until now, i didn't get this error. I dont know what is happened. Please help me.
My code:
package ScanPatch;
import java.util.TimerTask;
import Controllers.InterfataController;
import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbFile;
public class MyTask extends TimerTask{
public MyTask(){
}
#Override
public void run() {
//System.out.println("Hi see you after 10 seconds");
for(int i=0;i<InterfataController.getListaCheckbox().size();i++)
{
String path="smb://bcr-hqb-w0935/Oracle/Patchuri/" + InterfataController.getListaCheckbox().get(i).getText() +"/";
NtlmPasswordAuthentication userCred = new NtlmPasswordAuthentication("BCRWAN",
"Sebastian.burchidrag", "Parola952491");
SmbFile smbFile;
jcifs.Config.setProperty("jcifs.smb.client.disablePlainTextPasswords","false");
try {
smbFile = new SmbFile(path, userCred);
String [] patchuri=smbFile.list();
if(patchuri.length>1)
{
InterfataController.getListaCheckbox().get(i).setStyle("-fx-text-fill: red;");
}
else
{
InterfataController.getListaCheckbox().get(i).setStyle("-fx-text-fill: black;");
}
}catch(Exception e)
{
e.printStackTrace();
}
}
}
}
The error is : jcifs.smb.SmbException: 0xC000009A on String [] patchuri=smbFile.list(); this line.
The idea is that if a restart my computer, the application will work for the first connection, but only first time, then a i will get this error.

Using reflections with onejar plugin

I am using reflections with onejar maven plugin, and I have a problem when running the resulting jar:
20204 [main] ERROR org.reflections.Reflections - given scan urls are
empty. set urls in the configuration
It seems to me that reflections doesn't support the class loader that onejar is using. I've been using the following configuration of Reflections in my code:
Reflections reflections = new Reflections("path.to.my.package");
Any ideas? Thanks.
Yep a known issue. There is a work around...
Use Custom UrlType and custom Vfs.Dir; Uses OneJarURLConnection to correctly read content from embedded JARs; uses 'standard' Vfs.File.
Issue and solution discussed here : http://code.google.com/p/reflections/issues/detail?id=128
Source if you need it:
OneJarDir
package com.sdl.ws.integration.profserv.shared.onejar;
import com.simontuffs.onejar.OneJarURLConnection;
import org.reflections.vfs.Vfs;
import org.reflections.vfs.ZipDir;
import org.reflections.vfs.ZipFile;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
public class OneJarDir implements Vfs.Dir {
private JarFile oneJarFile = null;
private List<Vfs.File> oneJarClassFiles = new ArrayList<Vfs.File>();
private OneJarURLConnection oneJarConnection;
public OneJarDir(OneJarURLConnection oneJarConnection) {
this.oneJarConnection = oneJarConnection;
try {
this.oneJarConnection.connect();
this.oneJarFile = this.oneJarConnection.getJarFile();
Enumeration<JarEntry> entries = oneJarFile.entries();
while (entries.hasMoreElements()) {
oneJarClassFiles.add(new ZipFile(new ZipDir(oneJarFile), entries.nextElement()));
}
} catch (IOException e) {
throw new RuntimeException("Can't create One-Jar VFS directory", e);
}
}
public String getPath() {
return oneJarConnection.getURL().getPath();
}
public Iterable<Vfs.File> getFiles() {
return oneJarClassFiles;
}
public void close() {
try {
if (oneJarConnection != null)
oneJarConnection.getInputStream().close();
} catch (IOException e) {
throw new RuntimeException("Can't close VFS JAR stream", e);
}
}
}
OneJarUrlType
package com.sdl.ws.integration.profserv.shared.onejar;
import com.simontuffs.onejar.OneJarURLConnection;
import org.reflections.vfs.Vfs;
import java.io.IOException;
import java.net.URL;
public class OneJarUrlType implements Vfs.UrlType {
private static final String _JAR_DIR = "jar!";
public boolean matches(URL url) {
// check if "double-jarred' by one-jar; this would appear to conflict with the standard JAR loader, so it either needs to be first (which it is)
// OR the standard needs to be removed. This match assumes a nested JAR, unlike the standard JAR type.
String externalForm = url.toExternalForm();
// ugly, but should be much faster than regex.
int idx1 = externalForm.indexOf(_JAR_DIR);
return (idx1 > 0 && externalForm.indexOf(_JAR_DIR, idx1 + _JAR_DIR.length()) > 0);
}
public Vfs.Dir createDir(URL url) {
try {
return new OneJarDir(new OneJarURLConnection(url));
} catch (IOException e) {
throw new RuntimeException("Can't open One-Jar embedded JAR", e);
}
}
}

Categories

Resources