I am trying to run an example of how to use pkcs11 using the next code
import java.lang.reflect.Constructor;
import java.security.KeyStore;
import java.security.Provider;
import java.security.Security;
import java.util.Enumeration;
public class SignWithPKCS11
{
public static void main (String [] args)
{
try
{
Class<?> pkcs11Class = Class.forName("sun.security.pkcs11.SunPKCS11");
Constructor<?> construct = pkcs11Class.getConstructor(new Class[] {String.class});
String configName = "pkcs11.cfg";
Provider p = (Provider)construct.newInstance(new Object[] {configName});
Security.addProvider(p);
}
catch (Throwable t)
{
t.printStackTrace();
}
}
}
The code above, calls the file pkcs11.cfg. The content of it is
name = JSignPdf
library = /home/grados-sanchez/grive/E-CONNECTING/david/opensc-pkcs11.so
using this command
java -cp . SignWithPKCS11
java -Djava.library.path=".:/home/grados-sanchez/grive/E-CONNECTING/david" -cp . SignWithPKCS11
but I get
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at SignWithPKCS11.main(SignWithPKCS11.java:32)
Caused by: java.security.ProviderException: Initialization failed
at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:376)
at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:103)
Caused by: java.io.IOException: libopensc.so.6: cannot open shared object file: No such file or directory/home/grados-sanchez/grive/E-CONNECTING/david/opensc-pkcs11.so
Could you help me, to fix it, please? What is wrong?
NOTE: When I did:
ls -l /home/grados-sanchez/grive/E-CONNECTING/david/opensc-pkcs11.so
I get
-rw-rw-r-- 1 user user 220232 Jun 19 01:59 /home/grados-sanchez/grive/E-CONNECTING/david/opensc-pkcs11.so
It seems that it's not the opensc-pkcs11.so that is missing, but a dependency of that library. Use ldd to check those dependencies. If they reside in the same directory as the provider, you need to set LD_LIBRARY_PATH=/home/grados-sanchez/grive/E-CONNECTING/david before executing the command (as a prefix, for example).
Related
Please read the note below.
I am having a problem in my chatbot program. I already did all the instructions they said on the tutorials of different website about how to create a chatbot in java using aiml. I create a maven project. Add the Ab.jar file in the dependency, even in local repository but still I am having this error.
Exception in thread "main" java.lang.NoClassDefFoundError: org/alicebot/ab/MagicBooleans
at com.Chatbot.main(Chatbot.java:21)
Caused by: java.lang.ClassNotFoundException: org.alicebot.ab.MagicBooleans
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
This is the half of the code in Chatbot.java
import java.io.File;
import org.alicebot.ab.Bot;
import org.alicebot.ab.Chat;
import org.alicebot.ab.History;
import org.alicebot.ab.MagicBooleans;
import org.alicebot.ab.MagicStrings;
import org.alicebot.ab.utils.IOUtils;
public class Chatbot {
private static final boolean TRACE_MODE = false;
static String botName = "super";
public static void main(String[] args) {
try {
String resourcesPath = getResourcesPath();
System.out.println(resourcesPath);
MagicBooleans.trace_mode = TRACE_MODE;
Bot bot = new Bot("super", resourcesPath);
Chat chatSession = new Chat(bot);
bot.brain.nodeStats();
String textLine = "";
It seems that my jar file is not recognized or what. Im actually new to this. Response is a great help.
Note: I have already read some of the NoClassDefError question here in stackoverflow and do what they suggest but still the problem exist.
I am creating the orc file and adding row to the file. its working on linux. But its not working on the windows.writer.close() return NPE.
please find the code below and stack trace below and give me help on the same.
code:--
package com.testing;
import java.io.IOException;
import java.util.Arrays;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hive.ql.io.orc.OrcFile;
import org.apache.hadoop.hive.ql.io.orc.OrcFile.WriterOptions;
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo;
import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils;
import org.apache.hadoop.hive.ql.io.orc.OrcFile;
import org.apache.hadoop.hive.ql.io.orc.OrcFile.WriterOptions;
import org.apache.hadoop.hive.ql.io.orc.Writer;
public class Typical {
public static void main(String args[]){
String filePath ="C:/usr/tmp/EDMS_FILE_ARCHIVE_.orc";
TypeInfo typeInfo=TypeInfoUtils.getTypeInfoFromTypeString("struct<a:string>");
ObjectInspector inspector=TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(typeInfo);
WriterOptions options=OrcFile.writerOptions(new Configuration()).inspector(inspector);
//Path path=new Path(temporaryFolder.getRoot().getCanonicalPath(),"part-00000");
Writer writer;
try {
writer = OrcFile.createWriter(new Path(filePath),options);
writer.addRow(Arrays.asList("hello"));
writer.close();
} catch (IllegalArgumentException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
statcktrace:--
Exception in thread "main" java.lang.NullPointerException
at java.lang.ProcessBuilder.start(Unknown Source)
at org.apache.hadoop.util.Shell.runCommand(Shell.java:482)
at org.apache.hadoop.util.Shell.run(Shell.java:455)
at org.apache.hadoop.util.Shell$ShellCommandExecutor.execute(Shell.java:715)
at org.apache.hadoop.util.Shell.execCommand(Shell.java:808)
at org.apache.hadoop.util.Shell.execCommand(Shell.java:791)
at org.apache.hadoop.fs.RawLocalFileSystem.setPermission(RawLocalFileSystem.java:656)
at org.apache.hadoop.fs.FilterFileSystem.setPermission(FilterFileSystem.java:490)
at org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:462)
at org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:428)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:908)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:889)
at org.apache.hadoop.hive.ql.io.orc.WriterImpl.getStream(WriterImpl.java:1967)
at org.apache.hadoop.hive.ql.io.orc.WriterImpl.flushStripe(WriterImpl.java:1984)
at org.apache.hadoop.hive.ql.io.orc.WriterImpl.close(WriterImpl.java:2289)
at com.testing.Typical.main(Typical.java:30)
Advance Thanks
Hanuman
Its an issue with using orc library on windows and writing to local file:
java.lang.NullPointerException
at java.lang.ProcessBuilder.start(Unknown Source)
Program wants to execute chmod command but its not present on windows - here you get the NPE.
I found workaround which i don't like:
dowload winutils.exe
System.setProperty("hadoop.home.dir", "c:\path\to\winutils"); the real path to wintutils libs should be c:\path\to\winutils\bin
I'm trying to code a program that will trade stocks in a sandbox environment with the E*Trade API. I am using their sample code as a guideline and currently am getting an issue with the .getAuthorizeURL() method. It says that it is undefined for type String however, after decompiling the OAuth jar I am stuck in a rut about how to solve this issue.
import com.etrade.etws.account.Account;
import com.etrade.etws.account.AccountListResponse;
import com.etrade.etws.oauth.sdk.client.IOAuthClient;
import com.etrade.etws.oauth.sdk.client.OAuthClientImpl;
import com.etrade.etws.oauth.sdk.common.Token;
import com.etrade.etws.sdk.client.ClientRequest;
import com.etrade.etws.sdk.client.Environment;
import com.etrade.etws.sdk.common.ETWSException;
import com.etrade.*;
import java.awt.Desktop;
import java.net.URI;
import java.*;
import java.io.IOException;
public class OAuth
{
public static void main(String[] args) throws IOException, ETWSException
{
//Variables
IOAuthClient client = null;
ClientRequest request = null;
Token token = null;
String oauth_consumer_key = null; // Your consumer key
String oauth_consumer_secret = null; // Your consumer secret
String oauth_request_token = null; // Request token
String oauth_request_token_secret = null; // Request token secret
client = OAuthClientImpl.getInstance(); // Instantiate IOAUthClient
request = new ClientRequest(); // Instantiate ClientRequest
request.setEnv(Environment.SANDBOX); // Use sandbox environment
request.setConsumerKey(oauth_consumer_key); //Set consumer key
request.setConsumerSecret(oauth_consumer_secret);
token = client.getRequestToken(request); // Get request-token object
oauth_request_token = token.getToken(); // Get token string
oauth_request_token_secret = token.getSecret(); // Get token secret
}
public String Verification(String client, ClientRequest request)
{
String authorizeURL = null;
authorizeURL = client.getAuthorizeUrl(request); // E*TRADE authorization URL
URI uri = new java.net.URI(authorizeURL);
Desktop desktop = Desktop.getDesktop();
desktop.browse(uri);
return authorizeURL;
}
}
Stack Trace
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at com.etrade.etws.oauth.sdk.client.OAuthClientImpl.<init>(OAuthClientImpl.java:22)
at com.etrade.etws.oauth.sdk.client.OAuthClientImpl.<clinit>(OAuthClientImpl.java:24)
at OAuth.main(OAuth.java:29)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 3 more
You need to configure your build path to include the Apache log4j logger (org/apache/log4j/Logger) in your external JARs. It's use is buried down in the ETRADE code.
What are you editing your code in? It should be easy to find instructions for your development environment. APACHE is free and you can download the JAR here: http://logging.apache.org/log4j/2.x/
Note the requirement from ETRADE (https://us.etrade.com/ctnt/dev-portal/getContent?contentUri=V0_Code-Tutorialhttps://us.etrade.com/ctnt/dev-portal/getContent?contentUri=V0_Code-Tutorial):
Java SDK
To proceed with this tutorial, you must first have completed the installation of the E*TRADE Java SDK, including:
•Java 1.6 or later installed
•3rd-party jars installed
•E*TRADE Java SDK libraries in your CLASSPATH
You can get instructions for all of the jars here https://us.etrade.com/ctnt/dev-portal/getContent?contentUri=V0_Code-SDKGuides-Java
If you were using Eclipse IDE, for example, you can follow these instructions How to import a jar in Eclipse
I am new to Cassandra and i am trying to create a column and super-column family with the below program in Eclipse:
import java.util.Arrays;
import java.util.List;
import me.prettyprint.cassandra.model.BasicColumnDefinition;
import me.prettyprint.cassandra.model.BasicColumnFamilyDefinition;
import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.cassandra.service.ThriftCfDef;
import me.prettyprint.hector.api.Cluster;
import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition;
import me.prettyprint.hector.api.ddl.ColumnIndexType;
import me.prettyprint.hector.api.ddl.ColumnType;
import me.prettyprint.hector.api.ddl.ComparatorType;
import me.prettyprint.hector.api.ddl.KeyspaceDefinition;
import me.prettyprint.hector.api.exceptions.HectorException;
import me.prettyprint.hector.api.factory.HFactory;
public class HectorTutorial {
private static final String TEST_KEYSPACE = "TestKeyspace";
private static final String TEST_CF= "TestColumnFamily";
private static final String TEST_SUPER= "TestSuperColumn";
private static StringSerializer stringSerializer = StringSerializer.get();
public static void main(String[] args) throws Exception {
Cluster cluster = HFactory.getOrCreateCluster("TestCluster", "localhost:9160");
try {
if ( cluster.describeKeyspace(TEST_KEYSPACE ) != null ) {
cluster.dropKeyspace(TEST_KEYSPACE );
}
BasicColumnDefinition columnDefinition = new BasicColumnDefinition();
columnDefinition.setName(stringSerializer.toByteBuffer("TestColumn"));
columnDefinition.setIndexName("TestColumn_idx ");
columnDefinition.setIndexType(ColumnIndexType.KEYS);
columnDefinition.setValidationClass(ComparatorType.LONGTYPE.getClassName());
BasicColumnFamilyDefinition columnFamilyDefinition = new BasicColumnFamilyDefinition();
columnFamilyDefinition.setKeyspaceName(TEST_KEYSPACE );
columnFamilyDefinition.setName(TEST_CF);
columnFamilyDefinition.addColumnDefinition(columnDefinition);
BasicColumnFamilyDefinition superCfDefinition = new BasicColumnFamilyDefinition();
superCfDefinition.setKeyspaceName(TEST_KEYSPACE );
superCfDefinition.setName(TEST_SUPER);
superCfDefinition.setColumnType(ColumnType.SUPER);
ColumnFamilyDefinition cfDefStandard = new ThriftCfDef(columnFamilyDefinition);
ColumnFamilyDefinition cfDefSuper = new ThriftCfDef(superCfDefinition);
KeyspaceDefinition keyspaceDefinition =
HFactory.createKeyspaceDefinition(TEST_KEYSPACE , "org.apache.cassandra.locator.SimpleStrategy",
1, Arrays.asList(cfDefStandard, cfDefSuper));
cluster.addKeyspace(keyspaceDefinition);
/* Below Code show your Keyspace Schema */
List<KeyspaceDefinition> keyspaces = cluster.describeKeyspaces();
for (KeyspaceDefinition kd : keyspaces) {
if ( kd.getName().equals(TEST_KEYSPACE ) ) {
System.out.println("Name: " +kd.getName());
System.out.println("RF: " +kd.getReplicationFactor());
System.out.println("strategy class: " +kd.getStrategyClass());
List<ColumnFamilyDefinition> cfDefs = kd.getCfDefs();
for (ColumnFamilyDefinition def : cfDefs) {
System.out.println(" CF Type: " +def.getColumnType());
System.out.println(" CF Name: " +def.getName());
System.out.println(" CF Metadata: " +def.getColumnMetadata());
}
}
}
} catch (HectorException he) {
he.printStackTrace();
}
cluster.getConnectionManager().shutdown();
}
}
When I try to execute the program I get the following exception:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/thrift/transport/TTransportException
at me.prettyprint.cassandra.connection.factory.HThriftClientFactoryImpl.createClient(HThriftClientFactoryImpl.java:28)
at me.prettyprint.cassandra.connection.ConcurrentHClientPool.createClient(ConcurrentHClientPool.java:147)
at me.prettyprint.cassandra.connection.ConcurrentHClientPool.<init>(ConcurrentHClientPool.java:53)
at me.prettyprint.cassandra.connection.RoundRobinBalancingPolicy.createConnection(RoundRobinBalancingPolicy.java:67)
at me.prettyprint.cassandra.connection.HConnectionManager.<init>(HConnectionManager.java:67)
at me.prettyprint.cassandra.service.AbstractCluster.<init>(AbstractCluster.java:67)
at me.prettyprint.cassandra.service.ThriftCluster.<init>(ThriftCluster.java:21)
at me.prettyprint.hector.api.factory.HFactory.createCluster(HFactory.java:197)
at me.prettyprint.hector.api.factory.HFactory.getOrCreateCluster(HFactory.java:144)
at me.prettyprint.hector.api.factory.HFactory.getOrCreateCluster(HFactory.java:133)
at HectorTutorial.main(HectorTutorial.java:27)
Caused by: java.lang.ClassNotFoundException: org.apache.thrift.transport.TTransportException
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
I have included all the Hector api jars in the classpath and I do not know what is causing this error. Can someone please explain the reason for the error?
It seems you're missing some 3rd party libraries (in this case, Thrift which I believe contains the TTransportException class). Add all required libraries to your classpath too, and let's see if that helps.
Check your "Run/Debug Configurations" under settings.
Ascertain the name of the "main class" you are using. Click to select the name of your current class. Apply. Ok.
I am trying to run Spring via Daemon service as stand alone application ofcourse.
I have configured run.sh script and added to it all Spring jars framework.
Now i am trying to execute my starting point class from the Daemon classes this way:
Code:
public class FeedDaemon implements Daemon
{
public FeedDaemon()
{
}
protected final static Logger log = LoggerFactory.getLogger(FeedDaemon.class);
protected boolean shouldBeRunning = false;
protected ProviderFactory runner = null;
#Override
public void destroy()
{
runner = null;
}
#Override
public void init(DaemonContext arg0) throws Exception
{
runner = new ProviderFactory();
}
public void start() throws RuntimeError, ConfigError
{
log.info("Starting daemon");
runner.start();
}
public void stop() throws Exception
{
log.info("Starting Shutting daemon ...");
runner.stop();
}
}
Code:
package com.spring.test;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.spring.aspect.Spring3HelloWorld;
import com.spring.beans.ParkingCar.CarBean;
import com.spring.beans.ParkingCar.CarMaker;
import com.spring.beans.ParkingCar.FourWheelsVechile;
import com.spring.beans.ParkingCar.TwoWheelsVechile;
import com.spring.beans.ParkingCar.Vechile;
import com.spring.beans.ParkingCar.VechileDetails;
import com.spring.beans.calculator.CalculateNumbersHolderBean;
import com.spring.beans.calculator.CalculateStrategyBean;
import com.spring.beans.calculator.CalculatorBean;
public class Spring3HelloWorldTest
{
static Logger logger = Logger.getLogger(Spring3HelloWorldTest.class);
public static void execute()
{
try
{
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
logger.debug("3");
Vechile fourWheelsVechile = (FourWheelsVechile) context.getBean("Ambulance");
fourWheelsVechile.drive();
CarMaker carMaker = (CarMaker) context.getBean("carMaker");
CarBean carBean = carMaker.createNewCar();
carBean.driveCar();
}
catch (Throwable e)
{
logger.error(e);
}
}
}
And I get this error:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.commons.daemon.support.DaemonLoader.load(DaemonLoader.java:164)
Caused by: java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext
at com.spring.runner.FeedDaemon.init(FeedDaemon.java:37)
... 5 more
Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContext
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 6 more
Cannot load daemon
Service exit with a return value of 3
thats my run.sh script:
export JAVA_HOME=/../
FIXGW=/../FIXGW
CLASSPATH=$FIXGW/lib/FeedHandler.jar:$FIXGW/lib/FixSpring.jar:$FIXGW/lib/org.springframework.web-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.web.struts-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.web.servlet-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.web.portlet-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.test-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.orm-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.jms-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.jdbc-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.context.support-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.aspects-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.transaction-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.oxm-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.instrument-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.instrument.tomcat-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.expression-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.core-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.context-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.beans-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.asm-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.aop-sources-3.1.1.RELEASE.jar:$FIXGW/lib/commons-daemon-1.0.3.jar
cd $FIXGW
/../jsvc -user fox \
-XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:SurvivorRatio=16 \
-Dlog4j.configuration=file:$FIXGW/conf/log4j.properties \
-outfile /dev/null \
-errfile $FIXGW/logs/error.log \
-verbose -classpath $CLASSPATH \
com.spring.runner.FeedDaemon
Any idea?
thanks,
ray.
You seem to have added all the jars containing the Spring java source (uncompiled code). You should instead add the jars not named ...-sources... to the class path.
spring jars are not in classpath. Check this my answer. Add all libraries in classpath via command line(ofcourse in your shell script).
Well I see your problem now. You have source files in classpath. Those are mentioned as org.springframework.web.servlet-sources-3.1.1.RELEASE.jar while compiled jars are mentioned as org.springframework.web.servlet-3.1.1.RELEASE.jar