Struts2 &NetBeans 7 [英] Struts2 & NetBeans 7

查看:22
本文介绍了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 支持

谢谢.

推荐答案

如果您熟悉在 NB 中使用 maven 只需关注 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

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 项目.(我在 Struts2 中使用 NB7)

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 文件

找到 之间的空行,然后在它们之间粘贴以下内容...

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) 接下来,在我们的项目树下,右键单击依赖项文件夹:在查询字段中输入: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.

或者:您可以通过在 Group ID、Artifact ID 和 Version 字段(在 maven 中称为坐标)中输入正确的值来完成 (a).您应该知道正确的值,因为 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步骤 3

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.

您应该在项目树下看到一个名为Other Sources"的新节点.

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

b) 展开Other Sources,展开src/main/resources",右键点击默认包,new > other,Categories:XML,File Types: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 中所做的那样,添加另一个名为log4j.xml"的 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 Pages"节点,如果不存在则创建一个名为WEB-INF"的文件夹.在名为 web.xml 的 WEB-INF 文件夹下创建一个新的 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 应用程序 并且什么都不做,只是点击了运行按钮,您会看到相同的页面,您需要做的是输入一个 不存在,例如在您的操作末尾输入test".

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 &amp;NetBeans 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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