您的位置:资讯频道 > 技术文档 > Java组件开发

让你用seam new-project创建的项目也能用上JBossTools的功能

来源:博客   作者:邓胤   时间:2008-04-10  点击:198 次
      我们可以用jbosstools直接创建Seam的项目,但是我试了创建war项目还好,创建ear项目的话, 创建出来的都是不能编译的, 而且发布到Jboss deploy目录也是不合法的ear布局。 这些问题虽然可以通过手工修改来解决。但是我觉得还是用seam new-project创建出来的项目结构好很多,而且有很好的ant脚本。可以很方便的执行各种任务,而且我看到seam论坛上有人就说用jbosstools创建的seam的ear项目其实有4个项目(大家可以试试)。 他更喜欢seam new-project创建出来的一种目录的形式。就只有一个目录,用svn也更方便。

  Seam2.0.1, JbossTools2.0.0GA(现在已经出了2.0.1GA,请看我在javaeye上发的新闻http://www.javaeye.com/news/1554)。

  安装好JbossTools后, 你需要在eclipse中设置你的Seam的home。



  用seam创建你的项目。请看。http://docs.jboss.com/seam/2.0.1.GA/reference/en/html/gettingstarted.html#d0e2146

  创建玩项目后用eclipse把刚创建的项目导入到eclipse中。File->Import->General->Existed projects into Workspace. 导入后你可能会发现有编译错误。 这个是因为eclipse把这个项目的java compiler设到了1.4. 我们把这个改成5.0就行了。



  Jbosstools最好的一项功能是它能自动的识别出项目中所有的component。这个在写xhtml非常方便。而且还能在xhtml中跳转到java code。 更多的jbosstools的功能请看。http://in.relation.to/Bloggers/JBossToolsScreenshots

  我们在eclipse中打开Seam Component, Window->Show View->Other->Seam->Seam Component.

  我们发现我们刚刚导入的sample项目找不到任何的compoent。Order是我用Jbosstools创建的一个war seam项目。



  OK,打开你的.project文件,加入以下的代码。 (不要告诉我你不知道.project在哪里,是干什么用的。)

Xml代码
<buildCommand>
 <name>org.jboss.tools.common.verification.verifybuilder</name>
 <arguments>
 </arguments>
</buildCommand>
<buildCommand>
 <name>org.jboss.tools.seam.core.seambuilder</name>
 <arguments>
 </arguments>
</buildCommand>

<buildCommand>
 <name>org.jboss.tools.common.verification.verifybuilder</name>
 <arguments>
 </arguments>
</buildCommand>
<buildCommand>
 <name>org.jboss.tools.seam.core.seambuilder</name>
 <arguments>
 </arguments>
</buildCommand>

加入之后的.project应该是这样的。

Xml代码
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
 <name>sample</name>
 <comment></comment>
 <projects>
 </projects>
 <buildSpec>
 <buildCommand>
  <name>org.eclipse.jdt.core.javabuilder</name>
  <arguments>
  </arguments>
 </buildCommand>
 <buildCommand>
  <name>org.jboss.tools.common.verification.verifybuilder</name>
  <arguments>
  </arguments>
 </buildCommand>
 <buildCommand>
  <name>org.jboss.tools.seam.core.seambuilder</name>
  <arguments>
  </arguments>
 </buildCommand>
 <buildCommand>
  <name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
  <triggers>auto,full,incremental,</triggers>
  <arguments>
  <dictionary>
   <key>LaunchConfigHandle</key>
   <value><project>/explode.launch</value>
  </dictionary>
  </arguments>
 </buildCommand>
 </buildSpec>
 <natures>
  <nature>org.eclipse.jdt.core.javanature</nature>
  <nature>org.hibernate.eclipse.console.hibernateNature</nature>
  <nature>org.jboss.tools.seam.core.seamnature</nature>
 </natures>
</projectDescription>

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
 <name>sample</name>
 <comment></comment>
 <projects>
 </projects>
 <buildSpec>
 <buildCommand>
  <name>org.eclipse.jdt.core.javabuilder</name>
  <arguments>
  </arguments>
 </buildCommand>
 <buildCommand>
  <name>org.jboss.tools.common.verification.verifybuilder</name>
  <arguments>
  </arguments>
 </buildCommand>
 <buildCommand>
  <name>org.jboss.tools.seam.core.seambuilder</name>
  <arguments>
  </arguments>
 </buildCommand>
 <buildCommand>
  <name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
  <triggers>auto,full,incremental,</triggers>
  <arguments>
  <dictionary>
   <key>LaunchConfigHandle</key>
   <value><project>/explode.launch</value>
  </dictionary>
  </arguments>
 </buildCommand>
 </buildSpec>
 <natures>
  <nature>org.eclipse.jdt.core.javanature</nature>
  <nature>org.hibernate.eclipse.console.hibernateNature</nature>
  <nature>org.jboss.tools.seam.core.seamnature</nature>
 </natures>
</projectDescription>

OK, 再看下Seam Component, 现在已经可以找到所有的seam component了。



随便写个seam compoenent。
Java代码
import org.jboss.seam.annotations.Name;

@Name("testELExpression")
public class TestElExpression {
 public String getName() {
  return "deng.yin@gmail.com";
 }

 public void doListener() {

 }
}

import org.jboss.seam.annotations.Name;

@Name("testELExpression")
public class TestElExpression {
 public String getName() {
  return "deng.yin@gmail.com";
 }

 public void doListener() {

 }
}

已经有提示了。