Reputation: 9439
I'd like to export my Java project using Eclipse Export capability. My project includes many Spring libs. I did right click project/Export/JAR file, chose project, checked everything of the project, specified Main Class. When I run it with arguments, errors occur. How to fix it?
F:\Downloads\MyProject>java -jar release.jar --d 2014/03/17 --l 1 --s 9001
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/b
eans/factory/BeanFactory
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.springframework.beans.factory.B
eanFactory
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)
... 6 more
Update: I tried to export it as Runnable JAR file. It shows the below error. (Sorry I cannot post whole error log because of security)
....
Invocation of init method failed; nested exception is java.io.
FileNotFoundException: ibatis\SqlMapConfig.xml (The system cannot find the path
specified)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getOb
ject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistr
y.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBe
an(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.
preInstantiateSingletons(DefaultListableBeanFactory.java:567)
at org.springframework.context.support.AbstractApplicationContext.finish
BeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refres
h(AbstractApplicationContext.java:464)
at org.springframework.context.support.FileSystemXmlApplicationContext.<
init>(FileSystemXmlApplicationContext.java:140)
at org.springframework.context.support.FileSystemXmlApplicationContext.<
init>(FileSystemXmlApplicationContext.java:84)
at net.webike.japan.spring.batch.GlobalEstimateProcessExec.process(Globa
lEstimateProcessExec.java:148)
at net.webike.japan.spring.batch.GlobalEstimateProcessExec.main(GlobalEs
timateProcessExec.java:120)
Caused by: java.io.FileNotFoundException: ibatis\SqlMapConfig.xml (The system ca
nnot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at org.springframework.core.io.FileSystemResource.getInputStream(FileSys
temResource.java:113)
at org.springframework.orm.ibatis.SqlMapClientFactoryBean.buildSqlMapCli
ent(SqlMapClientFactoryBean.java:336)
at org.springframework.orm.ibatis.SqlMapClientFactoryBean.afterPropertie
sSet(SqlMapClientFactoryBean.java:291)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 13 more
Update: spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!-- Database -->
<bean id="test" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://myip/myProject?useUnicode=yes&characterEncoding=SJIS</value>
</property>
<property name="username">
<value>test</value>
</property>
<property name="password">
<value>test</value>
</property>
<property name="maxActive" value="30" />
<property name="maxIdle" value="8" />
<property name="maxWait" value="-1" />
<property name="validationQuery" value="select version()" />
</bean>
<bean id="test" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>ibatis/SqlMapConfig.xml</value>
</property>
<property name="dataSource">
<ref local="dsGlobalRanking" />
</property>
</bean>
<bean id="SomethingDAO"
class="mypackage.SomethingDAOImpl"
scope="singleton">
<constructor-arg>
<ref bean="test" />
</constructor-arg>
</bean>
</beans>
Then I load it
String contextPath = "classpath:spring.xml";
BeanFactory context =
(BeanFactory) new FileSystemXmlApplicationContext(contextPath);
Upvotes: 0
Views: 650
Reputation: 1722
Assuming you have SqlMapConfig.xml inside the Jar, for example in the position:
/res/ibatis/SqlMapConfig.xml
You should reference it in the spring.xml file as the following:
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="classpath:/res/ibatis/SqlMapConfig.xml"/>
<property name="dataSource" ref="yourDataSource"/>
</bean>
(note the classpath: marker)
Upvotes: 1