Eclipse / JBoss Развертывание JSP - PullRequest
0 голосов
/ 20 марта 2012

Хорошо, я собираюсь ответить на вопрос о дробовике здесь. Я попытался создать базовый JSP на сервере JBoss 6.0 с Eclipse SR2. У меня есть файл JSP, Web.XML и Build.XML все ниже. Теперь имейте в виду, что Eclipse хранит WAR в C: \ JBoss \ jboss-6.0.0.Final \ server \ default \ deploy \ quote.war

Проблема в том, что файлы не отображаются на локальном хосте. Я пытаюсь разобраться в проблеме.

Итак, вот quote.jsp:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Arrays" %>
<%@ page import="java.util.Random" %>

<%
//Word up.
String[] quotes = {
"Eat my shorts!", "Cowabunga dude!","Oh snap!","Psyche!",
"Talk to the hand!","Different strokes for different folks.",
"Dont go there.","Da Bomb!",
"All that, and a bag of potato chips!"};

ArrayList<String> list = new ArrayList<String>(Arrays.asList(quotes));
Random r = new Random(); /*This creates a new random number generator.*/
int x = r.nextInt(list.size()); /*nextInt finds the next integer of the randomized number, between 0 and the integer provided, in this case, nine possible phrases.*/
String saying = (String)list.get(x); //Not sure why they felt they had to cast this as a string...
pageContext.setAttribute("saying",saying); /*Apparently takes whatever string value to be used within the scope of the HTML?*/
%>

<html>
<head>
<title>Behold! And Despair!</title>
</head>
<body>
<br>
<c:set var="sessionCount" scope="session"
value="${sessionCount +1}" />
<c:set var="applicationCount" scope="application"
value="${applicationCount +1}" />
<h1>
<font color="#1230cb">Catchphrases You Wish Time Forgot</font>
</h1>
<h3>
<br>
<font color="#a6a6a6">
${saying}
<br>-your Childhood
</font>
</h3>
<br><br>
You've visited this application ${sessionCount}
times this session. Perhaps its time to get a life.
<br>
Also, this application has been visited ${applicationCount}
by you and others who also have no social outlet.
</body>
</html>

Вот файл web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/j2ee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>QuoteServlet</servlet-name>
<jsp-file>/quote.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>QuoteServlet</servlet-name>
<url-pattern>/quote</url-pattern>
</servlet-mapping>
</web-app>

И, наконец, build.xml:

    <project name="quote" basedir="../" default="deploy">

    <!-- Project settings -->
    <property name="project.distname" value="quote"/>

    <!-- Local system paths -->
    <property file="${basedir}/ant/build.properties"/>
    <property name="webroot.dir" value="${basedir}\WebContent"/>
    <property name="webinf.dir" value="${webroot.dir}\WEB-INF"/>
    <property name="build.dir" value="build"/>

    <!-- classpath for JSF 1.1.01 -->
    <path id="compile.classpath">
        <pathelement path ="${webinf.dir}/lib/commons-beanutils.jar"/>
        <pathelement path ="${webinf.dir}/lib/commons-collections.jar"/>
        <pathelement path ="${webinf.dir}/lib/commons-digester.jar"/>
        <pathelement path ="${webinf.dir}/lib/commons-logging.jar"/>
        <pathelement path ="${webinf.dir}/lib/jsf-api.jar"/>
        <pathelement path ="${webinf.dir}/lib/jsf-impl.jar"/>
        <pathelement path ="${webinf.dir}/lib/jstl.jar"/>
        <pathelement path ="${webinf.dir}/lib/standard.jar"/>
        <pathelement path ="${webinf.dir}/classes"/>
        <pathelement path ="${classpath.external}"/>
        <pathelement path ="${classpath}"/>
    </path>

    <!-- define your folder for deployment -->
    <property name="deploy.dir" value="deploy"/>


    <!-- Check timestamp on files -->
    <target name="prepare">
        <tstamp/>
    </target>

    <!-- Copy any resource or configuration files -->
    <target name="resources">
        <copy todir="${webinf.dir}/classes" includeEmptyDirs="no">
            <fileset dir="JavaSource">
            <patternset>
                <include name="**/*.conf"/>
                <include name="**/*.properties"/>
                <include name="**/*.xml"/>
            </patternset>
            </fileset>
        </copy>
    </target>

    <!-- Normal build of application -->
    <target name="compile" depends="prepare,resources">
        <javac srcdir="JavaSource" destdir="${webinf.dir}/classes">
            <classpath refid="compile.classpath"/>
        </javac>
    </target>

    <!-- Remove classes directory for clean build -->
    <target name="clean"
      description="Prepare for clean build">
      <delete dir="${webinf.dir}/classes"/>
      <mkdir  dir="${webinf.dir}/classes"/>
    </target>

    <!-- Build entire project -->
    <target name="build" depends="prepare,compile"/>
    <target name="rebuild" depends="clean,prepare,compile"/>

    <!-- Create binary distribution -->
    <target name="war" depends="build">
      <mkdir dir="${build.dir}"/>
      <war
        basedir="${webroot.dir}"
        warfile="${build.dir}/${project.distname}.war"
        webxml="${webinf.dir}\web.xml">
        <exclude name="WEB-INF/${build.dir}/**"/>
        <exclude name="WEB-INF/src/**"/>
        <exclude name="WEB-INF/web.xml"/>
       </war>

    </target>

    <target name="deploy" depends="war">
       <delete file="${deploy.dir}/${project.distname}.war"/>
       <delete dir="${deploy.dir}/${project.distname}"/>
       <copy file="${build.dir}/${project.distname}.war" todir="${deploy.dir}"/>
    </target>

</project>

Извините за то, что я здесь беспорядок. Но совет был бы оценен.

1 Ответ

0 голосов
/ 20 марта 2012

Предполагается, что вы развернули свой военный файл в

C:\JBoss\jboss-6.0.0.Final\server\default\deploy\quote.war

и запустил профиль JBoss по умолчанию

C:\JBoss\jboss-6.0.0.Final\bin\run.bat

и НЕ вижу ошибок в вашем лог-файле

C:\JBoss\jboss-6.0.0.Final\server\default\log\server.log

Вы должны увидеть развернутое приложение и получить к нему доступ, используя http://localhost:8080/quote.jsp или http://localhost:8080/quote/quote.jsp

Надеюсь, это поможет.

Удачи!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...