Appfuse安装配置
一、软件准备
JDK 1.4.2
Appfuse 1.8 http://www.appfuse.org/
Tomcat 5.0.30 http://jakarta.apache.org/tomcat
Ant 1.6.5 http://ant.apache.org
MySQL 5.0.24 http://www.mysql.com
二、环境设置
ANT_HOME
JAVA_HOME
CATALINA_HOME
MYSQL_HOME
Path中加入%JAVA_HOME%\bin;%ANT_HOME%\bin;%CATALINA_HOME%\bin;%MYSQL_HOME%\bin;
三、在Eclipse中使用Ant编译
1、Create New Java Project in Eclipse
Open Eclipse (either with an existing or a new workspace) and to go File → New → Project. Then select "Java Project" and hit the Next button. In the Project Name field, enter the name of your project (i.e. appfuse) and the directory that your project lives (i.e. c:\source\appfuse) in the box below. If you're prompted to switch the Java Perspective, choose Yes.
If you try to build the project at this point, you'll likely get numerous errors. Most of them involve the fact that the UserForm class can not be found. This is because all of the ActionForms in AppFuse (if you're using the Struts version) are generated from POJOs with XDoclet.
All of the tasks for XDoclet are configured in the Ant build.xml file so the easiest thing to do is to run "ant gen-forms" to generate the ActionForms. If you have Ant 1.6.2+ installed and in your path, you can do this from the command line. The next step shows you how configure Eclipse to run your AppFuse build.xml.
2、Configuring Ant in Eclipse
The easiest way to configure Eclipse for AppFuse is to install Ant on your hard drive (i.e. c:\Tools\apache-ant-1.6.2) and then point Eclipse's ANT_HOME to this directory. To do this, go to Window → Preferences → Ant → Runtime. Then click the "Ant Home" button and select the installation folder on your hard drive.
If you'd rather use Eclipse's built-in Ant, you'll need to add junit.jar to its classpath. To do this, go to Window → Preferences → Ant → Runtime. Then click the "Add JARs" button and select junit.jar from appfuse/lib/junit3.8.1/lib/junit.jar. Click OK until you arrive back at the workbench view.
Next, add the catalina-ant.jar (from $CATALINA_HOME/server/lib) to the ant classpath. Then in the property tab, add tomcatTasks.properties (in lib/ant-contrib) file as a global properties file.
3、Add build.xml to Ant View
Now we need to add the build.xml to Eclipse's Ant View. To do this, go to Window → Show View → Ant. Then click on the first icon in this view (screenshot below) to add AppFuse's build file.
4、Run Ant
After adding the build.xml, you should be able to expand it in the Ant View and execute any of the targets. I usually do "test-all" to verify all the tests pass in my initial project. For a list of targets I use most often, see AppFuse Ant Targets.
Now if you run the "compile" target and then refresh the project (right-click on project → Refresh) you shouldn't see any errors in the "Problems" pane. You should now be able to compile and create classes as you normally would. Sometimes when my imports aren't resolving correctly in Eclipse, I do have to run Project → Clean in Eclipse.
注:其实在Eclipse中已经自带了Ant 1.6.5,所以Run的时候主要注意junit.jar和catalina-ant.jar就可以了
NOTE: If you're using the internal version of Ant, you may get an error message like the one below:
BUILD FAILED: C:\source\appfuse\build.xml:802: The following error occurred while executing this line:
C:\source\appfuse\build.xml:780: The following error occurred while executing this line:
java.lang.NoClassDefFoundError: org/apache/xml/serialize/OutputFormat
This is because there are tasks that require Xerces to be in your Ant classpath [reference]. I added xercesImpl.jar and xml-apis.jar (from my self-installed version of Ant) to Eclipse's Ant classpath to solve this.
5、Run JUnit Tests in Eclipse
It's also possible to run your JUnit tests in Eclipse. But before running them, you need to run the "war" target. After this target completes, refresh your project.
After you have successfully done so, in Eclipse open a test you'd like to run (i.e. UserDaoTest) and go to Run → Debug As →JUnit Test. Note that you may have to run the "db-load" target before you run your tests every so often. I did have the following method in the Base*TestCase class for each layer, but this caused DBUnit to reload the database before every test in a Test class. Removing it reduces the execution time of "test-all" by more than 30 seconds.
protected void setUp() throws Exception {
DataSource ds = (DataSource) ctx.getBean("dataSource");
IDatabaseConnection conn = new DatabaseConnection(ds.getConnection());
IDataSet dataSet =
new XmlDataSet(new FileInputStream("metadata/sql/sample-data.xml"));
// clear table and insert only sample data
DatabaseOperation.CLEAN_INSERT.execute(conn, dataSet);
conn.close();
}
If the instructions above don't work for running JUnit tests in Eclipse, I suggest just using the command line - i.e. ant test-dao -Dtestcase=UserDAO. Running tests from the command line always works. ;-)
6、在tomcat中部署(第5步中有些需要注意的写在这里了)
修改properties.xml中的mysql的配置,主要是用户名和密码。然后执行db-prepare建立数据表。然后执行db-load建立数据。再接着执行deploy-web就可以在${env.CATALINA_HOME}下看到要部署的三个文件夹:common,conf,webapps,考到tomcat下。这时运行还会报缺一个javax.transaction.TransactionManager,把jta.jar考到lib下。还有WARN~~~~@!$$@$@!,不过还好,能看见登录界面了。
在Eclipse中test-dao会看到[dbunit] WARNING - app_user.enabled data type (1111, ?bit?) notrecognized and will be ignored的错误,这个是mysql 驱动程序的错误引起的.解决方法有二.第一是按照http://issues.appfuse.org/browse/APF-148提出的方法修改程序.另外也可以采用mysql的nightly build的驱动,替换appfuse自带的驱动来解决。换驱动的时候修改lib\lib.properties文件中的mysql version号,引入mysql 5.0.3的驱动,之后,这个错误解决。test-dao成功.但是...还是登录不了:<
在properties.xml中注意到tomcat的端口是8080(我的tomcat改成80口了),好,改回来。然后把tomcat-user.xml中的admin的用户名和密码修改为properties.xml中的admin,admin,ok,启动tomcat,登录,哈哈,终于进去了。

浙公网安备 33010602011771号