spp0152

先说下的要求:导出编写的java项目为jar包 可执行方式。如 [cmd]  [java -jar upsms.jar]

java项目用到spring 3.2 和hibernate4.2版本

使用eclipse自带导出jar包功能,选择[Runnable JAR file]

 

然后点击[Finish]就OK。

导出jar包打开页面如下

spring的配置文件 和 jdbc以及Log4j相关配置文件都放在java项目同目录下新建一个文件夹存放。如:

<bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list><!--exe_config所在路径同upsms.jar-->
                <value>exe_config/jdbc.properties</value>
            </list>
        </property>
    </bean>
  /**
     * ide测试环境
     */
    public static void localBy(){
        PropertyConfigurator.configure("src/config/log4j.properties"); 
        ApplicationContext ctx = new FileSystemXmlApplicationContext("src/spring_config/spring-context.xml");
    }
    /**
     * jar包环境
     * 发布jar方式
     * 获取jar包运行路径
     * @param log
     */
    public static void exeLoadBy(Logger log){
         String rootPath = System.getProperty("user.dir");
         log.info("-------------------jar包所在目录:"+rootPath);
         PropertyConfigurator.configure(rootPath+"/exe_config/log4j.properties");
         ApplicationContext ctx = new FileSystemXmlApplicationContext(rootPath+"/exe_config/spring-context.xml");//发布jar方式,这里路径写注意
    }

 

 

分类:

技术点:

相关文章:

  • 2021-12-19
  • 2021-11-28
  • 2021-05-03
猜你喜欢
  • 2021-05-12
  • 2021-10-24
  • 2021-06-22
  • 2021-11-26
  • 2021-12-08
  • 2021-12-08
  • 2021-12-08
相关资源
相似解决方案