knowm / XChange

XChange is a Java library providing a streamlined API for interacting with 60+ Bitcoin and Altcoin exchanges providing a consistent interface for trading and accessing market data.
http://knowm.org/open-source/xchange/
MIT License
3.89k stars 1.94k forks source link

Unable to initialize class in Tomcat servlet #78

Closed magmahindenburg closed 11 years ago

magmahindenburg commented 11 years ago

I have some problems with running the first and most simple text example in Tomcat with my servlet. I have included all the libs, but I get java.lang.NoClassDefFoundError.

How many people are running XChange on TomCat? All the classes exist, so I should not get this error.

SEVERE: StandardWrapper.Throwable java.lang.NoClassDefFoundError: Could not initialize class com.xeiam.xchange.rest.RestRequestData at com.xeiam.xchange.rest.RestInvocationHandler.invoke(RestInvocationHandler.java:55) at com.sun.proxy.$Proxy6.getTicker(Unknown Source) at com.xeiam.xchange.mtgox.v1.service.marketdata.polling.MtGoxPollingMarketDataService.getTicker(MtGoxPollingMarketDataService.java:72) at se.myown.trader.Tickersrv.init(Tickersrv.java:55) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4420) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4733) at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3460) at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:426) at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1357) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1649) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1658) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1658) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1638) at java.lang.Thread.run(Thread.java:722)

Apr 17, 2013 2:46:32 PM org.apache.catalina.core.StandardContext loadOnStartup SEVERE: Servlet /TradeAPI threw load() exception java.lang.NoClassDefFoundError: Could not initialize class com.xeiam.xchange.rest.RestRequestData at com.xeiam.xchange.rest.RestInvocationHandler.invoke(RestInvocationHandler.java:55) at com.sun.proxy.$Proxy6.getTicker(Unknown Source) at com.xeiam.xchange.mtgox.v1.service.marketdata.polling.MtGoxPollingMarketDataService.getTicker(MtGoxPollingMarketDataService.java:72) at se.myown.trader.Tickersrv.init(Tickersrv.java:55) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4420) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4733) at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3460) at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:426) at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1357) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1649) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1658) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1658) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1638) at java.lang.Thread.run(Thread.java:722)

gary-rowe commented 11 years ago

Which version of XChange are you using? The RestRequestData has been moved into its own separate dependency due to recent work by Matija and has been repackaged.

magmahindenburg commented 11 years ago

I'm using xchange-1.5.0. I downloaded the jars today. The xchange-core jar contains the rest/ folder under com/xeiam/xchange/, but the source on Git does not.

gary-rowe commented 11 years ago

I can verify that the Maven Central xchange-core-1.5.0.jar definitely has these files. If you want to build them yourself from Git you'll need to do a hard reset on master to hash b15c70e which was the point at which the code was released as 1.5.0.

magmahindenburg commented 11 years ago

I can see the files in Eclipse. And I have the files in Tomcat's lib folder. I'm wondering if this is Tomcat specific? Tomcat is supposed to find all class files automatically. All other class files are found with no problem.

gary-rowe commented 11 years ago

Does the code execute correctly in Eclipse? If so, then you should be able to package up your web application was a WAR and then drop it into Tomcat's deploy folder (been a while since I've used Tomcat so unsure of the name right now). You should see the xchange-core and xchange-mtgox JAR files in the WEB-INF/lib of your WAR. If not then there is a build issue with your web app.

timmolter commented 11 years ago

@magmahindenburg Gary is right about the jars needing to be in WEB-INF/lib of your WAR file. Tomcat should definitely find the class files if the jars are there. You'll need to get the 3rd-party libs as well and make sure they all get built into WEB-INF/lib as well.

About the 1.5.0 confusion... The 1.5.0 source is on the master branch, and the latest and greatest code in on the develop branch. Obviously they will be different so just keep that in mind while researching things. We plan a 1.6.0 release very soon.