2010-01-19 2 views
5

Java EE, Spring 및 Maven (Nexus 저장소 관리자 사용)을 사용하여 Eclipse에서 샘플 동적 웹 프로젝트를 설정하려고합니다. 필자는 이클립스에서 엔터프라이즈 웹 애플리케이션 용으로 설정해야하는 "모범 사례"디렉토리 구조를 아는 사람이 있는지 궁금하다. 나에게 기본 구조 만 고수해야 하는가? 내가 인터넷 (예를 들어, WEB-INF 및 META-INF 폴더가 어디에 있는지는 'war'디렉토리 등이 있습니다.)과 관련된 다양한 변형을 보았 기 때문에 묻습니다. 감사! their convention을 따라Java EE Eclipse 프로젝트 디렉토리 구조?

+0

Eclipse를 만들려면 및 받는다는 더 나은 플레이 내가 m2eclipse에 플러그인을 다운로드 좋을 것, 그것의 업데이트 사이트는 http://m2eclipse.sonatype.org/update/ 응답에 대한 –

답변

2

당신은 메이븐을 사용하는 경우, 그것은 가장 좋습니다. 당신은 스프링을 사용하는 경우

, 당신은 EAR 필요하지 않습니다. WAR는 정상적으로 작동합니다.

WAR 파일에는 반드시 따라야 할 확실한 표준이 있습니다. 적절한 WAR 파일을 생성 할 수있는 한 소스 코드에 적합한 모든 디렉토리 구조를 사용할 수 있습니다.

나는 이런 식으로 뭔가를 사용 : 나는 인 IntelliJ를 사용

/project 
+---/src (.java) 
+---/test (TestNG .java here) 
+---/test-lib (testNG JAR, Spring test JAR, etc.) 
+---/resources (log4j.xml, etc.) 
+---/web (root of web content here) 
+---+---/WEB-INF 
+---+---+---/classes (compile .java to this directory) 
+---+---+---/lib (JAR files) 

를, 그래서 나를 위해 출력으로 분해 WAR 파일을 만듭니다.

나는 일반적으로 IntelliJ에 디렉토리 구조를 다음과 개미의 build.xml 있습니다. 도움이된다면 침대에 오신 것을 환영합니다. 당신은 메이븐을 사용하는 경우

<?xml version="1.0" encoding="UTF-8"?> 
<project name="xslt-converter" basedir="." default="package"> 

    <property name="version" value="1.6"/> 
    <property name="haltonfailure" value="no"/> 

    <property name="out" value="out"/> 

    <property name="production.src" value="src"/> 
    <property name="production.lib" value="lib"/> 
    <property name="production.resources" value="config"/> 
    <property name="production.classes" value="${out}/production/${ant.project.name}"/> 

    <property name="test.src" value="test"/> 
    <property name="test.lib" value="lib"/> 
    <property name="test.resources" value="config"/> 
    <property name="test.classes" value="${out}/test/${ant.project.name}"/> 

    <property name="exploded" value="out/exploded/${ant.project.name}"/> 
    <property name="exploded.classes" value="${exploded}/WEB-INF/classes"/> 
    <property name="exploded.lib" value="${exploded}/WEB-INF/lib"/> 

    <property name="reports.out" value="${out}/reports"/> 
    <property name="junit.out" value="${reports.out}/junit"/> 
    <property name="testng.out" value="${reports.out}/testng"/> 

    <path id="production.class.path"> 
     <pathelement location="${production.classes}"/> 
     <pathelement location="${production.resources}"/> 
     <fileset dir="${production.lib}"> 
      <include name="**/*.jar"/> 
      <exclude name="**/junit*.jar"/> 
      <exclude name="**/*test*.jar"/> 
     </fileset> 
    </path> 

    <path id="test.class.path">        
     <path refid="production.class.path"/> 
     <pathelement location="${test.classes}"/> 
     <pathelement location="${test.resources}"/> 
     <fileset dir="${test.lib}"> 
      <include name="**/junit*.jar"/> 
      <include name="**/*test*.jar"/> 
     </fileset> 
    </path> 

    <path id="testng.class.path"> 
     <fileset dir="${test.lib}"> 
      <include name="**/testng*.jar"/> 
     </fileset> 
    </path> 

    <available file="${out}" property="outputExists"/> 

    <target name="clean" description="remove all generated artifacts" if="outputExists"> 
     <delete dir="${out}" includeEmptyDirs="true"/> 
     <delete dir="${reports.out}" includeEmptyDirs="true"/> 
    </target> 

    <target name="create" description="create the output directories" unless="outputExists"> 
     <mkdir dir="${production.classes}"/> 
     <mkdir dir="${test.classes}"/> 
     <mkdir dir="${reports.out}"/> 
     <mkdir dir="${junit.out}"/> 
     <mkdir dir="${testng.out}"/> 
     <mkdir dir="${exploded.classes}"/> 
     <mkdir dir="${exploded.lib}"/> 
    </target> 

    <target name="compile" description="compile all .java source files" depends="create"> 
     <!-- Debug output 
       <property name="production.class.path" refid="production.class.path"/> 
       <echo message="${production.class.path}"/> 
     --> 
     <javac srcdir="src" destdir="${out}/production/${ant.project.name}" debug="on" source="${version}"> 
      <classpath refid="production.class.path"/> 
      <include name="**/*.java"/> 
      <exclude name="**/*Test.java"/> 
     </javac> 
     <javac srcdir="${test.src}" destdir="${out}/test/${ant.project.name}" debug="on" source="${version}"> 
      <classpath refid="test.class.path"/> 
      <include name="**/*Test.java"/> 
     </javac> 
    </target> 

    <target name="junit-test" description="run all junit tests" depends="compile"> 
     <!-- Debug output 
       <property name="test.class.path" refid="test.class.path"/> 
       <echo message="${test.class.path}"/> 
     --> 
     <junit printsummary="yes" haltonfailure="${haltonfailure}"> 
      <classpath refid="test.class.path"/> 
      <formatter type="xml"/> 
      <batchtest fork="yes" todir="${junit.out}"> 
       <fileset dir="${test.src}"> 
        <include name="**/*Test.java"/> 
       </fileset> 
      </batchtest> 
     </junit> 
     <junitreport todir="${junit.out}"> 
      <fileset dir="${junit.out}"> 
       <include name="TEST-*.xml"/> 
      </fileset> 
      <report todir="${junit.out}" format="frames"/> 
     </junitreport> 
    </target> 

    <taskdef resource="testngtasks" classpathref="testng.class.path"/> 
    <target name="testng-test" description="run all testng tests" depends="compile"> 
     <!-- Debug output 
       <property name="test.class.path" refid="test.class.path"/> 
       <echo message="${test.class.path}"/> 
     --> 
     <testng classpathref="test.class.path" outputDir="${testng.out}" haltOnFailure="${haltonfailure}" verbose="2" parallel="methods" threadcount="50"> 
      <classfileset dir="${out}/test/${ant.project.name}" includes="**/*.class"/> 
     </testng> 
    </target> 

    <target name="exploded" description="create exploded deployment" depends="testng-test"> 
     <copy todir="${exploded.classes}"> 
      <fileset dir="${production.classes}"/> 
     </copy> 
     <copy todir="${exploded.lib}"> 
      <fileset dir="${production.lib}"/> 
     </copy> 
    </target> 

    <target name="package" description="create package file" depends="exploded"> 
     <jar destfile="${out}/${ant.project.name}.jar" basedir="${production.classes}" includes="**/*.class"/> 
    </target> 

