Struts2和NetBeans 7 [英] Struts2 & NetBeans 7

查看:94
本文介绍了Struts2和NetBeans 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在任何地方都找不到对NetBeans 7的ngbit支持.我必须为Web应用程序开发安装Struts2.对于NetBeans 6.9,我的较旧版本的ngbit 0.4可以正常工作,但对于NetBeans 7不起作用.由于HTML5,我需要NetBeans 7.

I cannot find anywhere ngbit support for NetBeans 7. I have to install Struts2 for my Web Applications development. For NetBeans 6.9 my older version of ngbit 0.4 works fine, but for NetBeans 7 doesn't work. I need NetBeans 7 because of HTML5.

当我尝试安装 org-netbeans-modules-web-frameworks-struts2.nbm 时,NetBeans出现以下错误:

When I try to install org-netbeans-modules-web-frameworks-struts2.nbm, NetBeans gives the following error:

某些插件需要安装插件编辑器库. 在版本> = 2.10.1.10.2(发行版2)中请求插件编辑器库,但仅找到3.8.1.13.8(发行版与2不同).
以下插件受到影响: Struts2支持

Some plugins require plugin Editor Library to be installed. The plugin Editor Library is requested in version >= 2.10.1.10.2 (release version 2) but only 3.8.1.13.8 (of release version different from 2) was found.
The following plugin is affected:        Struts2 Support

谢谢.

推荐答案

如果您熟悉NB中的Maven,请遵循

If you're familiar with using maven in NB just follow http://struts.apache.org/2.2.1.1/docs/create-struts-2-web-application-using-maven-to-manage-artifacts-and-to-build-the-application.html

,您将立即拥有一个S2项目. (我将NB7与Struts2一起使用)

and you'll have a S2 project in no time. (I'm using NB7 with Struts2)

如果您有任何困难,请告诉我.

If you have any difficulties let me know.

编辑:如何使用Netbeans 7 GUI创建新的Struts2 Maven Web应用程序.

Edit: How to create a new Struts2 Maven Web Application with the Netbeans 7 GUI.

1)文件>新建项目,在类别下:Maven>在项目下:Web应用程序>下一步>在名称和位置屏幕"上以所需方式填写内容...

1) File > New Project, Under Categories: Maven > Under Projects : Web Application > Next > On "Name and Location Screen" fill out things the way you want...

2)编辑:随着在线存储库状态的更新,您此时无需添加任何其他存储库,请跳至#3 .如果有人需要,我将保留以下内容作为参考.

2) Edit: With updates to the state of the online repositories, you should not need to add any further repositories at this time, please skip to #3. I will leave the following as a reference should someone need it.

现在,在左侧,您应该在项目"窗格中看到一个新的项目.展开项目文件",然后打开pom.xml.

Now on the left hand side you should see a new Project in the "Projects" pane. Expand "Project Files" and open pom.xml.

现在此文件说明了如何构建项目...以帮助您添加依赖项,我们将告诉Maven一些可用于搜索jar文件的在线存储库

</properties><dependencies>之间找到空白行,并将以下内容粘贴在它们之间...

Locate the blank line between </properties> and <dependencies> and paste the following in between them...

<repositories>
    <repository>
        <id>JBoss Repo</id>
        <url>http://repository.jboss.com/maven2</url>
        <name>JBoss Repo</name>
    </repository>
    <repository>
        <id>ibiblio mirror</id>
        <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
    </repository>
    <repository>
        <id>jboss-public-repository-group</id>
        <name>JBoss Public Maven Repository Group</name>
        <url>https://repository.jboss.org/nexus/content/groups/public/</url>
        <layout>default</layout>
        <releases>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
        </releases>
        <snapshots>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
        </snapshots>
    </repository>
    <repository>
        <url>http://ftp.ing.umu.se/mirror/eclipse/rt/eclipselink/maven.repo</url>
        <id>eclipselink</id>
        <layout>default</layout>
        <name>Repository for library Library[eclipselink]</name>
    </repository>
</repositories>

也许它们并不需要全部...但是这些覆盖了我现在拥有的所有依赖关系库,因此它们应该为您做得很好.如果您不执行上述步骤,我认为您仍然可以完成以下步骤,但是在添加spring和hibernate依赖项时可能会遇到问题

保存并关闭文件. 现在,maven将为我们处理很多依赖工作,就像您很快就会看到的那样.

3)

a)接下来,在我们的项目树下,右键单击"dependencies"文件夹:在查询"字段中输入:"struts2-core",展开将出现在搜索结果"下的下拉列表,然后选择"2.2.1.1"版本来自ibiblio镜子.

a) Next under our project tree, right click the dependencies folder: In the Query field enter: "struts2-core", expand the drop down which will appear under "Search Results" and select the "2.2.1.1" version from the ibiblio mirror.

或者:您可以通过在组ID",工件ID"和版本"字段(在maven中称为坐标)中输入正确的值来完成(a)的操作.您应该知道正确的值,因为

