I want to create Java-classes out of an MySQL-Database using hibernate. Just using eclipse and the Hibernate-Plugin, this works fine (described here: http://www.wikihow.com/Generate-Hibernate-Pojo-Classes-from-DB-Tables), but I want to do it with maven. This, after some tries, does not work.
Generelly, I have an hibernate.cfg.xml and a persistance.xml-file, both with the correct connection-information. I found some threads about howto generate the classes from java (for example How to configure hibernate-tools with maven to generate hibernate.cfg.xml, *.hbm.xml, POJOs and DAOs) and the documentation of the hibernate-maven-plugin (http://mojo.codehaus.org/hibernate3-maven-plugin).
I tried several code snippets, the most promising seems to me from: Maven Java Source Code Generation for Hibernate
I added the file I need, and I got:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>hbm2java</goal>
</goals>
</execution>
</executions>
<configuration>
<components>
<component>
<name>hbm2java</name>
<implementation>configuration</implementation>
<outputDirectory>target/generated-sources/hibernate3</outputDirectory>
</component>
</components>
<componentProperties>
<drop>true</drop>
<jdk5>true</jdk5>
<configurationfile>/src/main/java/hibernate.cfg.xml</configurationfile>
<packagename>de.unileipzig.database</packagename>
</componentProperties>
</configuration>
</plugin>
But unfortunately, when executing, I get
[ERROR] Failed to execute goal org.codehaus.mojo:hibernate3-maven-plugin:2.2:hbm2java (default-cli) on project AWV: Execution default-cli of goal org.codehaus.mojo:hibernate3-maven-plugin:2.2:hbm2java failed: An AnnotationConfiguration instance is required to use <mapping class="de.unileipzig.database.objectlist"/> -> [Help 1]
I googled the error, and found on http://www.mkyong.com/hibernate/hibernate-error-an-annotationconfiguration-instance-is-required-to-use/ that one has to add the dependency. It seemed somehow awkward to me, as I am using Hibernate 4 and the Maven Plugin for Hibernate 3 (the hibernate 4 plugin seems not to be practical usable for my case: http://www.smartics.eu/hibernate4-maven-plugin/ ), but I tried adding:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.6-Final</version>
</dependency>
(As the version specified at the Mykong-Post can't be found in my repositories).
Unfortunately, still, the error occurs. Does anybody have an hint how to solve this problem? Is there just an problem with the annotation-dependeny, or is my usage of the plugin not right?
After the advice of julschi, I added the following code to the plugin:
<plugin>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.5.6-Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.5.6-Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.6-Final</version>
</dependency>
</dependencies>
</plugin>
Unfortunately, this did not change anything. When I used the version I use in the project (Hibernate 4.2.7) it results in an error, that org.hibernate.util.StringHelper is not found; it seems to be moved to another package (https://docs.jboss.org/hibernate/orm/4.1/javadocs/org/hibernate/internal/util/StringHelper.html). But if I use the version 3.5.6-FINAL, I just get the same AnnotationConfiguration error.
If someone wants to try it out: the whole POM is here: http://nopaste.info/a70449bee6.html.
maybe create a dependencies section in the plugin part itself, like this:
<plugin>
...
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.2.144</version>
</dependency>
</dependencies>
...
</plugin>
Related
I know this is a duplicate question but the answers on other topics didn't help me.
I'm using Eclipse Photon, Java Version :10, I've set jdk/jre versions on 10 in eclipse and pom.xml file. I've changed eclipse.ini file :
-Dosgi.requiredJavaVersion=10 (it was set to 1.8)
and also I've added plugin in my pom.xml :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>10</source>
<target>10</target>
</configuration>
</plugin>
Nothing helped. This is my pom.xml :
<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>com.luv2code</groupId>
<artifactId>spring-security-demo-06-user-roles</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<name>spring-security-demo</name>
<properties>
<maven.compiler.source>10</maven.compiler.source>
<maven.compiler.target>10</maven.compiler.target>
</properties>
<dependencies>
<!-- Spring Security -->
<!-- Spring Security WEB -->
<!-- Spring Security taglibs -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>5.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>5.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>5.1.1.RELEASE</version>
</dependency>
<!-- Spring MVC support -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.2.RELEASE</version>
</dependency>
<!-- Servlet, JSP and JSTL support -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- TO DO: Add support for Maven WAR Plugin -->
<build>
<finalName>spring-security-demo</finalName>
<pluginManagement>
<plugins>
<plugin>
<!-- Add Maven coordinates forL maven-war-plugin -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>10</source>
<target>10</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
The dependencies aren't being read in class files and also I've tried deleting .m2 repository and starting Eclipse and doing the : Maven->Clean, Maven->install, and than Maven->update project. Nothing helped. I'm really stuck here for about 2-3 hours now.
Note: in Windows->Preferences->installed JRE's the jre10 was marked with the tick. I changed it to mark the jdk10. but still error :
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project spring-security-demo-06-user-roles: Compilation failure
Everything was working fine until I added the dependency of : spring-security-taglibs.
Deleting the dependency doesn't do anything aswell.
Check properly settings with version of your project in eclipse and version of your runner for maven.
I have reproduced the same issue with maven-compiler plugin, but using version 3.8.1:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project testName: Fatal error compiling
My POM was:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
To clarify:
in project I'm using Java 11 and IntelijIDEA (but logic I think the same for eclipse). So I'm using maven lifecycle phases fine only if my version of project (check properly Project Structure -> Project Settings) corresponds to version of maven runner.
E.g. if version of runner is for java 8, but project settings are for Java 11 then I'm getting this error. If I have the same for both then I don't have any problems.
And I highly recommend to check all settings for maven and the whole project. It helps to avoid the issues in the future. Deleting folder for maven is as alternative solution, but it must be last thing that you need to do.
It started working Automagically . FIX : delete .m2 repository.
I did that yesterday but it didn't help, today somehow, deleting the .m2 repository and updating the project helped !
Confirm, delete your entire local repository pointed to by .m2/settings.xml, usually this is .m2/repository
I updated my Java SDK to 11.9 and reloaded the project. With this I solved my problem.
I had the same issue, it was because the Spring Boot project was using Java 11 but my %JAVA_HOME% variable was pointing to Java 8 home directory. I resolved the issue by changing the path to %JAVA_HOME% variable.
You just need to go to preference(eclipse in this case) and change the right version of JDK like below in pic:
Trying to build an example from camel via mvn package
apache-camel-2.22.0/examples/camel-example-cdi-xml
Getting an error never seen before, i checked dependency tree for transitive deps and apache-collections is 3.2.1 and not corrupt so can't explain it, obviously i know what it means, just can't figure out why it's happening because everything that should be required is provided:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-remote-resources-plugin:1.5:process (process-resource-bundles) on project camel-example-cdi-xml: Execution process-resource-bundles of goal org.apache.maven.plugins:maven-remote-resources-plugin:1.5:process failed: A required class was missing while executing org.apache.maven.plugins:maven-remote-resources-plugin:1.5:process: org/apache/commons/collections/ExtendedProperties
Not really sure how to trouble shoot it.
I tried building with several different versions of maven. JDK = 1.8
update pom.xml add the following code
<plugin>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.6.0</version>
<dependencies>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-lang/commons-lang -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>bundle</goal>
</goals>
</execution>
</executions>
</plugin>
I am attempting to POST test results to TestRails.
Using test suites and test cases, the tests in question were created using SoapUI. What I currently have will POST directly from SoapUI to TestRails. The company I work for wants to initiate the SoapUI tests using Maven, which is possible with a SoapUI plug-in for the Maven pom file. This part of the process works perfectly.
However, POSTing to the TestRails project only works if I initiate the tests via the SoapUI application. When I run the same tests via Maven, all the test steps complete and are visible in the stack trace, but none of the test case results are sent to TestRails.
What I have done is placed a plug-in in the pom file, which is supposed to connect Maven to TestRails and allow the transfer of the test results, but while there are no errors in the program, no POST is done.
Here's how I have it coded in my pom file:
<plugin>
<groupId>com.smartbear.soapui</groupId>
<artifactId>soapui-maven-plugin</artifactId>
<version>5.1.2</version>
<configuration>
<settingsFile>${projectDir}\soapui-settings.xml</settingsFile>
<iface>mobileAdsService</iface>
<exportwAll>true</exportwAll>
<printReport>true</printReport>
<testFailIgnore>true</testFailIgnore>
<junitReport>true</junitReport>
<outputFolder>${projectDir}\TestResults</outputFolder>
<projectFile>${basedir}\Irdeto-v1.xml</projectFile>
<saveAfterRun>true</saveAfterRun>
</configuration>
<dependencies>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.9-RC1</version>
</dependency>
***<dependency>
<groupId>com.codepine.api</groupId>
<artifactId>testrail-api-java-client</artifactId>
<version>1.0.0</version>
</dependency>***
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.0.6</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.10-FINAL</version>
<exclusions>
<exclusion>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<executions>
<execution>
<id>soapui-tests</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
This appears to have been due to a bug in the non-licensed version of SoapUI.
Usually i start tomcat using mvnDebug tomcat:run.
After Code-change i need to use mvn tomcat:redeploy.
This is sub-optimal because i often only change content of existing method-bodys.
Can I HotSwap the method's body into the runtime, and hot-redeploy as a fallback?
I have unfortunatally nothing found like a maven-hotswap-plugin.
faces-config.xml
... <application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
<locale-config>
<default-locale>de_DE</default-locale>
</locale-config>
<resource-bundle>
<base-name>Message</base-name>
<var>message</var>
</resource-bundle>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
</faces-config>
web.xml:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
pom.xml:
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-envers</artifactId>
<version>4.3.0.Final</version>
</dependency>
<dependency>
<groupId>net.java.dev.ajax4jsf</groupId>
<artifactId>ajax4jsf</artifactId>
<version>1.0.6</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.6.Final</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-api</artifactId>
<version>1.2.10</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-impl</artifactId>
<version>1.2.10</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.myfaces.tomahawk</groupId>
<artifactId>tomahawk12</artifactId>
<version>1.1.9</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.sun.facelets</groupId>
<artifactId>jsf-facelets</artifactId>
<version>1.1.14</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>3.1.0.GA</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.2-1004-jdbc41</version>
</dependency>
<dependency>
<groupId>servletapi</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<contextReloadable>true</contextReloadable>
</configuration>
</plugin>
</plugins>
</build>
You can use Jrebel - it works exactly as you expect. You just need to specify javaagent and it will reload all classes and framework changes during runtime. It also works with remote servers
To integrate it with maven project you have to add jrebel-maven-plugin, which will generate all configuration (rebel.xml) files.
Without JRebel you can use standard HotSwap mechanism but it only allows to reload method bodies
One of the best solutions for your situation is JRebel
What you need to do is make the appropriate changes to the framework
and integrate it using a jrebel-maven-plugin.
It allows to reload all the method bodies.
Once you are done with the link-up a auto xml configuration file will be generated which will be used as a config file for the plugin.
Mention Your Java Agent as well.
After the successful test you can also integrate it with a build
JRebel is a good option. It isn't cheap but there are open source licences available. The installation instructions for Maven are here:
http://zeroturnaround.com/software/jrebel/learn/maven/
We get this working through a specific run profile and embedded Tomcat. This is a specific sub-module that depends on the other projects that build the web application wars. So if you configure something like the following in the runner submodule:
<profiles>
<profile>
<id>run</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<executions>
<execution>
<id>run-wars</id>
<goals>
<goal>run-war-only</goal>
</goals>
<phase>integration-test</phase>
</execution>
</executions>
<configuration>
<warDirectory>theWar</warDirectory>
<path>/relativepath</path>
<systemProperties>
<webapps>
<webapp>
<groupId>${project.groupId}</groupId>
<artifactId>myArtifact</artifactId>
<version>${project.version}</version>
<type>war</type>
<asWebapp>true</asWebapp>
<contextPath>myContext</contextPath>
</webapp>
</webapps>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
You can run this with mvn package -Prun which you should be able to shut down with Ctrl+C.
Then, whilst this is running in one terminal, make your code changes, open a new terminal and run mvn compile. With JRebel going the changes should be reflected virtually instantly in your web app.
There should be nothing preventing you from running these same goals through Eclipse's m2e plugin.
It seems that you may be using some old version of the maven tomcat plug-in, because newer versions should be referred as tomcat6 or tomcat7, e..g. mvnDebug tomcat7:run. I'm on 2.2 and hot swap from Eclipse works just fine.
To clarify a little more, that's what I see in the command prompt when starting the app with mvn tomcat:run:
...
[INFO] >>> tomcat-maven-plugin:1.1:run (default-cli) # tomcatMvnDebug >>>
...
Notice the 1.1.
And that's what I see when starting the app with mvn tomcat7:run:
...
[INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) # tomcatMvnDebug >>>
...
Notice that this time maven uses tomcat plug-in version 2.2.
I'd use the HotSwap functions of Eclipse or IntelliJ. They both work very well for me: Just run maven goal in debug mode (tomcat:run).
We generally develop the web applications using grails which already has reload feature, I believe it's done with the spring-loaded plugin. It may be a replacement to jRebel (although I'm not sure if it will work for you, but if you want to save a few hundreds $$, may be worth trying).
So, basically I see the following options:
Use the framework which already supports reloading classes (Grails, Play)
Use some javaagent like spring-loaded or JRebel
Use some javaagent integrated into the IDE (I use IntelliJ IDEA and highly recommend it. Not sure if it works in the free community edition though).
https://github.com/spring-projects/spring-loaded
There is a maven plugin. It doesn't seem to be maintained. However from short look at the source code I believe you can make it work.
It is based on similar plugin for ant, so alternatively you can use maven antrun to execute this
Nevertheless it is going to have the same capabilities (and limitations) as hotswap in any IDE.
I have a working application that persists to a database using JDO - I want to use a PersistenceCapable class that's in a second java module. Although the app compiles a simple test gives the error:
The class "com.hello.world.Foo" is not persistable This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data/annotations for the class are not found.
Ok, so the enhancer plugin is not running on the classes in the second module. I'm not sure what i need to do to point the enhancer at that module during the build.
ParentProject
Second Module: com.hello.world.Foo
ParentProject pom.xml with relevant parts - problem is how do i point the enhancer at the second module containing my persistent class?
<dependencies>
<dependency>
<groupId>Second Module</groupId>
<artifactId>Second Module</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.jdo</groupId>
<artifactId>jdo-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-core</artifactId>
<version>[3.2.0, 3.2.99)</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-api-jdo</artifactId>
<version>[3.2.0, 3.2.99)</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-rdbms</artifactId>
<version>[3.2.0, 3.2.99)</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-maven-plugin</artifactId>
<version>3.3.0-release</version>
<configuration>
<api>JDO</api>
<props>${basedir}/datanucleus.properties</props>
<log4jConfiguration>${basedir}/log4j.properties</log4jConfiguration>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
got it - i had to add the exact same pom.xml config in the question to the second module and do a mvn install to get those classes enahnced before compiling the parent module. Working on both Jetty and GAE. I thought, wrongly, that the parent module would enhance classes included in the module dependencies.
Thanks for your help DataNucleus!