一.在http://axis.apache.org/axis2/java/core/download.cgi下载axis2(1.6:http://apache.etoak.com//axis/axis2/java/core/1.6.1/axis2-1.6.1-bin.zip)
二.解压到你觉得应该解压的目录
然后进入bin,执行axis2server.sh启动测试服务器,如果看到以下信息,表示启动成功.
mrjs-MacBook-Pro:bin mrj$ ./axis2server.sh Using AXIS2_HOME: /Users/mrj/Downloads/axis2-1.6.1 Using JAVA_HOME: /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home [INFO] [SimpleAxisServer] Starting [INFO] [SimpleAxisServer] Using the Axis2 Repository/Users/mrj/Downloads/axis2-1.6.1/repository [SimpleAxisServer] Using the Axis2 Repository/Users/mrj/Downloads/axis2-1.6.1/repository [SimpleAxisServer] Using the Axis2 Configuration File/Users/mrj/Downloads/axis2-1.6.1/conf/axis2.xml [INFO] Clustering has been disabled [INFO] Deploying module: addressing-1.6.1 - file:/Users/mrj/Downloads/axis2-1.6.1/repository/modules/addressing-1.6.1.mar [INFO] Deploying module: metadataExchange-1.6.1 - file:/Users/mrj/Downloads/axis2-1.6.1/repository/modules/mex-1.6.1.mar [INFO] Deploying module: mtompolicy-1.6.1 - file:/Users/mrj/Downloads/axis2-1.6.1/repository/modules/mtompolicy-1.6.1.mar [INFO] Deploying module: ping-1.6.1 - file:/Users/mrj/Downloads/axis2-1.6.1/repository/modules/ping-1.6.1.mar [INFO] Deploying module: script-1.6.1 - file:/Users/mrj/Downloads/axis2-1.6.1/repository/modules/scripting-1.6.1.mar [INFO] Deploying module: soapmonitor-1.6.1 - file:/Users/mrj/Downloads/axis2-1.6.1/repository/modules/soapmonitor-1.6.1.mar [INFO] Deploying Web service: version.aar - file:/Users/mrj/Downloads/axis2-1.6.1/repository/services/version.aar [INFO] Listening on port 8080 [INFO] [SimpleAxisServer] Started [SimpleAxisServer] Started
注:你可能需要给文件加上可执行的权限
sudo chmod a+rwx *
三.配置相应环境变量
sudo vim /etc/profile
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home export AXIS2_HOME=/Users/mrj/Downloads/axis2-1.6.1
source /etc/profile
四.使用wsdl生成java文件
进入axis2的bin目录(当然你可以配置环境变量)
如果你已将wsdl下载到本地:
./wsdl2java.sh -o javacode -uri /Users/mrj/Downloads/PadManage.xml
如果是一个web资源:
./wsdl2java.sh -o javacode -uri http://127.0.0.1:8080/axis2/services/Version?wsdl
注:-o指定文件生成目录,你还可以指定-r以生成单元测试类,关于更多的信息,请参数axis2帮助文档.
五.把生成的java文件目录copy到你的项目路径,刷新开发工具,此时你可以看到生成的java文件.
此时你可能会看到项目中有些错误,你只需要将下载来的axis2目录lib里面的jar包加入bulid path.
// -------------------------
附上对helloworld的单元测试
// -------------------------
package sample.axisversion.test; import java.rmi.RemoteException; import org.apache.axis2.AxisFault; import org.junit.Test; import sample.axisversion.VersionExceptionException; import sample.axisversion.VersionStub; import sample.axisversion.VersionStub.GetVersion; /** * * @author mrj * */ public class TestHelloAsix { @Test public void testGetVersion() { try { VersionStub versionStup = new VersionStub(); GetVersion request = new GetVersion(); System.out.println(versionStup.getVersion(request).get_return()); } catch (AxisFault e) { e.printStackTrace(); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (VersionExceptionException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
控制台输出:
log4j:WARN No appenders could be found for logger (org.apache.axis2.description.AxisOperation).
log4j:WARN Please initialize the log4j system properly.
Hi - the Axis2 version is 1.6.1
--------------------
同时jax-ws也是一个不错的东西,你可以在(http://jax-ws-commons.java.net/)下载到它的最新版本(JDK已经带了).
下面这条命令可以生成java代码
wsimport -s /Users/mrj/Desktop/ -extension -p mypkg http://192.168.1.100:8812/PadManage/?wsdl
可能需要用到的jar包:
webservices-rt.jar(**必须的一个)
-- helloworld程序不需要以下jar包,.
webservices-api.jar
webservices-extra-api.jar
webservices-extra.jar
写在前面的话:本系列主要是学习sundy的Android深入浅出视频中的一些记录,心得。方便自己以后查阅。也供大家查看。欢迎交流,补充。
一般作为面试题(有些有答案,有些没有。问题一般从sundy老师思维导图中摘录,答案并非唯一标准,仅供参考):
1、Activity , Window和View的关系是什么?
跟踪Activity的源码就会发现:
Activity.attch() -> PolicyManager -> Policy -> PhoneWindow -> mLayoutInflater.inflate()&mContentParent.addView()
这只是一个简单的跟踪过程描述。通过跟踪源代码,就可以很清晰的看出他们三者的关系。
Activity像一个工匠(控制单元),Window像窗户(承载模型),View像窗花(显示视图)
LayoutInflater像剪刀,Xml配置像窗花图纸。
1)一个Activity构造的时候会初始化一个Window,准确的说是PhoneWindow。
2)这个PhoneWindow有一个“ViewRoot”,引号是说其实这个“ViewRoot”是一个View或者说ViewGroup,是最初始的根视图。
3)“ViewRoot”通过addView方法来一个个的添加View。比如TextView,Button等
4)这些View的事件监听,是由WindowManagerService来接受消息,并且回调Activity函数。比如onClickListener,onKeyDown等
2、Activity是android的显示视图么?
不是
3、LayoutInflater是做什么的 ? layoutInflater.inflater()做什么的?
一般来讲,我们用LayoutInflater做一件事:inflate。inflate这个方法总共有四种形式,目的都是把xml表述的layout转化为View。
This class is used to instantiate layout XML file into its corresponding View objects . It is never be used directly -- use
getLayoutInflater() or getSystemService(String)getLayoutInflater() or getSystemService(String) to retrieve a standard
LayoutInflater instance that is already hooked up to the current context and correctly configured for the device you are
running on
@Override public boolean onCreateOptionsMenu(Menu menu) { setMenuBackground(); return super.onCreateOptionsMenu(menu); } protected void setMenuBackground() { MenuDemo.this.getLayoutInflater().setFactory( new android.view.LayoutInflater.Factory() { @Override public View onCreateView(String name, Context context, AttributeSet attrs) { // 指定自定义inflate的对象 if (name.equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView") || name.equalsIgnoreCase("com.android.internal.view.menu.ListMenuItemView")) { try { LayoutInflater f = getLayoutInflater(); final View view = f.createView(name, null,attrs); new Handler().post(new Runnable() { public void run() { // 设置背景图片 view.setBackgroundResource(R.drawable.upcorners_shape); } }); return view; } catch (InflateException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } } return null; } }); }
改变menu的颜色 在有些真机上试了,不行,不知道什么原因