1

我對IntellijIdea是全新的,我正在尋找一些分步過程來設置基本項目。Maven + Jaxb項目入門+ IntellijIdea

我的項目依賴於Maven + Jaxb類,所以我需要一個Maven項目,這樣當我編譯這個項目時,JAXB對象由Maven插件生成。現在,我開始喜歡這個

  1. 我創建了一個空白的項目說瑪雅項目
  2. 新增的Maven模塊它
  3. 添加在pom.xml中以下設置
<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
      http://maven.apache.org/xsd/maven-4.0.0.xsd"> 

    <modelVersion>4.0.0</modelVersion> 

    <groupId>MaJa</groupId> 
    <artifactId>MaJa</artifactId> 
    <version>1.0</version> 

    <dependencies> 
     <dependency> 
      <groupId>javax.xml.bind</groupId> 
      <artifactId>jaxb-api</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>com.sun.xml.bind</groupId> 
      <artifactId>jaxb-impl</artifactId> 
      <version>2.1</version> 
     </dependency> 
    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>jaxb2-maven-plugin</artifactId> 
       <executions> 
        <execution> 
         <goals> 
          <goal>xjc</goal> 
         </goals> 
        </execution> 
       </executions> 
       <configuration> 
        <schemaDirectory>${basedir}/src/main/resource/api/MaJa</schemaDirectory> 
        <packageName>com.rimt.shopping.api.web.ws.v1.model</packageName> 
        <outputDirectory>${build.directory}</outputDirectory> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
</project> 
  1. 第一所有,這是正確的設置?

  2. 我嘗試點擊項目>右鍵菜單中的Make/Compile'MaJa',它沒有做任何事情。

我會期待yoru的回覆。

回答

1

必須單擊不Make/Compile 'MaJa'
1)你必須在這裏(不小於Compile)選擇Maven構建生命週期階段的一個。
2)將路徑設置爲maven。
3)添加版本jaxb-api神器

enter image description here

我添加shiporder.xsd到目錄/src/main/resource/api/MaJa併產生良好

[jaxb2:xjc] 
Generating source... 
parsing a schema... 
compiling a schema... 
com\rim\shopping\api\web\ws\v1\model\ObjectFactory.java 
com\rim\shopping\api\web\ws\v1\model\Shiporder.java 
+0

優秀的Java類。儘管我遇到了Maven抱怨1.3版不支持註釋的問題。所以我說以下設置'行家編譯-插件<結構> 1.7 1.7' **現在一個問題**應我生成在類(.java文件) '$ {build.directory}'或者它應該放在'$ {build.sourceDirectory}'中。只是想確認,因爲你沒有指出。 –

+0

它們應該位於'$ {build.directory}'中,因爲如果我將它們保存在build.directory中,它們必須被刪除並重新生成每個新的版本 – Ilya

+0

,那麼IDE將無法看到這些文件,因爲它們不是' t在'src'目錄下,因此寫代碼時自動完成/錯誤是不可能的。不知道,還沒有嘗試過,但你知道我在說什麼? –