I am trying to load an ontology saved on my PC. The file format is .n3.
After a lot of work and searching for the possible solutions, I didn't find an appropriate way to load an ontology.
I tried the following code:
import edu.stanford.smi.protegex.owl.ProtegeOWL;
import edu.stanford.smi.protegex.owl.model.OWLModel;
public class Extractor {
public static void main(String[] args) {
String ontologyURI = "file:///C:/acco.n3";
try {
OWLModel owlModel = ProtegeOWL.createJenaOWLModelFromURI(ontologyURI);
System.out.println("Worked");
}catch (Exception exception) {
System.out.println("Error can't upload the ontologie ");
}
}
}
but it always gives me this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at com.hp.hpl.jena.graph.Node.<clinit>(Node.java:35)
at com.hp.hpl.jena.rdf.model.impl.ResourceImpl.fresh(ResourceImpl.java:108)
at com.hp.hpl.jena.rdf.model.impl.ResourceImpl.<init>(ResourceImpl.java:68)
at com.hp.hpl.jena.rdf.model.ResourceFactory$Impl.createResource(ResourceFactory.java:176)
at com.hp.hpl.jena.rdf.model.ResourceFactory.createResource(ResourceFactory.java:69)
at com.hp.hpl.jena.vocabulary.RDF.resource(RDF.java:29)
at com.hp.hpl.jena.vocabulary.RDF.<clinit>(RDF.java:37)
at com.hp.hpl.jena.datatypes.xsd.impl.XMLLiteralType.<clinit>(XMLLiteralType.java:30)
at com.hp.hpl.jena.datatypes.TypeMapper.<clinit>(TypeMapper.java:52)
at edu.stanford.smi.protegex.owl.model.impl.OWLSystemFrames.createRDFSDatatypes(Unknown Source)
at edu.stanford.smi.protegex.owl.model.impl.OWLSystemFrames.createOWLInstances(Unknown Source)
at edu.stanford.smi.protegex.owl.model.impl.OWLSystemFrames.createOWLMetaModel(Unknown Source)
at edu.stanford.smi.protegex.owl.model.impl.OWLSystemFrames.<init>(Unknown Source)
at edu.stanford.smi.protegex.owl.swrl.SWRLSystemFrames.<init>(Unknown Source)
at edu.stanford.smi.protegex.owl.model.impl.AbstractOWLModel.createSystemFrames(Unknown Source)
at edu.stanford.smi.protegex.owl.model.impl.AbstractOWLModel.createSystemFrames(Unknown Source)
at edu.stanford.smi.protege.model.DefaultKnowledgeBase.<init>(DefaultKnowledgeBase.java:79)
at edu.stanford.smi.protegex.owl.model.impl.AbstractOWLModel.<init>(Unknown Source)
at edu.stanford.smi.protegex.owl.jena.JenaOWLModel.<init>(Unknown Source)
at edu.stanford.smi.protegex.owl.jena.JenaKnowledgeBaseFactory.createKnowledgeBase(Unknown Source)
at edu.stanford.smi.protege.model.Project.createDomainKB(Project.java:429)
at edu.stanford.smi.protege.model.Project.createDomainKnowledgeBase(Project.java:447)
at edu.stanford.smi.protegex.owl.jena.creator.OwlProjectFromUriCreator.create(Unknown Source)
at edu.stanford.smi.protegex.owl.ProtegeOWL.createJenaOWLModelFromURI(Unknown Source)
at Extractor.main(Extractor.java:28)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
... 25 more
I need your help in solving this error, or perhaps find a way to load ontologies to extract knowledge from them.
Thanks in advance.
Update:
I added the missing dependencies to the class path as #Roddy of the Frozen Peas suggested.
but it gives me the following error:
WARNING: [Local Folder Repository] The specified file must be a directory. (C:\eclipse-workspace\NewEx\plugins\edu.stanford.smi.protegex.owl) -- LocalFolderRepository.update()
Exception in thread "main" java.lang.NoClassDefFoundError: org/protege/editor/owl/model/hierarchy/roots/Relation
at edu.stanford.smi.protegex.owl.jena.parser.TripleProcessor.<init>(Unknown Source)
at edu.stanford.smi.protegex.owl.jena.parser.GlobalParserCache.getTripleProcessor(Unknown Source)
at edu.stanford.smi.protegex.owl.jena.parser.ProtegeOWLParser.loadTriples(Unknown Source)
at edu.stanford.smi.protegex.owl.jena.parser.ProtegeOWLParser.run(Unknown Source)
at edu.stanford.smi.protegex.owl.jena.JenaKnowledgeBaseFactory.loadKnowledgeBase(Unknown Source)
at edu.stanford.smi.protege.model.Project.loadDomainKB(Project.java:1346)
at edu.stanford.smi.protege.model.Project.createDomainKnowledgeBase(Project.java:456)
at edu.stanford.smi.protegex.owl.jena.creator.OwlProjectFromUriCreator.create(Unknown Source)
at edu.stanford.smi.protegex.owl.ProtegeOWL.createJenaOWLModelFromURI(Unknown Source)
at Extractor.main(Extractor.java:10)
Caused by: java.lang.ClassNotFoundException: org.protege.editor.owl.model.hierarchy.roots.Relation
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
... 10 more
any suggestions please?
java.lang.ClassNotFoundException: org.protege.editor.owl.model.hierarchy.roots.Relation
There are other dependencies you need. Rather than going piecemeal, you should use a build system that can resolve the dependency closure for you, such as Maven, Gradle or similar.
The problem here is not Protege specific or ontology related, it's just plain Java libraries missing from the classpath.
Note that your code does not use OWL API. These classes are Jena classes and Protege classes (from Protege 3.x, I'd think). Note that Protege 3.x is a very dated API. Consider using a newer version (5.2.0 or newer), or directly using the actual OWL API. See https://github.com/owlcs/owlapi/wiki/Documentation
OWL API also has zip files containing all dependencies, which might simplify your work (Maven is still better than resolving dependencies by hand). See https://github.com/owlcs/releases/tree/master/owlapi/5
Related
I am trying to connect Ms Access database with java 8 version. But as in this version jdbcodbcbridge driver has been removed, so following jar files need to be included :
**ucanaccess-x.x.x.jar
HSQLDB (hsqldb.jar, version 2.2.5 or newer)
,Jackcess (jackcess-2.x.x.jar)
,commons-lang (commons-lang-2.6.jar, or newer 2.x version)
,commons-logging (commons-logging-1.1.1.jar, or newer 1.x version)**
I have bought all these jar files in my eclipse through Build Path option.
But still when i am executing the following code it is coming up with error as:
Exception in thread "main" java.lang.NoClassDefFoundError:
com/healthmarketscience/jackcess/util/ErrorHandler at java.lang.Class.forName0(Native Method) at
java.lang.Class.forName(Unknown Source) at
demo.JDBCDemo.main(JDBCDemo.java:11) Caused by:
java.lang.ClassNotFoundException:
com.healthmarketscience.jackcess.util.ErrorHandler at
java.net.URLClassLoader.findClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) ... 3 more
And my code is:
import java.sql.*;
import java.util.*;
import com.healthmarketscience.jackcess.util.ErrorHandler;
public class JDBCDemo {
public static void main(String args[]) throws Exception
{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection con=DriverManager.getConnection("jdbc:ucanaccess://C:\\Users\\isha\\Desktop\\StudentData.accdb");
Statement stmt=con.createStatement();
String str="insert into NameData values(4,'ram')";
stmt.executeUpdate(str);
String s="select * from NameData";
ResultSet res=stmt.executeQuery(s);
while(res.next()){
System.out.println(res.getString(1)+":"+res.getString(2));
Enumeration e=DriverManager.getDrivers();
while(e.hasMoreElements()){
Driver d=(Driver)e.nextElement();
System.out.println(d.getClass().getName());
}
}
}
}
You have an old obsolete version of jackcess in your classpath. Please add to your classpath ucanaccess.jar the jars in the folder lib of the specific ucanaccess distribution you're using.
String str="insert into NameData values(4,'ram')";
in which columns you insert this values?
I am trying to access an eXist xml db using the embedded method, as described here.
That page has a list of jars needed for the classpath, and I have all of them there, but I keep getting this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/ws/commons/serialize/DOMSerializer
Here's what I have in my classpath; I'm using eclipse:
antlr-2.7.7.jar
commons-collections-3.2.1.jar
commons-logging-1.1.1.jar
commons-pool-1.6.jar
exist-modules.jar
exist-optional.jar
exist.jar
jta-1.1.jar
log4j-1.2.17.jar
pkg-repo.jar
quartz-2.1.6.jar
slf4j-api-1.7.2.jar
slf4j-log4j12-1.7.2.jar
sunxacml-1.2.jar
xmldb.jar
xmlrpc-client-3.1.3.jar
xmlrpc-common-3.1.3.jar
xmlrpc-server-3.1.3.jar
saxonhe-9.4.0.7.jar
serializer-2.7.1.jar
xalan-2.7.1.jar
xercesImpl-2.11.0.jar
xml-apis-1.4.01.jar
xml-resolver-1.2.jar
Here is the relevant code:
System.out.println("trying to call class.forname on " + DRIVER);
Class cl = Class.forName(DRIVER);
System.out.println("creating db instance");
Database database = (Database) cl.newInstance();
database.setProperty("create-database", "true");
System.out.println("register database");
DatabaseManager.registerDatabase(database);
System.out.println("getting collection: " + URI + collectionName);
Collection collection = DatabaseManager.getCollection(URI + collectionName);
//collection.setProperty(OutputKeys.INDENT, "yes");
//System.out.println("getting resource");
//XMLResource xmlRes = (XMLResource)collection.getResource(resourceName);
and here is the console output including the error:
******************************************************
reading a doc from xml db
******************************************************
reading doc...
trying to call class.forname on org.exist.xmldb.DatabaseImpl
creating db instance
register database
getting collection: xmldb:exist://localhost:8080/exist/xmlrpc/db/test-journal
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/ws/commons/serialize/DOMSerializer
at org.apache.xmlrpc.serializer.NodeSerializer.<clinit>(NodeSerializer.java:30)
at org.apache.xmlrpc.common.TypeFactoryImpl.<clinit>(TypeFactoryImpl.java:88)
at org.apache.xmlrpc.common.XmlRpcController.<init>(XmlRpcController.java:31)
at org.apache.xmlrpc.client.XmlRpcClient.<init>(XmlRpcClient.java:51)
at org.exist.xmldb.DatabaseImpl.getRpcClient(DatabaseImpl.java:324)
at org.exist.xmldb.DatabaseImpl.getRemoteCollection(DatabaseImpl.java:240)
at org.exist.xmldb.DatabaseImpl.getCollection(DatabaseImpl.java:164)
at org.exist.xmldb.DatabaseImpl.getCollection(DatabaseImpl.java:153)
at org.xmldb.api.DatabaseManager.getCollection(Unknown Source)
at org.xmldb.api.DatabaseManager.getCollection(Unknown Source)
at com.jasonwardenburg.codetest.exist.ExistDBFileReader.readDoc(ExistDBFileReader.java:48)
at com.jasonwardenburg.codetest.exist.ExistDBFileReader.main(ExistDBFileReader.java:27)
Caused by: java.lang.ClassNotFoundException: org.apache.ws.commons.serialize.DOMSerializer
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 12 more
I went to the apache xml-rpc page, but most of the mirror sites are not functioning...anyone have any ideas as to the best way to get this working?
thanks!
You are missing ws-commons-util-1.0.2.jar from $EXIST_HOME/lib/core.
I guess the documentation has become out of date. You should make sure you have included at least all of the libraries from $EXIST_HOME/lib/core.
According to the dependencies tree for xmlrpc, you're missing ws-commons-util.jar, which is one of its runtime dependencies, if you're not using maven, you can download the jar from the central repository, here, then include it in your classpath. On the other hand, be wary! existDB docs are very specific about the fact that some of its features might not work if you don't include Xerces, Xalan and Saxon as endorsed libraries, since you're Java release might have the wrong versions. good luck.
I am using the Apertium Translator and using the sample code they provide. My code is like this.
import com.robtheis.aptr.language.Language;
import com.robtheis.aptr.translate.Translate;
public class Test {
public static void main(String[] args) throws Exception {
// Set the Apertium API Key - Get yours at http://api.apertium.org/register.jsp
Translate.setKey("BNSCFhEL8DoTApc2I1+aa3UYkVg");
String translatedText = Translate.execute("Hola, mundo!", Language.SPANISH, Language.ENGLISH);
System.out.println(translatedText);
}
}
I have no errors or warnings and when I run the program I get the following errors.
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/simple/JSONValue
at com.robtheis.aptr.ApertiumTranslatorAPI.jsonSubObjToString(ApertiumTranslatorAPI.java:195)
at com.robtheis.aptr.ApertiumTranslatorAPI.retrieveSubObjString(ApertiumTranslatorAPI.java:140)
at com.robtheis.aptr.translate.Translate.execute(Translate.java:56)
at maple.Test.main(Test.java:11)
Caused by: java.lang.ClassNotFoundException: org.json.simple.JSONValue
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 4 more
The .jar I'm using is the second one from https://github.com/rmtheis/apertium-translator-java-api/downloads
You have to download the first one. The first jar file (apertium-translator-java-api-0.2-jar-with-dependencies.jar) contains the all dependencies needed..
Or you add a json library to your project path..
Well JVM is not able to find some class at Runtime which was available at compile time. That is the reason of NoClassDefFoundError
Below you also have ClassNotFoundException for this class org.json.simple.JSONValue
which means you are trying to load the particular class at run-time by name.
Both of them related to Java Class Path.
I don't know alot about jSON stuff. But you are missing this file org.json.simple.JSONValue you can take it from here http://code.google.com/p/json-simple/
add the above jar file in your class path . And the code will definitely run. Guaranteed.!!!
Thanks
Update:
Now I found out something very strange, it works when i put the compiled test classes directly
into the "super-csv-dozer-2.1.0.jar" with the same structure as in the svn repo.
But as soon as i use my own package it wont work. I always used the entire path
like this: myPackage.csv.SurveyResponse.class
What am i missing? and why does it work in a normal Java Project but not in a Play Project?
I also tried it outside of eclipse in a different directory and dont have any checkouts from
the svn repo that could confuse the paths. Another thing i tried is to put the Writing.class into adifferent package but didnt help.
Original qustion:
Im trying to use SuperCSV with Dozer in a Play Project.
The official supercsv sample works fine in a separate Java Project.
But when I put the code and the needed SuperCSV Jars in a freshly created Play project I always
get a ClassNotfoundException for SurveyResponse.class in this line of code:
beanWriter.configureBeanMapping(myPackage.csv.SurveyResponse.class, FIELD_MAPPING);
Here a screenshot of my project structure:
http://oi44.tinypic.com/mrqp7s.jpg
I made sure that all the JARS are available, I put them unmanaged into the /lib folder,
they are available in eclipse and no errors appear during compilation.
I debugged the code and the SurveyResponse.class is found and the beanWriter is initialized.
So somehow Play must do some magic in the background to trigger this bug.
What could play be doing in the background to possibly trigger such odd behavior?
What could I try to do to fix this?
Changes I made to the sample so it works with Play:
I used exactly the same code as the offical supercsv example.
The only change i did is remove the Writing.main(..) method and set the methods Writing.writeWithDozerCsvBeanWriter()
and Writing.partialWriteWithCsvDozerBeanWriter() to public,so it can be accessed from the Application controller.
And of course I changed the package name in all classes to package myPackage.test;
Links to sample:
See in the comment, i cant add more than 2 links because of low reputation.
Controller:
public class Application extends Controller {
public static Result index() throws Exception {
Writing.writeWithDozerCsvBeanWriter();
Writing.partialWriteWithCsvDozerBeanWriter();
return ok(index.render("Your new application is ready."));
}
}
Code that triggers error in Writing class:
ICsvDozerBeanWriter beanWriter = null;
try {
beanWriter = new CsvDozerBeanWriter(new FileWriter("target/writeWithCsvDozerBeanWriter.csv"),
CsvPreference.STANDARD_PREFERENCE);
// configure the mapping from the fields to the CSV columns
//Here the exception occures:
beanWriter.configureBeanMapping(myPackage.csv.SurveyResponse.class, FIELD_MAPPING);
Stack trace:
play.api.Application$$anon$1: Execution exception[[MappingException: java.lang.ClassNotFoundException: myPackage.test.SurveyResponse]]
at play.api.Application$class.handleError(Application.scala:289) ~[play_2.10.jar:2.1.1]
at play.api.DefaultApplication.handleError(Application.scala:383) [play_2.10.jar:2.1.1]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anon$2$$anonfun$handle$1.apply(PlayDefaultUpstreamHandler.scala:144) [play_2.10.jar:2.1.1]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anon$2$$anonfun$handle$1.apply(PlayDefaultUpstreamHandler.scala:140) [play_2.10.jar:2.1.1]
at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.1]
at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.1]
at play.api.libs.concurrent.PlayPromise$$anonfun$extend$1$$anonfun$apply$1.apply(Promise.scala:104) [play_2.10.jar:2.1.1]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) [scala-library.jar:na]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) [scala-library.jar:na]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) [na:1.6.0_37]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.6.0_37]
at java.lang.Thread.run(Unknown Source) [na:1.6.0_37]
org.dozer.MappingException: java.lang.ClassNotFoundException: myPackage.test.SurveyResponse
at org.dozer.util.MappingUtils.throwMappingException(MappingUtils.java:82) ~[dozer-5.4.0.jar:na]
at org.dozer.util.DefaultClassLoader.loadClass(DefaultClassLoader.java:38) ~[dozer-5.4.0.jar:na]
at org.dozer.util.MappingUtils.loadClass(MappingUtils.java:224) ~[dozer-5.4.0.jar:na]
at org.dozer.loader.DozerBuilder$MappingBuilder.classA(DozerBuilder.java:129) ~[dozer-5.4.0.jar:na]
at org.dozer.loader.api.BeanMappingBuilder.mapping(BeanMappingBuilder.java:72) ~[dozer-5.4.0.jar:na]
at org.dozer.loader.api.BeanMappingBuilder.mapping(BeanMappingBuilder.java:67) ~[dozer-5.4.0.jar:na]
at org.supercsv.io.dozer.CsvDozerBeanWriter$MappingBuilder.configure(CsvDozerBeanWriter.java:178) ~[super-csv-dozer-2.1.0.jar:na]
at org.dozer.loader.api.BeanMappingBuilder.build(BeanMappingBuilder.java:42) ~[dozer-5.4.0.jar:na]
at org.dozer.DozerBeanMapper.addMapping(DozerBeanMapper.java:258) ~[dozer-5.4.0.jar:na]
at org.supercsv.io.dozer.CsvDozerBeanWriter.configureBeanMapping(CsvDozerBeanWriter.java:91) ~[super-csv-dozer-2.1.0.jar:na]
at myPackage.test.Writing.writeWithDozerCsvBeanWriter(Writing.java:88) ~[na:na]
at controllers.Application.index(Application.java:12) ~[na:na]
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$1$$anonfun$apply$1.apply(routes_routing.scala:49) ~[na:na]
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$1$$anonfun$apply$1.apply(routes_routing.scala:49) ~[na:na]
at play.core.Router$HandlerInvoker$$anon$6$$anon$2.invocation(Router.scala:164) ~[play_2.10.jar:2.1.1]
at play.core.Router$Routes$$anon$1.invocation(Router.scala:345) ~[play_2.10.jar:2.1.1]
at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:31) ~[play_2.10.jar:2.1.1]
at play.core.j.JavaAction$$anon$2.apply(JavaAction.scala:74) ~[play_2.10.jar:2.1.1]
at play.core.j.JavaAction$$anon$2.apply(JavaAction.scala:73) ~[play_2.10.jar:2.1.1]
at play.libs.F$Promise$PromiseActor.onReceive(F.java:420) ~[play_2.10.jar:2.1.1]
at akka.actor.UntypedActor$$anonfun$receive$1.applyOrElse(UntypedActor.scala:159) ~[akka-actor_2.10.jar:na]
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:425) ~[akka-actor_2.10.jar:na]
at akka.actor.ActorCell.invoke(ActorCell.scala:386) ~[akka-actor_2.10.jar:na]
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:230) ~[akka-actor_2.10.jar:na]
at akka.dispatch.Mailbox.run(Mailbox.scala:212) ~[akka-actor_2.10.jar:na]
at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:502) ~[akka-actor_2.10.jar:na]
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:262) ~[scala-library.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975) ~[scala-library.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1478) ~[scala-library.jar:na]
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104) ~[scala-library.jar:na]
Caused by: java.lang.ClassNotFoundException: myPackage.test.SurveyResponse
at java.net.URLClassLoader$1.run(Unknown Source) ~[na:1.6.0_37]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.6.0_37]
at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.6.0_37]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.6.0_37]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.6.0_37]
at sbt.PlayCommands$$anonfun$53$$anonfun$55$$anon$2.loadClass(PlayCommands.scala:535) ~[na:na]
at java.lang.Class.forName0(Native Method) ~[na:1.6.0_37]
at java.lang.Class.forName(Unknown Source) ~[na:1.6.0_37]
at org.apache.commons.lang3.ClassUtils.getClass(ClassUtils.java:823) ~[commons-lang3.jar:3.1]
at org.apache.commons.lang3.ClassUtils.getClass(ClassUtils.java:889) ~[commons-lang3.jar:3.1]
at org.apache.commons.lang3.ClassUtils.getClass(ClassUtils.java:872) ~[commons-lang3.jar:3.1]
at org.dozer.util.DefaultClassLoader.loadClass(DefaultClassLoader.java:36) ~[dozer-5.4.0.jar:na]
... 28 common frames omitted
Extra information:
I still couldnt solve the problem, but here some extra infomation to narrow down the problem:
The csv header is successfully written to the file when i remove the configureBeanMapping Method call (see code below).
The SurveyResponse class is working too when i do a System.out.println() on a filled SurveyResponse object (see code below).
So its not a problem with the package or class name.
The modiefied Code that writes only the header:
//...more code
myPackage.csv.SurveyResponse response3 = new myPackage.csv.SurveyResponse(42, false, Arrays.asList(new Answer(1, null), new Answer(2,
"Carl Sagan"), new Answer(3, "Star Wars")));
final List<myPackage.csv.SurveyResponse> surveyResponses = Arrays.asList(response1, response2, response3);
ICsvDozerBeanWriter beanWriter = null;
try {
beanWriter = new CsvDozerBeanWriter(new FileWriter("target/writeWithCsvDozerBeanWriter.csv"),
CsvPreference.STANDARD_PREFERENCE);
// configure the mapping from the fields to the CSV columns
//beanWriter.configureBeanMapping(myPackage.csv.SurveyResponse.class, FIELD_MAPPING);
//Prints the value 42 successfully
System.out.println(response3.getAge());
// write the header
beanWriter.writeHeader("age", "consentGiven", "questionNo1", "answer1", "questionNo2", "answer2","questionNo3", "answer3");
//...more code
From what I understand from the error, Play is trying to load the wrong class. Look at this line :
java.lang.ClassNotFoundException: org.supercsv.mock.dozer.SurveyResponse
I think that SurverResponse is one of your own project classes and not part of SuperCSV. Try to prefix it with the full path such as :
beanWriter.configureBeanMapping(whateverpackage.models.SurveyResponse.class, FIELD_MAPPING);
SurveyResponse and Answer are test classes of the super-csv-dozer artifact - so they aren't packaged in the distribution (i.e they're not in Maven or in the zip file on SourceForge).
You can view the test source online or checkout the SVN repo (which it sounds like you've already done) and just copy them into your Play project.
Both files are in the following directory:
supercsv/super-csv-dozer/src/test/java/org/supercsv/mock/dozer/
I'm a little curious why you're not getting a compilation error when trying to use SurveyResponse in your code. My guess is that you have the super-csv-dozer project checked out and open in your IDE and your project is finding it.
I have the following java code. I am using XQJ to write a test XQuery program using XQJ api. I have downloaded JSR-000225 XQuery API for Java 1.0 Final Release, and added xqjapi.jar to my classpath.
The java code is as simple as the following
import javax.xml.xquery.XQConnection;
import javax.xml.xquery.XQDataSource;
import javax.xml.xquery.XQException;
public class SaxonExtJavaObject {
public static void main(String[] args) throws XQException, InstantiationException, IllegalAccessException, ClassNotFoundException {
XQDataSource xqds = (XQDataSource)
Class.forName("com.jsr225.xqj").newInstance();
// obtain a connection
XQConnection con = xqds.getConnection("usr", "passwd");
System.out.println("connected");
}
}
My problem is that I have the following exception
Exception in thread "main" java.lang.ClassNotFoundException: com.jsr225.xqj
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
Please some one help me solving this.
you will still need a product (i.e. XQuery processor) acting as an actual data source; you can find a list of supported implementations on http://xqj.net/
Much like JDBC, despite having an interface defining the operations allowed with a database, you need an implementation (e.g. MySQL, PostgreSQL or DB2) that carries out the selected tasks.
There are XQJ implementations for XML Databases written in Java: BaseX, eXist
as well as interfaces to Zorba, MarkLogic (commercial) and Sedna (written in C/C++).
In your example you reference Saxon, information on using Saxon and XQJ can be found in Saxon’s documentation
I hope this helped to clear things up a litte.
Michael