I am using Intellij and Gradle. When I run the jar file -
trevor@trevor-Lenovo-YOGA-510-14AST:~/decent/Master5/out/artifacts/Master5_main_jar$ java -jar Master5.main.jar Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory at BlockgetConnection.(BlockgetConnection.java:12) at BlockgetAccount.getAccountByName(BlockgetAccount.java:31) at BlockgetStart.main(BlockgetStart.java:8) Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory at java.net.URLClassLoader.findClass(URLClassLoader.java:382) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 3 more
I am not explicitly logging and I assume in the Decent logic there is a need to log somehow. I included my build.gradle. I have included some dependencies for logging. Any idea about the solution?
Code (main class) -
import ch.decent.sdk.model.Account;
public class BlockgetStart {
public static void main(String[] args) {
BlockgetAccount anAccount = new BlockgetAccount();
Account myAcct = anAccount.getAccountByName("trevor3");
}
}
Instance of this class used -
import ch.decent.sdk.DCoreApi;
import ch.decent.sdk.crypto.Address;
import ch.decent.sdk.crypto.Credentials;
import ch.decent.sdk.model.Account;
import ch.decent.sdk.model.AssetAmount;
import ch.decent.sdk.model.Fee;
import ch.decent.sdk.model.TransactionConfirmation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
@Component
public class BlockgetAccount {
// connection to accounts
private static final Long AMOUNT_OF_DCT_REQUIRED_FOR_CREATION = 100000L;
@Autowired
private BlockgetConnection connectionExample;
@Autowired
private BlockgetLogin loginExample;
@Autowired
private BlockgetGenerateKeys generateKeys;
/**
* Example of getting any account by its name.
*
* @param accountName name of the account e.g. dw-account
* @return Account instance for given account name
*/
public Account getAccountByName(String accountName) {
connectionExample = new BlockgetConnection();
final DCoreApi dcoreApi = connectionExample.connect();
return dcoreApi
.getAccountApi()
.getByName(accountName)
.blockingGet();
}
/**
* Example of account creation with initial fee.
*
* @param newAccountName Unique account name that you wish to create.
* @return Confirmation about transaction
*/
public TransactionConfirmation createAccount(String newAccountName) {
final DCoreApi dcoreApi = connectionExample.connect();
final Credentials credentials = loginExample.login();
final Address newAccountPublicKey = generateKeys.generateKeys();
final AssetAmount dctAssetAmount = new AssetAmount(AMOUNT_OF_DCT_REQUIRED_FOR_CREATION);
final Fee initialFee = new Fee(dctAssetAmount.getAssetId(), AMOUNT_OF_DCT_REQUIRED_FOR_CREATION);
return dcoreApi.getAccountApi().create(
credentials,
newAccountName,
newAccountPublicKey,
initialFee
).blockingGet();
}
}
Build.gradle -
plugins {
id 'java'
}
group 'com.blockget.Master5'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
jar { manifest { attributes 'Main-Class': 'BlockgetStart' } }
allprojects {
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
dependencies {
// https://mvnrepository.com/artifact/org.springframework/spring-context
// https://mvnrepository.com/artifact/org.springframework/spring-context
compile group: 'org.springframework', name: 'spring-context', version: '5.1.8.RELEASE'
// https://mvnrepository.com/artifact/org.slf4j/slf4j-ap
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.26'
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl
compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.12.0'
testCompile group: 'junit', name: 'junit', version: '4.12'
implementation 'com.github.DECENTfoundation:DCoreKt-SDK:2.3.1'
}
I get this for the jar breakdown -
trevor@trevor-Lenovo-YOGA-510
14AST:~/decent/Master5/out/artifacts/Master5_main_jar$ jar tf
Master5.main.jar
META-INF/MANIFEST.MF
META-INF/
BlockgetNftMgr.class
BlockgetLogin.class
BlockgetConnection.class
BlockgetNft.class
BlockgetStart.class
BlockgetAccount.class
BlockgetGenerateKeys.class
Any ideas show to solve?
Top comments (0)