当我运行此命令
时mvn antrun:运行@hbm2java
我有这个错误
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building ciccio 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-antrun-plugin:1.8:run (hbm2java) @ ciccio ---
Downloading: https://repo.maven.apache.org/maven2/org/apache/ant/ant/1.9.4/ant-1.9.4.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/ant/ant/1.9.4/ant-1.9.4.pom (10 KB at 9.5 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/ant/ant/1.9.4/ant-1.9.4.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/ant/ant/1.9.4/ant-1.9.4.jar (1972 KB at 1036.8 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.267 s
[INFO] Finished at: 2016-11-27T23:32:16+01:00
[INFO] Final Memory: 15M/144M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run (hbm2java) on project ciccio: An Ant BuildException has occured: The following error occurred while executing this line:
[ERROR] jar:file:/C:/Users/ciro/.m2/repository/org/apache/maven/plugins/maven-antrun-plugin/1.8/maven-antrun-plugin-1.8.jar!/org/apache/maven/ant/tasks/antlib.xml:24: The following error occurred while executing this line:
[ERROR] jar:file:/C:/Users/ciro/.m2/repository/org/apache/ant/ant/1.9.4/ant-1.9.4.jar!/org/apache/tools/ant/antlib.xml:37: Could not create task or type of type: componentdef.
[ERROR]
[ERROR] Ant could not find the task or a class this task relies upon.
[ERROR]
[ERROR] This is common and has a number of causes; the usual
[ERROR] solutions are to read the manual pages then download and
[ERROR] install needed JAR files, or fix the build file:
[ERROR] - You have misspelt 'componentdef'.
[ERROR] Fix: check your spelling.
[ERROR] - The task needs an external JAR file to execute
[ERROR] and this is not found at the right place in the classpath.
[ERROR] Fix: check the documentation for dependencies.
[ERROR] Fix: declare the task.
[ERROR] - The task is an Ant optional task and the JAR file and/or libraries
[ERROR] implementing the functionality were not found at the time you
[ERROR] yourself built your installation of Ant from the Ant sources.
[ERROR] Fix: Look in the ANT_HOME/lib for the 'ant-' JAR corresponding to the
[ERROR] task and make sure it contains more than merely a META-INF/MANIFEST.MF.
[ERROR] If all it contains is the manifest, then rebuild Ant with the needed
[ERROR] libraries present in ${ant.home}/lib/optional/ , or alternatively,
[ERROR] download a pre-built release version from apache.org
[ERROR] - The build file was written for a later version of Ant
[ERROR] Fix: upgrade to at least the latest release version of Ant
[ERROR] - The task is not an Ant core or optional task
[ERROR] and needs to be declared using <taskdef>.
[ERROR] - You are attempting to use a task defined using
[ERROR] <presetdef> or <macrodef> but have spelt wrong or not
[ERROR] defined it at the point of use
[ERROR]
[ERROR] Remember that for JAR files to be visible to Ant tasks implemented
[ERROR] in ANT_HOME/lib, the files must be in the same directory or on the
[ERROR] classpath
[ERROR]
[ERROR] Please neither file bug reports on this problem, nor email the
[ERROR] Ant mailing lists, until all of these causes have been explored,
[ERROR] as this is not an Ant bug.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
我已经安装了ant 1.8,并设置了ant_home e将bin文件夹放在Windows路径内。
我感到您正在尝试做他们不应该做的事情。例如,我认为这是Ant Apache的存储库下载版本1.9,我不知道为什么。然后忽略我已经安装在机器Ant
上的事实谢谢
编辑
我确认了些什么。我更名为1.9版的罐子,并将其放置在1.8的位置。一切正常。但是最好没有这些技巧来工作
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution> <!--mvn antrun:run@hbm2java-->
<id>hbm2java</id>
<phase>none</phase>
<configuration>
<target>
<echo message="Start generating entities .."/>
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask"/>
<hibernatetool>
<jdbcconfiguration
revengfile="src/main/resources/hibernate.reveng.xml"
packagename="it.ciccio.test"
detectmanytomany="true"
configurationfile="src/main/resources/hibernate.cfg.xml"/>
<hbm2java
destdir="src/main/java/"
jdk5="true"
ejb3="true"
/>
</hibernatetool>
<echo message="End generating entities"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution> <!--mvn antrun:run@hbm2dao-->
<id>hbm2dao</id>
<phase>none</phase>
<configuration>
<target>
<echo message="Start generating dao .."/>
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask"/>
<hibernatetool>
<jdbcconfiguration
revengfile="src/main/resources/hibernate.reveng.xml"
packagename="it.ciccio.dao"
detectmanytomany="true"
configurationfile="src/main/resources/hibernate.cfg.xml"/>
<hbmtemplate destdir="${basedir}/src/main/java"
templatepath="${basedir}/src/main/resources/template"
template="daohome.ftl"
filepattern="{package-name}/{class-name}Dao.java">
<property key="ejb3" value="true" />
<property key="jdk5" value="true" />
</hbmtemplate>
</hibernatetool>
<echo message="End generating dao"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>5.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.8</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1207.jre7</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-tools</artifactId>
<version>${hibernate.version}</version>
<exclusions>
<exclusion>
<groupId>org.hiernate</groupId>
<artifactId>${hibernate.version}</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</plugin>
我发布正确的pom。
问题是在工具中使用的依赖版本
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution> <!--mvn antrun:run@hbm2java-->
<id>hbm2java</id>
<phase>none</phase>
<configuration>
<target>
<echo message="Start generating entities .."/>
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask"/>
<hibernatetool>
<jdbcconfiguration
revengfile="src/main/resources/hibernate.reveng.xml"
packagename="it.ciccio.test"
detectmanytomany="true"
configurationfile="src/main/resources/hibernate.cfg.xml"/>
<hbm2java
destdir="src/main/java/"
jdk5="true"
ejb3="true"
/>
</hibernatetool>
<echo message="End generating entities"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution> <!--mvn antrun:run@hbm2java-->
<id>hbm2dao</id>
<phase>none</phase>
<configuration>
<target>
<echo message="Start generating dao .."/>
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask"/>
<hibernatetool>
<jdbcconfiguration
revengfile="src/main/resources/hibernate.reveng.xml"
packagename="it.webgate.dao"
detectmanytomany="true"
configurationfile="src/main/resources/hibernate.cfg.xml"/>
<hbmtemplate destdir="${basedir}/src/main/java"
templatepath="${basedir}/src/main/resources/template"
template="daohome.ftl"
filepattern="{package-name}/{class-name}Dao.java">
<property key="ejb3" value="true" />
<property key="jdk5" value="true" />
</hbmtemplate>
</hibernatetool>
<echo message="End generating dao"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.11.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.11.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.11.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate.common/hibernate-commons-annotations -->
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>4.0.5.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.8</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1207.jre7</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-tools</artifactId>
<version>4.3.2.Final</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>