The SF documentation is missing some information needed to build the latest partner.jar API file. Here is the link I found that gets you started
http://www.salesforce.com/us/developer/docs/api_asynch/Content/asynch_api_code_set_up_client.htm
The missing part is a dependency on a Javascript libraray called rhino. If you follow the instructions given you get
~/Documents/workspace2/salesforce/carmanah_salesforce$ java -classpath force-wsc-27.0.0.jar com.sforce.ws.tools.wsdlc partner.wsdl partner-27.jar
[WSC][wsdlc.run:320]Created temp dir: /var/folders/D0/D0me7a5vFGmGh95S1IO9PU+++TI/-Tmp-/wsdlc-temp-3884699697501788635-dir
[WSC][wsdlc.<init>:81]Generating Java files from schema ...
Exception in thread "main" java.lang.NoClassDefFoundError: org/mozilla/javascript/Scriptable
at com.sforce.ws.tools.TypeGenerator.generate(TypeGenerator.java:73)
at com.sforce.ws.tools.wsdlc.generate(wsdlc.java:291)
at com.sforce.ws.tools.wsdlc.generateTypes(wsdlc.java:278)
at com.sforce.ws.tools.wsdlc.<init>(wsdlc.java:81)
at com.sforce.ws.tools.wsdlc.run(wsdlc.java:320)
at com.sforce.ws.tools.wsdlc.main(wsdlc.java:311)
Caused by: java.lang.ClassNotFoundException: org.mozilla.javascript.Scriptable
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 6 more
The solution is to get the latest rhino library from http://mvnrepository.com/artifact/rhino
and add this to the command line.
Just for the record, the WSC download is here http://mvnrepository.com/artifact/com.force.api/force-wsc
I'm working with v27 today, file: "force-wsc-27.0.0.jar"
I also downloaded rhino jar file: "js-1.7R2.jar"
I am working on a MAC. I placed both downloaded jar files in my working directory. I downloaded the partner.wsdl file as well. Then use this command line to produce the partner jar file:
java -classpath force-wsc-27.0.0.jar:js-1.7R2.jar com.sforce.ws.tools.wsdlc partner.wsdl partner-27.jar
On some systems you need to use a semi-colon to separate the jar files. Like this:
java -classpath force-wsc-27.0.0.jar;js-1.7R2.jar com.sforce.ws.tools.wsdlc partner.wsdl partner-27.jar
Thanks, it saved me some trouble ;)
ReplyDeleteIs it time to rebuild the partner.jar file again. Summer 13 release is out and the soap version is now v 28. Plus the code that used to work a while ago now throws errors like this: com.sforce.ws.ConnectionException: Unexpected element. Parser was expecting element 'urn:partner.soap.sforce.com:searchable' but found 'urn:partner.soap.sforce.com:searchLayoutable'
ReplyDeleteat com.sforce.ws.bind.TypeMapper.verifyTag(TypeMapper.java:386)
at com.sforce.ws.bind.TypeMapper.verifyElement(TypeMapper.java:415)
at com.sforce.soap.partner.DescribeSObjectResult.loadFields(DescribeSObjectResult.java:814)
at com.sforce.soap.partner.DescribeSObjectResult.load(DescribeSObjectResult.java:730)
....
So, I'll try to build the latest version and see what happens
Yes it seems we need to rebuild the partner jar file now. I say this because a rebuild cleared the above problem. I tried to use V28 WSC downloaded as above but I got this: xception in thread "main" java.lang.NoClassDefFoundError: org/stringtemplate/v4/STGroupDir
ReplyDeleteSo, I used the V27 WSC and all seemed to work well. Here is the compile command:
java -classpath force-wsc-27.0.0.jar:js-1.7R2.jar com.sforce.ws.tools.wsdlc partner.wsdl.v28.xml partner-28.jar
Then copy the jar to servlet container's lib folder. For example,
cp partner-28.jar ~/InstalledSoftware/apache-tomcat/lib/
Thanks you saved me on the java.lang.NoClassDefFoundError: org/stringtemplate/v4/STGroupDir error!!
ReplyDeleteFor API version 29, the command did not work. I had to use
ReplyDeletejava -classpath C:\force-wsc-29.0.0.jar;C:\ST-4.0.7.jar com.sforce.ws.tools.wsdlc C:\partner.wsdl C:\partner.jar
on windows. I obtained ST-4.0.7.jar from http://www.stringtemplate.org/
This just saved me! Thank you!
DeleteThis saved me, thank you! Was on this for hours...
DeleteHi guys, I still can't get API version 29 to work. After downloading ST-4.0.7.jar, did you put it into the same folder as the other wsdl and jar files?
DeleteHello Anonymous,
DeleteYes. Same directory. But you can put them where ever you wish as long as you include the path (absolute or relative) to the jar files.
Thanks Bryan. I get the following error saying the ..\lib\tools.jar cannot be found. I have installed JRE6 and am running the command from C:\Program Files\Java\jre6 in DOS. I validated that the tools.jar does not exist. Am I missing something?
DeleteC:\Program Files\Java\jre6>java -classpath C:\SFDC\force-wsc-29.0.0.jar;C:\SFDC\
ST-4.0.7.jar com.sforce.ws.tools.wsdlc C:\SFDC\partner.wsdl C:\SFDC\partner.jar
[WSC][Generator.generate:130]Generating Java files from schema ...
[WSC][Generator.generate:130]Generated 218 java files.
java.io.FileNotFoundException: C:\Program Files\Java\jre6\lib\tools.jar (The sys
tem cannot find the file specified)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.(Unknown Source)
at java.util.jar.JarFile.(Unknown Source)
at java.util.jar.JarFile.(Unknown Source)
at com.sforce.ws.codegen.ToolsJarClassLoader.(ToolsJarClassLoader.
java:52)
at com.sforce.ws.codegen.Compiler.findCompilerInToolsJar(Compiler.java:6
9)
at com.sforce.ws.codegen.Compiler.(Compiler.java:57)
at com.sforce.ws.codegen.Generator.compileTypes(Generator.java:121)
at com.sforce.ws.tools.wsdlc.run(wsdlc.java:110)
at com.sforce.ws.tools.wsdlc.run(wsdlc.java:142)
at com.sforce.ws.tools.wsdlc.main(wsdlc.java:64)
Error: Unable to find compiler. Make sure that tools.jar is in your classpath: j
ava.io.FileNotFoundException: C:\Program Files\Java\jre6\lib\tools.jar (The syst
em cannot find the file specified)
Hello Anonymous, tools.jar is part of the JDK. You mention that you are using a JRE which is just the Java Runtime Engine. The Java Development Kit has more content. Go back to the Java download page and look for a JDK for Windows. Install that and I'm sure you will be good to go.
DeleteVenkateswaran, Great timing! I'll be updating to the new API soon. So, thanks for the help!
ReplyDeleteYou SAVED my life today!! thankyou!!
ReplyDeleteVenkateswaran you saved my time .
ReplyDeleteThank you for this useful information.
ReplyDeleteThanks Venkateswaran. I had to rebuild the jar again today and needed your link to the StringTemplate. My latest command line (on Mac) is
ReplyDeletejava -classpath force-wsc-29.0.0.jar:js-1.7R2.jar:ST-4.0.7.jar com.sforce.ws.tools.wsdlc partnerV29.wsdl partner-29.jar
My pleasure Bryan. Thanks for maintaining this blog. This is one of my bookmarks now.
DeleteHow to add jar file to command line in Ubuntu?
ReplyDeleteI am getting below error while trying to generate the jar file from the wsdl,
ReplyDeleteC:\Users\amishra>java -classpath c:\FF\force-wsc-29.0.0.jar;c:\FF\js-1.7R2.jar;c:\FF\ST4-4.0.7.jar com.sforce.ws.tools.wsdlc c:\FF\enterprise.wsdl c:\FF\enterprise.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/antlr/runtime/CharStream
at com.sforce.ws.tools.wsdlc.run(wsdlc.java:142)
at com.sforce.ws.tools.wsdlc.main(wsdlc.java:64)
Caused by: java.lang.ClassNotFoundException: org.antlr.runtime.CharStream
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:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 2 more
Is anyone help me out from this problem?
Thanks in advance.
Hi Anonymous, Start over and get the partner jar files not the enterprise. If this doesn't make sense then let me know and I'll find the links in the help files for you.
DeleteThanks for the great post!!
ReplyDeleteUpdate ... now that I'm using Java 7 I also needed to update the wsc-20.jar file. Go here to get the latests version https://code.google.com/p/sfdc-wsc/downloads/list
ReplyDeletejava -classpath force-wsc-32.0.0.jar:js-1.7R2.jar:ST4-4.0.7.jar:antlr-runtime-3.5.jar com.sforce.ws.tools.wsdlc wsdl.jsp.xml enterprise.jar
ReplyDeleteThank you, it worked :)
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHi All,
ReplyDeleteCan anyone of you please help me with this. I have tired this many times but cloud not resolve. I tired to give the JDK path but it says main class not found can anyone please send me the command for the same
C:\Program Files\Java\jdk1.8.0_25>java -classpath C:\users\ctsuser1\desktop\soft
ware\force-wsc-33.0.0.jar;C:\users\ctsuser1\desktop\software\js-14.jar;C:\users\
ctsuser1\desktop\software\ST-4.0.8.jar;\lib\tools.jar com.sforce.ws.tools.wsdlc
C:\users\ctsuser1\desktop\software\salesforce.wsdl C:\users\ctsuser1\desktop\sof
tware\enterprise.jar
[WSC][wsdlc.main:71]Generating Java files from schema ...
[WSC][wsdlc.main:71]Generated 1188 java files.
java.io.FileNotFoundException: C:\Program Files\Java\jre1.8.0_25\lib\tools.jar (
The system cannot find the file specified)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.(Unknown Source)
at java.util.zip.ZipFile.(Unknown Source)
at java.util.jar.JarFile.(Unknown Source)
at java.util.jar.JarFile.(Unknown Source)
at com.sforce.ws.codegen.ToolsJarClassLoader.(ToolsJarClassLoader.
java:52)
at com.sforce.ws.codegen.Compiler.findCompilerInToolsJar(Compiler.java:6
9)
at com.sforce.ws.codegen.Compiler.(Compiler.java:57)
at com.sforce.ws.codegen.Generator.compileTypes(Generator.java:132)
at com.sforce.ws.tools.wsdlc.run(wsdlc.java:117)
at com.sforce.ws.tools.wsdlc.run(wsdlc.java:149)
at com.sforce.ws.tools.wsdlc.main(wsdlc.java:71)
Error: Unable to find compiler. Make sure that tools.jar is in your classpath: j
ava.io.FileNotFoundException: C:\Program Files\Java\jre1.8.0_25\lib\tools.jar (T
he system cannot find the file specified)
I got the same error with JDK 1.8.0_77:
ReplyDelete---
$ java -classpath target/force-wsc-37.0.3-uber.jar com.sforce.ws.tools.wsdlc eu6.salesforce.com_soap_wsdl.jsp.xml salesforceespatial-partner-37.0.3.jar
[WSC][wsdlc.main:71]Generating Java files from schema ...
[WSC][wsdlc.main:71]Generated 615 java files.
java.io.FileNotFoundException: C:\Program Files\Java\jre1.8.0_77\lib\tools.jar (The system cannot find the file specified)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.(Unknown Source)
at java.util.zip.ZipFile.(Unknown Source)
at java.util.jar.JarFile.(Unknown Source)
at java.util.jar.JarFile.(Unknown Source)
at com.sforce.ws.codegen.ToolsJarClassLoader.(ToolsJarClassLoader.java:52)
at com.sforce.ws.codegen.Compiler.findCompilerInToolsJar(Compiler.java:69)
at com.sforce.ws.codegen.Compiler.(Compiler.java:57)
at com.sforce.ws.codegen.Generator.compileTypes(Generator.java:136)
at com.sforce.ws.tools.wsdlc.run(wsdlc.java:117)
at com.sforce.ws.tools.wsdlc.run(wsdlc.java:149)
at com.sforce.ws.tools.wsdlc.main(wsdlc.java:71)
Error: Unable to find compiler. Make sure that tools.jar is in your classpath: java.io.FileNotFoundException: C:\Program Files\Java\jre1.8.0_77\lib\tools.jar (The system cannot find the file specified)
---
I just copied tools.jar from the jdk/lib location to the jre/lib and it worked
¯\_(ツ)_/¯