Sonderzeichen-Test für BPreplay
[website] / dist / hibernate4-maven-plugin-1.1.0 / configuration.html
1 <!DOCTYPE html>
2 <!-- Generated by Apache Maven Doxia Site Renderer 1.6 at 2015-09-08 -->
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     <meta name="viewport" content="width=device-width, initial-scale=1" />
13     <link rel="stylesheet" type="text/css" href="/css/base.css" />
14     <style type="text/css">
15       @import '/css/screen.css' screen;
16     </style>
17     <script src="/js/prettify.js"></script>
18     <!--[if lt IE 9]>
19       <script src="/js/html5shiv.js"></script>
20     <![endif]-->
21     <!--[if IE 8]>
22       <link rel="stylesheet" type="text/css" href="/css/ie8.css" />
23     <![endif]-->
24         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
25   </head>
26   <body class="menu" onload="prettyPrint()">
27     <div id="page" class="cf">
28       <header id="header">
29         <h1 id="logo"><a href="/" title="Home" class="l">juplo</a></h1>
30         <span id="slogan"><strong>Java</strong> bits from nerds for nerds</span>
31         <hr class="h" />
32       </header>
33       <div id="breadcrumb">
34         <strong class="b title">You are here:</strong>
35         <ol class="b">
36           <li class="b"><a class="b" href="/">Home</a></li>
37           <li class="b"><a class="b" href="/projects.html">Projects</a></li>
38                       <li class="b"><a class="b" href="./index.html">Hibernate 4 Maven Plugin</a></li>
39                         <li class="b"><strong class="b">Configuration Examples</strong></li>
40                   </ol>
41         <a class="hide" href="#navigation">Jump to navigation</a>
42         <hr class="b" />
43       </div>
44       <main class="content cf">
45         <article id="content" class="main">
46           <header><h1>Configuration Examples</h1></header>
47           
48  
49  
50   
51 <div class="section">
52 <h2><a name="Configuration_through_a_hibernate.properties-File"></a>Configuration through a hibernate.properties-File</h2>
53   
54 <p>
55   The most simple way to configure the plugin is, to put all the
56   hibernate-configuration in a <b>hibernate.properties</b>-file on your
57   classpath. Put the file in the <tt>resources</tt>-folder. Maven will put
58   it in the <tt>class</tt>-folder of your webapp, where it will be picked up
59   by this plugin as well as by Hibernate 4.
60   </p>
61   
62 <p>
63   Doing so, the only additionally configuration needed, to activat the plugin
64   is the following entry in the <tt>plugins</tt>-section of your <tt>pom.xml</tt>:
65   </p>
66   
67 <div>
68 <pre class="prettyprint linenums lang-html">
69 &lt;plugin&gt;
70   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
71   &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
72   &lt;version&gt;1.1.0&lt;/version&gt;
73   &lt;executions&gt;
74     &lt;execution&gt;
75       &lt;goals&gt;
76         &lt;goal&gt;export&lt;/goal&gt;
77       &lt;/goals&gt;
78     &lt;/execution&gt;
79   &lt;/executions&gt;
80 &lt;/plugin&gt;</pre></div>
81   
82 <p>
83   But be aware, that in this case the database-url, that is
84   build in the application is the same that is used while testing, where
85   the database is droped and recreated by the plugin.
86   Because of that,
87   <b>
88     you should never fire up this configuration on your production
89     system, or your database might be erased!
90   </b>
91   </p>
92   
93 <p>
94   A better approach is, to specify a different url for testing like in the
95   following snippet:
96   </p>
97   
98 <div>
99 <pre class="prettyprint linenums lang-html">
100 &lt;plugin&gt;
101   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
102   &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
103   &lt;version&gt;1.1.0&lt;/version&gt;
104   &lt;executions&gt;
105     &lt;execution&gt;
106       &lt;goals&gt;
107         &lt;goal&gt;export&lt;/goal&gt;
108       &lt;/goals&gt;
109     &lt;/execution&gt;
110   &lt;/executions&gt;
111   &lt;configuration&gt;
112     &lt;url&gt;&lt;![CDATA[jdbc:mysql://localhost/test-db]]&gt;&lt;/url&gt;
113   &lt;/configuration&gt;
114 &lt;/plugin&gt;</pre></div>
115   
116 <p>
117   Configuration properties, that are set in the <tt>configuration</tt>-section
118   of the plugin-configuration cannnot be overwritten elsewere (for details
119   see <a href="#precedence">Configuration-Method-Precedence</a>).
120   You never can overwrite them by accident when specifying a property on
121   the commandline or in your <tt>settings.xml</tt>.
122   </p>
123   </div>
124 <div class="section">
125 <h2><a name="Configuration_through_maven-properties"></a>Configuration through maven-properties</h2>
126   
127 <p>
128   Alternatively, it is possible, to configure the plugin via maven-properties.
129   Each relevant configuration-option has a corresponding maven-property
130   (for a full list see the <a href="./export-mojo.html">Documentation of the export-Mojo</a>).
131   These are named after the
132   <a class="externalLink" href="http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#configuration-hibernatejdbc">Hibernate JDBC Properties</a>:
133   </p>
134   
135 <ul>
136     
137 <li><tt>hibernate.connection.driver_class</tt></li>
138     
139 <li><tt>hibernate.dialect</tt></li>
140     
141 <li><tt>hibernate.connection.url</tt></li>
142     
143 <li><tt>hibernate.connection.username</tt></li>
144     
145 <li><tt>hibernate.connection.password</tt></li>
146   </ul>
147   
148 <p>
149   So, instead of writing the hibernate-configuration in the properties-file,
150   like above, you could put it in the <tt>properties</tt>-section of your
151   <tt>pom.xml</tt>.
152   </p>
153   
154 <p>
155   Thogether with the plugin-definition from above, the following would
156   be a complete configuration (again, the database-url was overwritten in
157   the plugin-configuration, to be sure to have a separate database for
158   testing):
159   </p>
160   
161 <div>
162 <pre class="prettyprint linenums lang-html">
163 &lt;properties&gt;
164   &lt;hibernate.connection.driver_class&gt;org.hsqldb.jdbcDriver&lt;/hibernate.connection.driver_class&gt;
165   &lt;hibernate.dialect&gt;org.hibernate.dialect.HSQLDialect&lt;/hibernate.dialect&gt;
166   &lt;hibernate.connection.url&gt;&lt;![CDATA[jdbc:hsqldb:res:org.my.path.production_db]]&gt;&lt;/hibernate.connection.url&gt;
167   &lt;hibernate.connection.username&gt;sa&lt;/hibernate.connection.username&gt;
168   &lt;hibernate.connection.password&gt;&lt;/hibernate.connection.password&gt;
169 &lt;/properties&gt;
170
171 ...
172
173 &lt;plugins&gt;
174
175   ...
176
177   &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;1.1.0&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;url&gt;&lt;![CDATA[jdbc:hsqldb:target/db/testdb;shutdown=true]]&gt;&lt;/url&gt;
190     &lt;/configuration&gt;
191   &lt;/plugin&gt;
192
193 &lt;plugins&gt;</pre></div>
194   </div>
195 <div class="section">
196 <h2><a name="Configuration_through_the_plugin-configuration"></a>Configuration through the plugin-configuration</h2>
197   
198 <p>
199   A third way for configuring the plugin is the plugin-configuration.
200   The relevant configuration-parameters are:
201   </p>
202   
203 <ul>
204     
205 <li><tt>driverClassName</tt></li>
206     
207 <li><tt>hibernateDialect</tt></li>
208     
209 <li><tt>url</tt></li>
210     
211 <li><tt>username</tt></li>
212     
213 <li><tt>password</tt></li>
214   </ul>
215   
216 <p>
217   The equivalent of the configuration from the last section would look
218   like this:
219   </p>
220   
221 <div>
222 <pre class="prettyprint linenums lang-html">
223 &lt;plugin&gt;
224   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
225   &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
226   &lt;version&gt;1.1.0&lt;/version&gt;
227   &lt;executions&gt;
228     &lt;execution&gt;
229       &lt;goals&gt;
230         &lt;goal&gt;export&lt;/goal&gt;
231       &lt;/goals&gt;
232     &lt;/execution&gt;
233   &lt;/executions&gt;
234   &lt;configuration&gt;
235     &lt;driverClassName&gt;org.hsqldb.jdbcDriver&lt;/driverClassName&gt;
236     &lt;hibernateDialect&gt;org.hibernate.dialect.HSQLDialect&lt;/hibernateDialect&gt;
237     &lt;url&gt;&lt;![CDATA[jdbc:hsqldb:target/db/fotos;shutdown=true]]&gt;&lt;/url&gt;
238     &lt;username&gt;sa&lt;/username&gt;
239     &lt;password&gt;&lt;/password&gt;
240   &lt;/configuration&gt;
241 &lt;/plugin&gt;</pre></div>
242   
243 <p>
244   The parameter <b>hibernateProperties</b> (name of the hibernate-properties-file
245   to use, defaults to <b>hibernate.properties</b>) can only be configured through
246   this approach.
247   </p>
248   
249 <p>
250   For more explanations, see the
251   <a href="./export-mojo.html">Documentation of the export-Mojo</a>.
252   </p>
253   </div>
254 <div class="section" id="precedence">
255 <h2 id="precedence">Configuration-Method-Precedence</h2>
256   
257 <p>
258   The configuration is gathered in a fix order:
259   </p>
260   
261 <ol style="list-style-type: decimal">
262     
263 <li><tt>hibernate.properties</tt></li>
264     
265 <li>maven-properties</li>
266     
267 <li>plugin-configuration</li>
268   </ol>
269   
270 <p>
271   If you are in doubt about where a configuration-value comes from, run
272   maven with the <a href="./debugging.html">debug-output</a> enabled: <tt>mvn -X hibernate4:export</tt>
273   and be aware, that maven-properties can be overwitten on the command-line,
274   in your <tt>~/.m2/settings.xml</tt> and in a profile.
275   </p>
276   
277 <p>
278   The plugin-configuration comes last and overwrites everything else.
279   That way, you can be sure, that a configuration-value, that is
280   specified in the plugin-configuration will never be overwritten by any
281   other configuration-method.
282   </p>
283   
284 <p>
285   If you need to overwrite plugin-configuration-values with
286   maven-properties, you can use maven-properties in the plugin-configuration:
287   </p>
288   
289 <div>
290 <pre class="prettyprint linenums lang-html">
291 &lt;plugin&gt;
292   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
293   &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
294   &lt;version&gt;1.1.0&lt;/version&gt;
295   &lt;executions&gt;
296     &lt;execution&gt;
297       &lt;goals&gt;
298         &lt;goal&gt;export&lt;/goal&gt;
299       &lt;/goals&gt;
300     &lt;/execution&gt;
301   &lt;/executions&gt;
302   &lt;configuration&gt;
303     &lt;password&gt;${my-password-property}&lt;/password&gt;
304   &lt;/configuration&gt;
305 &lt;/plugin&gt;</pre></div>
306  </div>
307
308         </article>
309         <div class="marginal">
310           <nav id="nav">
311             <hr class="n" />
312             <a id="navigation"></a>
313             <a class="hide" href="#top" title="Show Content">Jump back to the top of the page</a>
314             <h2 class="nav menu">Section-Menu</h2>
315             <ul id="menu">
316               <li class="m blog"><a href="/blog/" class="m">Blog</a></li>
317               <li class="m projects"><a href="/projects.html" class="m selected">Projects</a></li>
318               <li class="m about"><a href="/about.html" class="m">About</a></li>
319             </ul>
320             <h2 class="nav submenu">
321               <span class="s">Submenu for section</span>
322               <a class="s selected" href="/projects.html">Projects</a>
323             </h2>
324             <ul id="submenu" class="s">
325                                                               <li class="s sub">
326                                           <a class="s selected" href="./index.html">Hibernate 4 Maven Plugin</a>
327                                         <ul class="s active">
328                                                                                                                                                                                                                                                                 <li class="s">
329               <strong class="s">Configuration Examples</strong>
330                 </li>
331                                                                                                                   <li class="s">
332                     <a href="export-mojo.html" class="s" title="Parameter Documentation">Parameter Documentation</a>
333                 </li>
334                                                                                                                   <li class="s">
335                     <a href="debugging.html" class="s" title="Enable Debug-Output">Enable Debug-Output</a>
336                 </li>
337                                                                                                                   <li class="s">
338                     <a href="skip.html" class="s" title="Skipping Execution">Skipping Execution</a>
339                 </li>
340                                                                                                                   <li class="s">
341                     <a href="force.html" class="s" title="Force Exceution">Force Exceution</a>
342                 </li>
343                                                                                                                   <li class="s">
344                     <a href="pitfalls.html" class="s" title="Known Pitfalls (FAQ)">Known Pitfalls (FAQ)</a>
345                 </li>
346                                                                                                                                                                                                                                                                                                                                                   <li class="s sub">
347                     <a href="project-info.html" class="s" title="Project Information">Project Information</a>
348                 </li>
349                                                                                                                                                                                                   <li class="s sub">
350                     <a href="project-reports.html" class="s" title="Project Reports">Project Reports</a>
351                 </li>
352                                                                                               </ul>
353                   </li>
354                                           </ul>
355             <hr class="n" />
356           </nav>
357           <aside class="m">
358             <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
359               <img class="poweredBy" alt="Built by Maven" src="./images/logos/maven-feather.png" />
360             </a>
361           </aside>
362         </div>
363       </main>
364       <footer id="footer">
365         <hr class="f" />
366         <ul id="footerlinks">
367           <li class="f" id="copyright">&#xa9; <strong>mo</strong>             2015
368       </li>
369           <li class="f"><a class="f" href="/impressum.html">Impressum</a></li>
370           <li class="f about"><a class="f" href="/about.html">About</a></li>
371         </ul>
372       </footer>
373     </div>
374         <script type="text/javascript"><!--//--><![CDATA[//><!--
375       var _gaq = _gaq || [];
376       _gaq.push(['_setAccount', 'UA-571104-3']);
377       _gaq.push(['_trackPageview']);
378       (function() {
379         var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
380         ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
381         var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
382       })();
383     //--><!]]>
384     </script>
385       </body>
386 </html>