</project> 
+0

감사합니다. 그렇다면 실제로 올바른 또는 "우수 사례"구조가 없다고 말씀 하시겠습니까? – jim

+0

일반적인 합의가 없습니다. 메이븐 (Maven)은 당신에게 하나를 부과합니다. 나는 그것을 이해하지 못한다. WAR 및 EAR 파일에는 확실한 고정 요구 사항이 있지만 생성 할 수있는 한 사용자에게 적합한 방식으로 수행 할 수 있습니다. – duffymo

+0

당신은 물론 Maven을 사용할 수 있으며, 기본 설정을 무시할 수 있습니다. –

6

, 내가 따뜻하게 단지 Maven의 컨벤션을 따르도록 권하고 싶습니다. 이것은 Maven의 세계에서 "우수 사례"입니다. (그렇게하지 않을 이유가별로 없으며,이 조언을 따르지 않으면 더 많은 작업을 할 수 있습니다.)

웹 애플리케이션 프로젝트를 만들 수있는 쉬운 방법 중 하나는 받는다는 - 원형 - 웹 애플리케이션 사용하는 것입니다

:

mvn archetype:generate -DarchetypeArtifactId=maven-archetype-webapp \ 
         -DgroupId=com.mycompany.app \ 
         -DartifactId=my-webapp \ 
         -Dversion=1.0-SNAPSHOT 

이 (당신은 리눅스 쉘에서 "있는 그대로"이 명령을 붙여 넣을 수 있습니다를, 모든 것을 입력 한 Windows에서 .

my-webapp 
|-- pom.xml 
`-- src 
    `-- main 
     |-- resources 
     `-- webapp 
      |-- WEB-INF 
      | `-- web.xml 
      `-- index.jsp 

이 레이아웃은 당신이저기서하든 플러그인 이클립스 WTP (준수하십시오 "\"없이 단일 선)

는 그리고 이것은 당신이 얻을 것이다 구조입니다 g Eclipse 통합 용). 이 프로젝트를 이클립스로 가져 오면 끝이다.

더 구체적인 질문이 있으시면 (예를 들어, 대부분 META-INF 디렉토리에 대해 걱정할 필요가 없지만 실제로 필요한 경우 src/main/resources 아래에 넣으십시오).

+1

감사! "maven-archetype-webapp"사용법을 자세히 설명해 주실 수 있습니까? 이 디렉토리 구조를 자동으로 생성하는 데 사용할 수있는 도구입니까? – jim

+0

예, 원형은 "프로젝트 생성자"입니다. 사실, 나는 그것을 언급 한 직후에 명령을 썼고 획득 한 구조를 보여 주었다. 나는 이것이 분명 할 것이라고 생각했다. –

+0

Apache에서 게시 한 링크는 전체 디렉토리 구조 표준을 설명합니다. 읽어 봤니, 짐? – duffymo

관련 문제