dubbo提供者打包,解决jar不能正常运行(不能注册到注册中心)

来源:互联网 发布:java基础测试题及答案 编辑:程序博客网 时间:2024/06/05 07:12

这几天打包发布dubbo提供者,出现了各种问题.

今天记录的是直接在Eclispe是运行Main方法时正常使用服务.打包成jar在服务运行时不能正常使用问题.

我写的Main方法:

public class BannerProvider {    public static void main(String[] args) {        com.alibaba.dubbo.container.Main.main(args);    }    }


查找了几天,翻了N文档.后来死心了..一行一行看看控制台的每一行log找到了解决方案(发现自己以前老是说别人不看控制台,我现在也懒了不想去看控制台信息..看到得好好反省反省了)

log4j:WARN No appenders could be found for logger (com.alibaba.dubbo.common.logger.LoggerFactory).log4j:WARN Please initialize the log4j system properly.log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.SLF4J: Class path contains multiple SLF4J bindings.SLF4J: Found binding in [jar:file:/D:/provider/hequ-banner/lib/logback-classic-1.0.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]SLF4J: Found binding in [jar:file:/D:/provider/hequ-banner/lib/slf4j-log4j12-1.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.15:17:39.071 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemProperties] PropertySource with lowest search precedence15:17:39.078 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence15:17:39.078 [main] DEBUG o.s.core.env.StandardEnvironment - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]15:17:39.084 [main] INFO  o.s.c.s.ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@58027738: startup date [Mon May 25 15:17:39 CST 2015]; root of context hierarchy15:17:39.136 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemProperties] PropertySource with lowest search precedence15:17:39.137 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence15:17:39.138 [main] DEBUG o.s.core.env.StandardEnvironment - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]15:17:39.149 [main] DEBUG o.s.c.i.s.PathMatchingResourcePatternResolver - Resolved location pattern [classpath*:META-INF/spring/*.xml] to resources []15:17:39.150 [main] DEBUG o.s.b.f.xml.XmlBeanDefinitionReader - Loaded 0 bean definitions from location pattern [classpath*:META-INF/spring/*.xml]15:17:39.151 [main] DEBUG o.s.c.s.ClassPathXmlApplicationContext - Bean factory for org.springframework.context.support.ClassPathXmlApplicationContext@58027738: org.springframework.beans.factory.support.DefaultListableBeanFactory@39376b96:defining beans []; root of factory hierarchy15:17:39.177 [main] DEBUG o.s.c.s.ClassPathXmlApplicationContext - Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@278fea01]15:17:39.182 [main] DEBUG o.s.c.s.ClassPathXmlApplicationContext - Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@75a472e9]15:17:39.183 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@39376b96: defining beans []; root of factory hierarchy15:17:39.186 [main] DEBUG o.s.c.s.ClassPathXmlApplicationContext - Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycleProcessor@5c207889]15:17:39.187 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'15:17:39.191 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'spring.liveBeansView.mbeanDomain' in [systemProperties]15:17:39.191 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'spring.liveBeansView.mbeanDomain' in [systemEnvironment]15:17:39.191 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Could not find key 'spring.liveBeansView.mbeanDomain' in any property source. Returning [null]15:17:39.192 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'[2015-05-25 15:17:39] Dubbo service server started!
这个是直接运行jar包控制台所输出的信息.

其中日志显示加载到0个配置信息. 

 Loaded 0 bean definitions from location pattern [classpath*:META-INF/spring/*.xml]

记得以前运行dubbo的demo时是正常的.

这次重新去看了dubbo的打包配置.


=================

解决方案

=================


再pom.xml中添加了这几行

<build><plugins><plugin><artifactId>maven-dependency-plugin</artifactId><executions><execution><id>unpack</id><phase>package</phase><goals><goal>unpack</goal></goals><configuration><artifactItems><artifactItem><groupId>com.alibaba</groupId><artifactId>dubbo</artifactId><version>2.5.3</version><outputDirectory>${project.build.directory}/dubbo</outputDirectory><includes>META-INF/assembly/**</includes></artifactItem></artifactItems></configuration></execution></executions></plugin><plugin><artifactId>maven-assembly-plugin</artifactId>                <configuration>                    <descriptor>src/main/assembly/assembly.xml</descriptor>                </configuration>                <executions><execution><id>make-assembly</id><phase>package</phase><goals><goal>single</goal></goals></execution></executions>            </plugin></plugins></build>

还需要在添加一个xml src/main/assembly/assembly.xml,一开始我是直接复制了dubbo下的.但是本人有强迫症把文件改了.你可以自己去下载原来的dubbo原来的点这下载

PS:为了修改这个我还去apache查看了Assembly怎么配置(主要是添加了单个文件的拷贝)  官方文档


<!-- - Copyright 1999-2011 Alibaba Group. -   - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at -   -      http://www.apache.org/licenses/LICENSE-2.0 -   - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License.--><assembly><id>assembly</id><formats><format>tar.gz</format></formats><includeBaseDirectory>true</includeBaseDirectory><fileSets><fileSet><directory>${project.build.directory}/dubbo/META-INF/assembly/bin</directory><outputDirectory>bin</outputDirectory><fileMode>0755</fileMode></fileSet><fileSet><directory>src/main/assembly/conf</directory><outputDirectory>conf</outputDirectory><fileMode>0644</fileMode></fileSet></fileSets><files><file><source>src/main/resources/applicationContext.xml</source><outputDirectory>conf</outputDirectory><fileMode>0644</fileMode></file><file><source>src/main/resources/dubbo.properties</source><outputDirectory>conf</outputDirectory><fileMode>0644</fileMode></file><file><source>src/main/resources/hequ.properties</source><outputDirectory>conf</outputDirectory><fileMode>0644</fileMode></file></files><dependencySets><dependencySet><outputDirectory>lib</outputDirectory></dependencySet></dependencySets></assembly>

重新打包 在target下生成了hequ-banner-provide-0.0.1-assembly.tar.gz 解压重新在bin正面运行对应有脚本.程序成功运行


1 0
原创粉丝点击