I'm trying to use Stanford CoreNLP as a library in my java program. I use IntelliJ as the IDE.
I was trying to test the library, so I wrote this code:
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import java.util.Properties;
/**
* Created by Benjamin on 15/5/4.
*/
public class SentimentAnaTest {
public static void main(String[] args) {
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
}
}
and it shows the error like this:
Adding annotator tokenize
TokenizerAnnotator: No tokenizer type provided. Defaulting to PTBTokenizer.
Adding annotator ssplit
Adding annotator pos
Exception in thread "main" java.lang.RuntimeException: edu.stanford.nlp.io.RuntimeIOException: Unrecoverable error while loading a tagger model
at edu.stanford.nlp.pipeline.AnnotatorFactories$4.create(AnnotatorFactories.java:292)
at edu.stanford.nlp.pipeline.AnnotatorPool.get(AnnotatorPool.java:85)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(StanfordCoreNLP.java:289)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:126)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:122)
at SentimentAnaTest.main(SentimentAnaTest.java:12)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: edu.stanford.nlp.io.RuntimeIOException: Unrecoverable error while loading a tagger model
at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:770)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:298)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:263)
at edu.stanford.nlp.pipeline.POSTaggerAnnotator.loadModel(POSTaggerAnnotator.java:97)
at edu.stanford.nlp.pipeline.POSTaggerAnnotator.<init>(POSTaggerAnnotator.java:77)
at edu.stanford.nlp.pipeline.AnnotatorImplementations.posTagger(AnnotatorImplementations.java:59)
at edu.stanford.nlp.pipeline.AnnotatorFactories$4.create(AnnotatorFactories.java:290)
... 10 more
Caused by: java.io.IOException: Unable to resolve "edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger" as either class path, filename or URL
at edu.stanford.nlp.io.IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(IOUtils.java:481)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:765)
... 16 more
I read a solution here but couldn't figure out what the problem was, because I added the library from the Maven Central Repository which already included the "stanford-corenlp-3.5.2-models.jar".
From the error message it seemed like the program was trying to load a file from edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger so I download the tagger file from here and put it into /edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger. However it still didn't work.
Can someone tell me whats this error is about and help me to solve it? Thank you!
I had the same problem. Fixed using:
<dependencies>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.5.2</version>
<classifier>models</classifier>
</dependency>
</dependencies>
or for SBT:
"edu.stanford.nlp" % "stanford-corenlp" % "3.5.2",
"edu.stanford.nlp" % "stanford-corenlp" % "3.5.2" classifier "models",
The tagger file has to be placed into your project root.
project
-- src --> SentimentAnaTest
-- english-left3words/english-left3words-distsim.tagger
Tested in Eclipse project.
I faced the same error and took me a long time to figure it out. Essentially there are two main jar files we will be needing to solve the error. One is the stable version 3.6.0 and the current version 3.7.0
So, download both jar files from the following link and link. Now extract both the jar files. The extracted folder of the 3.7.0 jar file does not have the models folder as of now. You can find this folder in the 3.6.0 jar file extracted folder.
Copy that folder from 3.6 version to 3.7 version.
Now from the root folder run the following command:
java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000
It should run perfectly. In order to use the server, follow this py-corenlp
The problem could be that you are starting server via the jar file that you must have created from the compiled classed, so make sure you re-create the jar after putting in the required file to the folder location as can be seen on the error console.
Once you re-create the jar, start the server.
Related
I have a moderately old, small Java application which has an option to read and export PDF files using the Apache PDFBox library (hereunder, "pdfbox-app.jar"). All the files, including this resource, are stored in a single flat folder.
This works fine when called from a JAR file:
D:\Prog\!GitHub\Arena>java -jar Athena.jar NPCGenerator -p
OED NPC Generator
-----------------
Writing Gwenllian-ElfFtr1Wiz1.pdf
It similarly works fine when run from my IDE (jGrasp).
But it fails when called from the command line, outside of its JAR:
D:\Prog\!GitHub\Arena>java NPCGenerator -p
OED NPC Generator
-----------------
Writing Eoin-HalflingFtr1.pdf
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/pdfbox/pdmodel/PDDoc
ument
at CharacterPDF.writePDF(CharacterPDF.java:49)
at NPCGenerator.printToPDF(NPCGenerator.java:294)
at NPCGenerator.makeAllNPCs(NPCGenerator.java:270)
at NPCGenerator.main(NPCGenerator.java:308)
Caused by: java.lang.ClassNotFoundException: org.apache.pdfbox.pdmodel.PDDocument
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.j
ava:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoader
s.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 4 more
What should I be doing to run this on the command line outside of its own JAR?
You should put the pdfbox jar, and any other dependencies, on the classpath:
java -classpath .;pdfbox-app.jar NPCGenerator -p
Without that, Java doesn't know where to look for org/apache/pdfbox classes. It looks for .class files relative to the default classpath (which is just ., the current directory), but does not look inside jars.
I have enabled overthereconnection's through Spring IDE, but when I try running my maven-built application via commandline, I get this error:
Exception in thread "main" java.util.ServiceConfigurationError: jar (Unknown file system scheme! May be the class path doesn't contain the respective driver module or it isn't set up correctly?)
at de.schlichtherle.truezip.fs.FsAbstractCompositeDriver.newController(FsAbstractCompositeDriver.java:33)
at de.schlichtherle.truezip.fs.FsDefaultManager.getController0(FsDefaultManager.java:95)
at de.schlichtherle.truezip.fs.FsDefaultManager.getController(FsDefaultManager.java:78)
at de.schlichtherle.truezip.file.TFile.getController(TFile.java:1497)
at de.schlichtherle.truezip.file.TFile.parse(TFile.java:687)
at de.schlichtherle.truezip.file.TFile.<init>(TFile.java:659)
at de.schlichtherle.truezip.file.TFile.<init>(TFile.java:601)
at nl.javadude.scannit.reader.TFiles.tFile(TFiles.java:23)
at nl.javadude.scannit.reader.ArchiveEntrySupplier.withArchiveEntries(ArchiveEntrySupplier.java:23)
at nl.javadude.scannit.Worker.scanFiles(Worker.java:59)
at nl.javadude.scannit.Worker.scanURI(Worker.java:53)
at nl.javadude.scannit.Worker.scan(Worker.java:46)
at nl.javadude.scannit.Scannit.<init>(Scannit.java:41)
at com.xebialabs.overthere.Overthere.boot(Overthere.java:74)
at com.xebialabs.overthere.Overthere.<clinit>(Overthere.java:69)
at com.emc.ondemand.agent.core.discovery.AnalyzeSelf.constructODEnvironmentForSingleHost(AnalyzeSelf.java:172)
at com.emc.ondemand.agent.core.discovery.DiscoverEnvironment.discoverEnvironment(DiscoverEnvironment.java:85)
at com.emc.ondemand.agent.core.discovery.DiscoverEnvironment.main(DiscoverEnvironment.java:48)
My code call looks like:
// establish winrm connection to target host
ConnectionOptions options = new ConnectionOptions();
options.set(ADDRESS, myHost.getIP());
options.set(USERNAME, user);
options.set(PASSWORD, pass);
options.set(OPERATING_SYSTEM, WINDOWS);
options.set(CONNECTION_TYPE, WINRM_NATIVE); // was not able to get WINRM_INTERNAL to work with processes
connection = Overthere.getConnection("cifs", options);
This is the only dependency I have:
<dependency>
<groupId>com.xebialabs.overthere</groupId>
<artifactId>overthere</artifactId>
<version>4.2.1</version>
</dependency>
It does pull in the correct Truezip classes so I'm at a loss as to what it means exactly.
I guess your dependency is an uber-JAR? Please check if there is a file named META-INF/services/de.schlichtherle.truezip.fs.spi.FsDriverService on the class path. Among others, it needs to contain the following entry:
de.schlichtherle.truezip.fs.archive.zip.ZipDriverService
If that's not the case, then please contact the creator of the overthere artifact and tell them that they appear to have incorrectly assembled their artifact from the TrueZIP dependencies.
In all cases, you should be able to fix this problem by adding another dependency to your class path:
<dependency>
<groupId>de.schlichtherle.truezip</groupId>
<artifactId>truezip-driver-zip</artifactId>
<version>7.7.9</version>
</dependency>
I am using the CoreNLP package to do some annotation on user comments and since I have upgraded to the 3.5.0 version I seem to repeatedly run into the same error:
Loading classifier from edu/stanford/nlp/models/ner/english.all.3class.distsim.crf.ser.gz ...
Loading distsim lexicon from /u/nlp/data/pos_tags_are_useless/egw4-reut.512.clusters ...
java.lang.RuntimeException: java.io.FileNotFoundException: \u\nlp\data\pos_tags_are_useless\egw4-reut.512.clusters (The system cannot find the path specified)
at edu.stanford.nlp.objectbank.ReaderIteratorFactory$ReaderIterator.setNextObject(ReaderIteratorFactory.java:225) (cue fifty lines of error)
A few searches here got me these similar questions:
Stanford NER Error: Loading distsim lexicon Failed and Stanford NER tagger generates 'file not found' exception with provided models which did not solve my issue: I am exclusively using code and models from the 3.5.0 (via Maven Central). I tried modifying the props file from the NER model and pointing towards another .clusters file in a user directory with no success (exact same error).
The code I use to instantiate the CoreNLP object is pretty standard too, but here it is:
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
stan = new StanfordCoreNLP(props);
Now I am thinking that there is something obvious that I am missing. Any help would be greatly appreciated.
A more complete stacktrace (if that can help) is as follows:
Loading classifier from edu/stanford/nlp/models/ner/english.all.3class.distsim.crf.ser.gz ... Loading distsim lexicon from /u/nlp/data/pos_tags_are_useless/egw4-reut.512.clusters ... java.lang.RuntimeException: java.io.FileNotFoundException: \u\nlp\data\pos_tags_are_useless\egw4-reut.512.clusters (The system cannot find the path specified)
at edu.stanford.nlp.objectbank.ReaderIteratorFactory$ReaderIterator.setNextObject(ReaderIteratorFactory.java:225)
at edu.stanford.nlp.objectbank.ReaderIteratorFactory$ReaderIterator.<init>(ReaderIteratorFactory.java:161)
at edu.stanford.nlp.objectbank.ReaderIteratorFactory.iterator(ReaderIteratorFactory.java:98)
at edu.stanford.nlp.objectbank.ObjectBank$OBIterator.<init>(ObjectBank.java:404)
at edu.stanford.nlp.objectbank.ObjectBank.iterator(ObjectBank.java:242)
at edu.stanford.nlp.ie.NERFeatureFactory.initLexicon(NERFeatureFactory.java:471)
at edu.stanford.nlp.ie.NERFeatureFactory.init(NERFeatureFactory.java:379)
at edu.stanford.nlp.ie.AbstractSequenceClassifier.reinit(AbstractSequenceClassifier.java:171)
at edu.stanford.nlp.ie.crf.CRFClassifier.loadClassifier(CRFClassifier.java:2630)
at edu.stanford.nlp.ie.AbstractSequenceClassifier.loadClassifier(AbstractSequenceClassifier.java:1620)
at edu.stanford.nlp.ie.AbstractSequenceClassifier.loadClassifier(AbstractSequenceClassifier.java:1675)
at edu.stanford.nlp.ie.AbstractSequenceClassifier.loadClassifier(AbstractSequenceClassifier.java:1662)
at edu.stanford.nlp.ie.crf.CRFClassifier.getClassifier(CRFClassifier.java:2851)
at edu.stanford.nlp.ie.ClassifierCombiner.loadClassifierFromPath(ClassifierCombiner.java:189)
at edu.stanford.nlp.ie.ClassifierCombiner.loadClassifiers(ClassifierCombiner.java:173)
at edu.stanford.nlp.ie.ClassifierCombiner.<init>(ClassifierCombiner.java:113)
at edu.stanford.nlp.ie.NERClassifierCombiner.<init>(NERClassifierCombiner.java:64)
at edu.stanford.nlp.pipeline.StanfordCoreNLP$6.create(StanfordCoreNLP.java:617)
at edu.stanford.nlp.pipeline.AnnotatorPool.get(AnnotatorPool.java:85)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(StanfordCoreNLP.java:267)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:129)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:125)
at rgu.jclos.quilt.utilities.nlp.DependenciesTagger.<init>(DependenciesTagger.java:99)
at rgu.jclos.quilt.eca.approaches.ApproachC_USS.main(ApproachC_USS.java:47)
Caused by: java.io.FileNotFoundException: \u\nlp\data\pos_tags_are_useless\egw4-reut.512.clusters (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:131)
at edu.stanford.nlp.io.EncodingFileReader.<init>(EncodingFileReader.java:78)
at edu.stanford.nlp.objectbank.ReaderIteratorFactory$ReaderIterator.setNextObject(ReaderIteratorFactory.java:192)
... 23 more
Loading classifier from edu/stanford/nlp/models/ner/english.all.3class.distsim.crf.ser.gz ... Exception in thread "main" edu.stanford.nlp.io.RuntimeIOException: java.io.FileNotFoundException
at edu.stanford.nlp.pipeline.StanfordCoreNLP$6.create(StanfordCoreNLP.java:621)
at edu.stanford.nlp.pipeline.AnnotatorPool.get(AnnotatorPool.java:85)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(StanfordCoreNLP.java:267)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:129)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:125)
at rgu.jclos.quilt.utilities.nlp.DependenciesTagger.<init>(DependenciesTagger.java:99)
at rgu.jclos.quilt.eca.approaches.ApproachC_USS.main(ApproachC_USS.java:47)
Caused by: java.io.FileNotFoundException
at edu.stanford.nlp.ie.ClassifierCombiner.loadClassifierFromPath(ClassifierCombiner.java:199)
at edu.stanford.nlp.ie.ClassifierCombiner.loadClassifiers(ClassifierCombiner.java:173)
at edu.stanford.nlp.ie.ClassifierCombiner.<init>(ClassifierCombiner.java:113)
at edu.stanford.nlp.ie.NERClassifierCombiner.<init>(NERClassifierCombiner.java:64)
at edu.stanford.nlp.pipeline.StanfordCoreNLP$6.create(StanfordCoreNLP.java:617)
... 6 more
Caused by: java.lang.ClassCastException: java.util.ArrayList cannot be cast to edu.stanford.nlp.classify.LinearClassifier
at edu.stanford.nlp.ie.ner.CMMClassifier.loadClassifier(CMMClassifier.java:1070)
at edu.stanford.nlp.ie.AbstractSequenceClassifier.loadClassifier(AbstractSequenceClassifier.java:1620)
at edu.stanford.nlp.ie.AbstractSequenceClassifier.loadClassifier(AbstractSequenceClassifier.java:1675)
at edu.stanford.nlp.ie.AbstractSequenceClassifier.loadClassifier(AbstractSequenceClassifier.java:1662)
at edu.stanford.nlp.ie.ner.CMMClassifier.getClassifier(CMMClassifier.java:1116)
at edu.stanford.nlp.ie.ClassifierCombiner.loadClassifierFromPath(ClassifierCombiner.java:195)
... 10 more
It turns out that the problem was caused by Maven.
My code was located in a utility library which was wrapping over the Stanford CoreNLP to provide additional processing, and was working perfectly well by itself. However when adding this project as a dependency to my master project, Maven defaulted to importing version 3.4 of the Stanford CoreNLP library models to the master project, which caused the bug described above.
I used the example code "Using WebEnv & QueryKey example" from http://www.ncbi.nlm.nih.gov/books/NBK55696/ - the ESearch part seems to work fine, but not EFetch. I added the command "e.printStackTrace()" to get the full error message:
WebEnv: NCID_1_160921978_130.14.18.34_9001_1392822285_1227953195
QueryKey: 1
org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement {http://www.ncbi.nlm.nih.gov/soap/eutils/efetch_pubmed}Affiliation
org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement {http://www.ncbi.nlm.nih.gov/soap/eutils/efetch_pubmed}Affiliation
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
at gov.nih.nlm.ncbi.www.soap.eutils.EFetchPubmedServiceStub.fromOM(EFetchPubmedServiceStub.java)
at gov.nih.nlm.ncbi.www.soap.eutils.EFetchPubmedServiceStub.run_eFetch(EFetchPubmedServiceStub.java:190)
at preparation.Client.main(Client.java:39)
Caused by: java.lang.Exception: org.apache.axis2.databinding.ADBException: Unexpected subelement {http://www.ncbi.nlm.nih.gov/soap/eutils/efetch_pubmed}Affiliation
at gov.nih.nlm.ncbi.www.soap.eutils.EFetchPubmedServiceStub$AuthorType$Factory.parse(EFetchPubmedServiceStub.java:47561)
at gov.nih.nlm.ncbi.www.soap.eutils.EFetchPubmedServiceStub$AuthorListType$Factory.parse(EFetchPubmedServiceStub.java:12284)
at gov.nih.nlm.ncbi.www.soap.eutils.EFetchPubmedServiceStub$ArticleType$Factory.parse(EFetchPubmedServiceStub.java)
at gov.nih.nlm.ncbi.www.soap.eutils.EFetchPubmedServiceStub$MedlineCitationType$Factory.parse(EFetchPubmedServiceStub.java:27035)
at gov.nih.nlm.ncbi.www.soap.eutils.EFetchPubmedServiceStub$PubmedArticleType$Factory.parse(EFetchPubmedServiceStub.java:17841)
at gov.nih.nlm.ncbi.www.soap.eutils.EFetchPubmedServiceStub$PubmedArticleSetChoiceE$Factory.parse(EFetchPubmedServiceStub.java)
at gov.nih.nlm.ncbi.www.soap.eutils.EFetchPubmedServiceStub$PubmedArticleSet_type0$Factory.parse(EFetchPubmedServiceStub.java:54143)
at gov.nih.nlm.ncbi.www.soap.eutils.EFetchPubmedServiceStub$EFetchResult$Factory.parse(EFetchPubmedServiceStub.java:48494)
... 3 more
Caused by: org.apache.axis2.databinding.ADBException: Unexpected subelement {http://www.ncbi.nlm.nih.gov/soap/eutils/efetch_pubmed}Affiliation
at gov.nih.nlm.ncbi.www.soap.eutils.EFetchPubmedServiceStub$AuthorType$Factory.parse(EFetchPubmedServiceStub.java:47555)
... 10 more
I am using Eclipse (Version: 3.7.2) with Ubuntu 12.04 LTS and java-7-openjdk-amd64 as JRE. The NCBI page mentions to use this command before runnning Client.java:
wsdl2java -uri http://eutils.ncbi.nlm.nih.gov/soap/v2.0/efetch_pubmed.wsdl
Instead of that, I simply included the jar files (only binaries) that have been shown as output in console, because this worked fine for all other exapmles on http://www.ncbi.nlm.nih.gov/books/NBK55696/ except the ELink example:
org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement {http://www.ncbi.nlm.nih.gov/soap/eutils/elink}error
I will describe which jar files I included in my project.
As the FTP link for downloading eutils_axis2.jar on the above mentioned page did not work, I searched for the current path and added it to my Eclipse project.
Their README says that JDK version 7.0.45 and Axis2 version 1.6.2 should be used and that it was released in December 2013.
I searched for "download wsdl2java.sh" in Google to get the Axis2 version in connection to WSDL and found the package axis2-eclipse-service-plugin-1.6.2.zip . I downloaded the package and added all jar files to my project:
apache-mime4j-core-0.7.2.jar
axiom-api-1.2.13.jar
axiom-impl-1.2.13.jar
axis2-adb-1.6.2.jar
axis2-codegen-1.6.2.jar
axis2-kernel-1.6.2.jar
commons-codec-1.3.jar
commons-fileupload-1.2.jar
commons-httpclient-3.1.jar
geronimo-jta_1.1_spec-1.1.jar
geronimo-ws-metadata_2.0_spec-1.1.2.jar
jaxen-1.1.1.jar
jsr311-api-1.0.jar
neethi-3.0.2.jar
servlet-api-2.3.jar
woden-api-1.0M9.jar
woden-impl-commons-1.0M9.jar
woden-impl-dom-1.0M9.jar
wsdl4j-1.6.2.jar
XmlSchema-1.4.7.jar
Then I searched the packages for the remaining error messages:
axis2-transport-http-1.6.2.jar
axis2-transport-local-1.6.2.jar
commons-logging-1.1.3.jar
geronimo-javamail_1.4_spec-1.7.1.jar
httpcore-4.3.2.jar
I searched for similar cases with Google, but I did not find a solution. How can I fix this message mentioned at the beginning?
The corresponding wsdl file mentioned in the NCBI tutorial is from 2010. Maybe it is outdated, but first, be sure that creating the specified java classes works fine. Do the following steps result in an error?
Download and extract axis2-1.6.2.
Set the environment variables
export AXIS2_HOME=<path/to/axis2-1.6.2>
export JAVA_HOME=<path/to/java-7-openjdk-amd64>
Download the following files
http://eutils.ncbi.nlm.nih.gov/soap/v2.0/efetch_pubmed.xsd
http://eutils.ncbi.nlm.nih.gov/soap/v2.0/efetch_db_pubmed.xsd
http://eutils.ncbi.nlm.nih.gov/soap/v2.0/efetch_pubmed.wsdl
and execute bin/wsdl2java.sh within the axis2-1.6.2 directory using the efetch_pubmed.wsdl file.
sh wsdl2java.sh -uri <path/to/efetch_pubmed.wsdl>
Two java classes should appear in
src/gov/nih/nlm/ncbi/www/soap/eutils
(still in your axis/bin directory). Import and use these files with your Client.java (pointing to the filename in the tutorial).
Works fine for me. Hope that helps.
I'm creating a cli tool to manage an existing application. Both the application and the tests build fine and run fine but despite that I receive a javassist failure when running my cli tool that exists within the jar:
INFO: Bytecode provider name : javassist
...
INFO: Hibernate EntityManager 3.5.1-Final
Exception in thread "main" javax.persistence.PersistenceException: Unable to configure EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:371)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:55)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
...
at com.sophware.flexipol.admin.AdminTool.<init>(AdminTool.java:40)
at com.sophware.flexipol.admin.AdminTool.main(AdminTool.java:69)
Caused by: java.lang.RuntimeException: Error while reading file:flexipol-jar-with-dependencies.jar
at org.hibernate.ejb.packaging.NativeScanner.getClassesInJar(NativeScanner.java:131)
at org.hibernate.ejb.Ejb3Configuration.addScannedEntries(Ejb3Configuration.java:467)
at org.hibernate.ejb.Ejb3Configuration.addMetadataFromScan(Ejb3Configuration.java:457)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:347)
... 11 more
Caused by: java.io.IOException: invalid constant type: 60
at javassist.bytecode.ConstPool.readOne(ConstPool.java:1027)
at javassist.bytecode.ConstPool.read(ConstPool.java:970)
at javassist.bytecode.ConstPool.<init>(ConstPool.java:127)
at javassist.bytecode.ClassFile.read(ClassFile.java:693)
at javassist.bytecode.ClassFile.<init>(ClassFile.java:85)
at org.hibernate.ejb.packaging.AbstractJarVisitor.checkAnnotationMatching(AbstractJarVisitor.java:243)
at org.hibernate.ejb.packaging.AbstractJarVisitor.executeJavaElementFilter(AbstractJarVisitor.java:209)
at org.hibernate.ejb.packaging.AbstractJarVisitor.addElement(AbstractJarVisitor.java:170)
at org.hibernate.ejb.packaging.FileZippedJarVisitor.doProcessElements(FileZippedJarVisitor.java:119)
at org.hibernate.ejb.packaging.AbstractJarVisitor.getMatchingEntries(AbstractJarVisitor.java:146)
at org.hibernate.ejb.packaging.NativeScanner.getClassesInJar(NativeScanner.java:128)
... 14 more
Since I know the jar is fine as the unit and integration tests run against it, I thought it might be a problem with javassist, so I tried cglib. The bytecode provider then shows as cglib but I still get the exact same stack trace with javassist present in it.
cglib is definitely in the classpath:
$ unzip -l flexipol-jar-with-dependencies.jar | grep cglib | wc -l
383
I've tried with both hibernate 3.4 and 3.5 and get the exact same error. Is this a problem with javassist?
UPDATE: I can run the application successfully within Eclipse (Right click->Run As->Java Application), but using the maven-generated jar-with-dependencies fails. I presume the difference is that with Eclipse javassist isn't inspecting the containing jar, rather, it's inspecting all of the class files (and perhaps a few dependent 3rd-party jars).
The problem is ultimately caused by an invalid class in icu4j-2.6.1 as can be seen in this post. Specifically, this file is invalid:
com/ibm/icu/impl/data/LocaleElements_zh__PINYIN.class
Here's a simple way to identify a corrupt file:
for x in PATH_TO_EXTRACTED_JAR/**/*.class; do
java -cp PATH_TO/javassist.jar javassist.tools.Dump $x >/dev/null 2>&1 || echo "$x is invalid"
done
This file is being included by indirectly by maven through its transitive dependencies which is why I didn't recognize that page as referencing the error and a file contained within the jar as being the culprit and cause of the problem. Here's how it ended up included in my jar-with-dependencies bundle:
jaxen-1.1.1 -> xom-1.0 -> icu4j-2.6.1
After adding the following exclusion to the jaxen dependency, everything worked correctly for me (but be careful if you need its localization pieces):
<exclusions>
<exclusion>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
</exclusion>
</exclusions>
Another option would be to remove the offending file(s) from the jar file:
#!/bin/sh
shopt -s extglob
shopt -s globstar
for x in **/*.jar ; do
zip -d $x 'com/ibm/icu/impl/data/*_zh*' >/dev/null 2>&1 && echo "Removed corrupted files from $x"
done