Struts2与Struts2 NetBeans 7

发布于 2024-11-02 10:30:13 字数 430 浏览 6 评论 0原文

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

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

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

谢谢。

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.

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

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

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只怪假的太真实 2024-11-09 10:30:13

如果您熟悉在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

,您很快就会拥有一个 S2 项目。 (我使用 NB7 和 Struts2)

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

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

1) 文件>新项目,类别下:Maven >在项目下:Web 应用程序 >下一页>在“名称和位置屏幕”上按照您想要的方式填写内容...

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

现在,您应该在左侧的“项目”窗格中看到一个新项目。展开“项目文件”并打开 pom.xml。

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

找到 并将以下内容粘贴到它们之间...

<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”,展开“搜索结果”下出现的下拉菜单,然后从 ibiblio 镜像中选择“2.2.1.1”版本。

或者:您可以通过在 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

b) 按照上面的替代说明使用 GUI 添加依赖项,如下所示坐标:

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

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

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

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

>这会处理 jar 文件。

4) 添加配置文件。首先我们需要知道您的项目在磁盘上的位置。您可能已经清楚地知道这一点,如果不是右键单击项目的根目录并选择“源”下的“属性”,它会告诉我们。

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

您应该会看到一个名为“resources”的新节点。项目树下的“其他来源”。

b) 展开其他源,展开“src/main/resources”,右键单击默认包,new >其他,类别:XML,文件类型:XML 文档,然后是下一步。输入:struts(请确保不要将 .xml 放在末尾,它将为您添加),将其保留在格式良好的文档中,完成。

将 struts.xml 的内容替换为:

<?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) 添加另一个 xml 文件,就像在 b 中所做的那样,名为“log4j.xml”(记住不要在文件名中添加 .xml)。

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

<?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-INF 文件夹下创建一个名为 web.xml 的新 xml 文件。

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

    <?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”,

如果您看到一个网页显示:没有为命名空间 / 和操作名称 test 映射的操作,那么 struts2 正在处理请求。 我希望我写得正确

,如果您需要有关如何在 NB7 中向 struts2 添加 spring 或 hibernate 的说明,我当时也可以概述这些内容。

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

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

If you have any difficulties let me know.

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

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) 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.

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

Now this file explains how to build your project... to help you add dependencies we are going to tell maven about several online repositories which it may use to search for jar files

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>

Perhaps they are not all needed... but these cover all the dependency bases I have right now so they should do quite well for you. If you do not do the above step, I think you can still complete the following steps but may run into issues when adding spring and or hibernate dependencies

Save and close the file.
Now maven will handle a lot of the dependancy work for us as you'll soon see.

3)

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.

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) 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>

If you inspect your pom.xml file you'll see how the above xml was added to the pom for you.

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

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

That takes care of the jar files.

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) 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) 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.

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) 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) 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.

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>

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.

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.

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.

陌若浮生 2024-11-09 10:30:13

该插件已更新为可在 Netbeans 7.x 中使用!
http://plugins.netbeans.org/plugin/39218

the plugin have been updated to work in Netbeans 7.x!
http://plugins.netbeans.org/plugin/39218

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文