Alternatively: You could have done (a) from above by entering the correct values into the Group ID, Artifact ID, and Version fields (known in maven speak as co-ordinates). You should know the correct values because the are spelled out on http://struts.apache.org/2.2.1.1/docs/create-struts-2-web-application-using-maven-to-manage-artifacts-and-to-build-the-application.html under Step 3

b)按照上述替代说明使用gui添加具有以下坐标的依赖项:

b) Follow the alternative instructions above to use the gui to add a dependency with the following co-ordinates:

<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.8.0.GA</version>
</dependency>

如果检查pom.xml文件,您将看到如何将上述xml添加到pom中.

c)现在您是添加依赖项添加的专家:

c) Now you're an expert at adding dependencies add:

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>

这将负责jar文件.

4)添加配置文件.首先,我们需要知道您的项目在磁盘上的位置.您可能已经知道了这一点,如果不是这样,请右键单击项目的根目录,然后在源"下选择属性",它将告诉我们.

4) Adding the configuration files. First we need to know where your project is on disk. You might already know this off the top of your head, if not right click the root of your project and select "properties" under "sources" it will tell us.

a)在Netbeans外部,使用操作系统文件导航器进入项目的根目录.打开 src/main 文件夹,您应该在此处看到"java"和"webapp"文件夹,创建一个名为"resources"的新文件夹,然后返回到Netbeans 7.

a) Outside Netbeans using your operating systems file navigator go into the root of your project. Open the src/main folders here you should see the "java" and "webapp" folders, create a new folder called "resources" and then go back into Netbeans 7.

您应该在项目树下看到一个名为其他来源"的新节点.

You should see a new node called "Other Sources" under your project tree.

b)展开 Other Sources ,展开"src/main/resources",右键单击默认包 new> other ,类别:XML,文件类型:XML文档,然后下一个.输入:struts(请确保不要将.xml末尾添加到您的文件中),将其保留在格式正确的文档上,结束.

b) Expand Other Sources, expand "src/main/resources", right click the default package, new > other, Categories: XML, File Types: XML Document, then next. Enter: struts (be sure not to put .xml on the end it will be added for you), leave it on well formed document, finish.

将struts.xml的内容替换为:

Replace the contents of struts.xml with:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
  <constant name="struts.devMode" value="true" />
</struts>

c)像在b中一样添加另一个xml文件,称为"log4j.xml"(切记不要在文件名中添加.xml).

c) Add another another xml file as you did in b called "log4j.xml" (remember not to add the .xml in the filename).

将以下内容粘贴到该文件中:

Paste the following into that file:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration PUBLIC "-//log4j/log4j Configuration//EN" "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

    <appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
       <layout class="org.apache.log4j.PatternLayout"> 
          <param name="ConversionPattern" value="%d %-5p %c.%M:%L - %m%n"/> 
       </layout> 
    </appender>

    <!-- specify the logging level for loggers from other libraries -->
    <logger name="com.opensymphony">
        <level value="DEBUG" />
    </logger>

    <logger name="org.apache.struts2">
         <level value="DEBUG" />
    </logger>

   <!-- for all other loggers log only info and above log messages -->
     <root>
        <priority value="INFO"/> 
        <appender-ref ref="STDOUT" /> 
     </root> 

</log4j:configuration> 

d)配置web.xml,在项目根目录下,展开网页"节点,并创建一个名为"WEB-INF"的文件夹(如果不存在).在WEB-INF文件夹下创建一个新的xml文件,名为web.xml.

d) Configure web.xml, under the project root, expand the "Web Pages" node, create a folder called "WEB-INF" if it does not exist. Create a new xml file under the WEB-INF folder called web.xml.

将以下内容粘贴到web.xml文件中:

Paste the following into the web.xml file:

    <?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

最终测试:现在,您应该可以单击运行按钮,选择您喜欢的Web服务器(tomcat或glassfish),然后看到hello world页面.听起来像成功.但这还没有(如果您创建了一个新的 Maven Web应用程序,并且只执行了一次运行按钮,您将看到同一页面,那么您要做的就是输入一个不存在,例如在操作结束时输入测试".

Final Test: Now you should be able to hit the run button select your preferred web server (tomcat or glassfish) and see the hello world page... Sounds like success. But it isn't yet (if you created a new Maven Web Application and did nothing but hit the run button you'd see the same page, what you need to do is enter a url that does not exist such as entering "test" onto the end of your action.

如果您看到一个网页,则说:没有为名称空间/和操作名称测试映射任何操作.然后struts2正在处理请求,我们知道一切都很好.

If you get a web page saying: There is no Action mapped for namespace / and action name test. Then struts2 is handling the requests and we know all is well.

我希望我能正确地写出来,如果您需要有关如何在NB7的struts2中添加spring或hibernate的说明,那时候我也可以概述一下.

I hope I wrote this out correctly, if you need instruction on how to add spring or hibernate to struts2 in NB7 I could outline those too at that time.

这篇关于Struts2和NetBeans 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