Projekt-Dokumentation (Aktueller Stand von juplo.de) hinzugefĆ¼gt
[website] / dist / hibernate4-maven-plugin-1.0.3 / configuration.html
1 <!DOCTYPE html>
2 <!-- Generated by Apache Maven Doxia Site Renderer 1.4 at 2013-12-16 -->
3                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       <!-- Current: configuration.html -->
4 <!-- Active: index.html -->
5 <!-- Path: [index.html, configuration.html] -->
6 <!-- Skiplist: [index.html, configuration.html, export-mojo.html, debugging.html, skip.html, force.html, pitfalls.html] -->
7 <html>
8   <head>
9     <title>juplo - Hibernate 4 Maven Plugin - Configuration Examples</title>
10     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
11     <link rel="canonical" href="http://juplo.de/hibernate4-maven-plugin/configuration.html"/>
12     <link rel="stylesheet" type="text/css" href="/css/base.css" />
13     <style type="text/css">
14       @import '/css/screen.css' screen and (min-width: 960px);
15       @import '/css/phone.css' screen and (max-width: 599px);
16       @import '/css/tiny.css' screen and (max-width: 399px);
17     </style>
18     <script src="/js/base.js"></script>
19     <!--[if IE 8]>
20       <script src="/js/ie8.js"></script>
21     <![endif]-->
22     <!--[if IE 7]>
23       <script src="/js/ie7.js"></script>
24     <![endif]-->
25     <!--[if lt IE 7]>
26       <script src="/js/ie6.js"></script>
27     <![endif]-->
28     <meta name="author" content="Kai Moritz" />
29     <meta name="Date-Revision-yyyymmdd" content="20131216" />
30     <meta http-equiv="Content-Language" content="en" />
31         
32   </head>
33   <body onload="prettyPrint()">
34     <div id="page">
35       <header id="header">
36         <a href="/" title="Home" id="logo">juplo</a>
37         <span id="slogan"><strong>Java</strong> bits from nerds for nerds</span>
38         <hr class="h" />
39       </header>
40       <div id="breadcrumb">
41         <strong class="b title">You are here:</strong>
42         <ol class="b">
43           <li class="b"><a class="b" href="/">Home</a></li>
44           <li class="b"><a class="b" href="/projects.html">Projects</a></li>
45                       <li class="b"><a class="b" href="./index.html">Hibernate 4 Maven Plugin</a </li>
46                         <li class="b"><strong class="b">Configuration Examples</strong></li>
47                   </ol>
48         <a class="hide" href="#navigation">Jump to navigation</a>
49         <div class="b"></div>
50       </div>
51       <div class="fc cols_2">
52         <div class="content cf">
53           <section id="content" class="main">
54             <h1>Hibernate 4 Maven Plugin - Configuration Examples</h1>
55             <div class="section">
56 <h2>Configuration through a hibernate.properties-File<a name="Configuration_through_a_hibernate.properties-File"></a></h2>
57 <p>The most simple way to configure the plugin is, to put all the hibernate-configuration in a <b>hibernate.properties</b>-file on your classpath. Put the file in the <tt>resources</tt>-folder. Maven will put it in the <tt>class</tt>-folder of your webapp, where it will be picked up by this plugin as well as by Hibernate 4.</p>
58 <p>Doing so, the only additionally configuration needed, to activat the plugin is the following entry in the <tt>plugins</tt>-section of your <tt>pom.xml</tt>:</p>
59 <div>
60 <pre>&lt;plugin&gt;
61   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
62   &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
63   &lt;version&gt;${project.version}&lt;/version&gt;
64   &lt;executions&gt;
65     &lt;execution&gt;
66       &lt;goals&gt;
67         &lt;goal&gt;export&lt;/goal&gt;
68       &lt;/goals&gt;
69     &lt;/execution&gt;
70   &lt;/executions&gt;
71 &lt;/plugin&gt;</pre></div>
72 <p>But be aware, that in this case the database-url, that is build in the application is the same that is used while testing, where the database is droped and recreated by the plugin. <tt>So, you should never fire up this configuration on your production system, or your database might be erased!</tt></p>
73 <p>Hence, you should specify a different url for testing like in the following snippet:</p>
74 <div>
75 <pre>&lt;plugin&gt;
76   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
77   &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
78   &lt;version&gt;${project.version}&lt;/version&gt;
79   &lt;executions&gt;
80     &lt;execution&gt;
81       &lt;goals&gt;
82         &lt;goal&gt;export&lt;/goal&gt;
83       &lt;/goals&gt;
84     &lt;/execution&gt;
85   &lt;/executions&gt;
86   &lt;configuration&gt;
87     &lt;url&gt;&lt;![CDATA[jdbc:mysql://localhost/test-db]]&gt;&lt;/url&gt;
88   &lt;/configuration&gt;
89 &lt;/plugin&gt;</pre></div>
90 <p>Configuration properties, that are set in the <tt>configuration</tt>-section of the plugin-configuration cannnot be overwritten elsewere (for details see <a href="#Configuration-Method-Precedence">Configuration-Method-Precedence</a>). You never can overwrite them by accident when specifying a property on the commandline or in your <tt>settings.xml</tt>.</p></div>
91 <div class="section">
92 <h2>Configuration through maven-properties<a name="Configuration_through_maven-properties"></a></h2>
93 <p>Alternatively, it is possible, to configure the plugin via maven-properties. Each relevant configuration-option has a corresponding maven-property (for a full list see the <a href="./export-mojo.html"> Documentation of the export-Mojo</a>). These are named after the <a class="externalLink" href="http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#configuration-hibernatejdbc"> Hibernate JDBC Properties</a>:</p>
94 <ul>
95 <li><tt>hibernate.connection.driver_class</tt></li>
96 <li><tt>hibernate.dialect</tt></li>
97 <li><tt>hibernate.connection.url</tt></li>
98 <li><tt>hibernate.connection.username</tt></li>
99 <li><tt>hibernate.connection.password</tt></li></ul>
100 <p>So, instead of writing the hibernate-configuration in the properties-file, like above, you could put it in the <tt>properties</tt>-section of your <tt>pom.xml</tt>.</p>
101 <p>Thogether with the plugin-definition from above, the following would be a complete configuration (again, the database-url was overwritten in the plugin-configuration, to be sure to have a separate database for testing):</p>
102 <div>
103 <pre>&lt;properties&gt;
104   &lt;hibernate.connection.driver_class&gt;org.hsqldb.jdbcDriver&lt;/hibernate.connection.driver_class&gt;
105   &lt;hibernate.dialect&gt;org.hibernate.dialect.HSQLDialect&lt;/hibernate.dialect&gt;
106   &lt;hibernate.connection.url&gt;&lt;![CDATA[jdbc:hsqldb:res:org.my.path.production_db]]&gt;&lt;/hibernate.connection.url&gt;
107   &lt;hibernate.connection.username&gt;sa&lt;/hibernate.connection.username&gt;
108   &lt;hibernate.connection.password&gt;&lt;/hibernate.connection.password&gt;
109 &lt;/properties&gt;
110
111 ...
112
113 &lt;plugins&gt;
114
115   ...
116
117   &lt;plugin&gt;
118     &lt;groupId&gt;de.juplo&lt;/groupId&gt;
119     &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
120     &lt;version&gt;${project.version}&lt;/version&gt;
121     &lt;executions&gt;
122       &lt;execution&gt;
123         &lt;goals&gt;
124           &lt;goal&gt;export&lt;/goal&gt;
125         &lt;/goals&gt;
126       &lt;/execution&gt;
127     &lt;/executions&gt;
128     &lt;configuration&gt;
129       &lt;url&gt;&lt;![CDATA[jdbc:hsqldb:target/db/testdb;shutdown=true]]&gt;&lt;/url&gt;
130     &lt;/configuration&gt;
131   &lt;/plugin&gt;
132
133 &lt;plugins&gt;</pre></div></div>
134 <div class="section">
135 <h2>Configuration through the plugin-configuration<a name="Configuration_through_the_plugin-configuration"></a></h2>
136 <p>A third way for configuring the plugin is the plugin-configuration. The relevant configuration-parameters are:</p>
137 <ul>
138 <li><tt>driverClassName</tt></li>
139 <li><tt>hibernateDialect</tt></li>
140 <li><tt>url</tt></li>
141 <li><tt>username</tt></li>
142 <li><tt>password</tt></li></ul>
143 <p>The equivalent of the configuration from the last section would look like this:</p>
144 <div>
145 <pre>&lt;plugin&gt;
146   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
147   &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
148   &lt;version&gt;${project.version}&lt;/version&gt;
149   &lt;executions&gt;
150     &lt;execution&gt;
151       &lt;goals&gt;
152         &lt;goal&gt;export&lt;/goal&gt;
153       &lt;/goals&gt;
154     &lt;/execution&gt;
155   &lt;/executions&gt;
156   &lt;configuration&gt;
157     &lt;driverClassName&gt;org.hsqldb.jdbcDriver&lt;/driverClassName&gt;
158     &lt;hibernateDialect&gt;org.hibernate.dialect.HSQLDialect&lt;/hibernateDialect&gt;
159     &lt;url&gt;&lt;![CDATA[jdbc:hsqldb:target/db/fotos;shutdown=true]]&gt;&lt;/url&gt;
160     &lt;username&gt;sa&lt;/username&gt;
161     &lt;password&gt;&lt;/password&gt;
162   &lt;/configuration&gt;
163 &lt;/plugin&gt;</pre></div>
164 <p>The parameter <b>hibernateProperties</b> (name of the hibernate-properties-file to use, defaults to <b>hibernate.properties</b>) can only be configured through this approach.</p>
165 <p>For more explanations, see the <a href="./export-mojo.html"> Documentation of the export-Mojo</a>.</p></div>
166 <div class="section">
167 <h2><a name="Configuration-Method-Precedence">Configuration-Method-Precedence</a></h2>
168 <p>The configuration is gathered in a fix order:</p>
169 <ol style="list-style-type: decimal">
170 <li><tt>hibernate.properties</tt></li>
171 <li>maven-properties</li>
172 <li>plugin-configuration</li></ol>
173 <p>If you are in doubt about where a configuration-value comes from, run maven with the <a href="./debugging.html">debug-output</a> enabled: <tt>mvn -X hibernate4:export</tt> and be aware, that maven-properties can be overwitten on the command-line, in your <tt>~/.m2/settings.xml</tt> and in a profile.</p>
174 <p>The plugin-configuration comes last and overwrites everything else. That way, you can be sure, that a configuration-value, that is specified in the plugin-configuration will never be overwritten by any other configuration-method.</p>
175 <p>If you realy need to overwrite plugin-configuration-values with maven-properties, you can use maven-properties in the plugin-configuration:</p>
176 <div>
177 <pre>&lt;plugin&gt;
178   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
179   &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
180   &lt;version&gt;${project.version}&lt;/version&gt;
181   &lt;executions&gt;
182     &lt;execution&gt;
183       &lt;goals&gt;
184         &lt;goal&gt;export&lt;/goal&gt;
185       &lt;/goals&gt;
186     &lt;/execution&gt;
187   &lt;/executions&gt;
188   &lt;configuration&gt;
189     &lt;password&gt;${my-password-property}&lt;/password&gt;
190   &lt;/configuration&gt;
191 &lt;/plugin&gt;</pre></div></div>
192           </section>
193           <div class="marginal">
194             <nav id="nav">
195               <hr />
196               <a id="navigation"></a>
197               <h2 class="nav menu">Section-Menu</h2>
198               <ul id="menu">
199                 <li class="m blog"><a href="/blog/" class="m">Blog</a></li>
200                 <li class="m projects"><a href="/projects.html" class="m selected">Projects</a></li>
201               </ul>
202               <h2 class="nav submenu">
203                 <span class="s">Submenu for section</span>
204                 <a class="s selected" href="/projects.html">Projects</a>
205               </h2>
206               <ul id="submenu" class="s">
207                                                                       <li class="s sub">
208                                               <a class="s selected" href="./index.html">Hibernate 4 Maven Plugin</a>
209                                             <ul class="s active">
210                                                                                                                                                                                                                                                                                 <li class="s">
211               <strong class="s">Configuration Examples</strong>
212                 </li>
213                                                                                                                       <li class="s">
214                     <a href="export-mojo.html" class="s" title="Parameter Documentation">Parameter Documentation</a>
215                 </li>
216                                                                                                                       <li class="s">
217                     <a href="debugging.html" class="s" title="Enable Debug-Output">Enable Debug-Output</a>
218                 </li>
219                                                                                                                       <li class="s">
220                     <a href="skip.html" class="s" title="Skipping Execution">Skipping Execution</a>
221                 </li>
222                                                                                                                       <li class="s">
223                     <a href="force.html" class="s" title="Force Exceution">Force Exceution</a>
224                 </li>
225                                                                                                                       <li class="s">
226                     <a href="pitfalls.html" class="s" title="Known Pitfalls (FAQ)">Known Pitfalls (FAQ)</a>
227                 </li>
228                                                                                                                                                                                                                                                                                                                                                                   <li class="s sub">
229                     <a href="project-info.html" class="s" title="Project Information">Project Information</a>
230                 </li>
231                                                                                                                                                                                                       <li class="s sub">
232                     <a href="project-reports.html" class="s" title="Project Reports">Project Reports</a>
233                 </li>
234                                                                                                       </ul>
235                     </li>
236                                                 </ul>
237               <hr />
238             </nav>
239             <p>
240               <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
241                 <img class="poweredBy" alt="Built by Maven" src="./images/logos/maven-feather.png" />
242               </a>
243             </p>
244           </div>
245         </div>
246       </div>
247       <footer id="footer">
248         <hr />
249         <ul id="footerlinks">
250           <li class="f" id="copyright">&#xa9; <strong>mo</strong>             2013
251       </li>
252         </ul>
253       </footer>
254     </div>
255         <script type="text/javascript"><!--//--><![CDATA[//><!--
256       var _gaq = _gaq || [];
257       _gaq.push(['_setAccount', 'UA-571104-3']);
258       _gaq.push(['_trackPageview']);
259       (function() {
260         var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
261         ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
262         var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
263       })();
264     //--><!]]>
265       </body>
266 </html>