Maven HeuristicMixedException with Wildfly webapp

huangapple go评论61阅读模式
英文:

Maven HeuristicMixedException with Wildfly webapp

问题

如果我尝试使用 `mvn clean install -U` 编译我的 web 应用程序,我会得到以下错误日志。

    [INFO] 正在扫描项目...
    [INFO] 
    [INFO] ---------------------< com.mycompany:myproject >---------------------
    [INFO] 正在构建 mycompany.com Scheduler 0.0.1-SNAPSHOT
    [INFO] --------------------------------[ war ]---------------------------------
    [INFO] 
    [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ myproject ---
    [INFO] 正在删除 /home/user/workspace JavaEE/myproject/target
    [INFO] 
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ myproject ---
    [INFO] 使用 'UTF-8' 编码来复制过滤资源。
    [INFO] 复制了 1 个资源
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ myproject ---
    [INFO] 检测到更改 - 正在重新编译模块!
    [INFO] 正在将 19 个源文件编译到 /home/user/workspace JavaEE/myproject/target/classes
    [INFO] -------------------------------------------------------------
    [ERROR] 编译错误 : 
    [INFO] -------------------------------------------------------------
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[10,25] 找不到符号
      符号:   类 HeuristicMixedException
      位置: package javax.transaction
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[11,25] 找不到符号
      符号:   类 HeuristicRollbackException
      位置: package javax.transaction
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[12,25] 找不到符号
      符号:   类 NotSupportedException
      位置: package javax.transaction
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[13,25] 找不到符号
      符号:   类 RollbackException
      位置: package javax.transaction
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[14,25] 找不到符号
      符号:   类 SystemException
      位置: package javax.transaction
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[15,25] 找不到符号
      符号:   类 UserTransaction
      位置: package javax.transaction
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[31,13] 找不到符号
      符号:   类 UserTransaction
      位置: 类 controller.Delete<T>
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[77,49] 找不到符号
      符号:   类 NotSupportedException
      位置: 类 controller.Delete<T>
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[77,72] 找不到符号
      符号:   类 SystemException
      位置: 类 controller.Delete<T>
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[78,36] 找不到符号
      符号:   类 RollbackException
      位置: 类 controller.Delete<T>
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[78,55] 找不到符号
      符号:   类 HeuristicMixedException
      位置: 类 controller.Delete<T>
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[78,80] 找不到符号
      符号:   类 HeuristicRollbackException
      位置: 类 controller.Delete<T>
    
    ...
    
    [INFO] 36 个错误 
    [INFO] -------------------------------------------------------------
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] 总时间:  3.186 s
    [INFO] 完成时间: 2020-04-10T13:50:37+02:00
    [INFO] ------------------------------------------------------------------------
    [ERROR] 无法执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project myproject: 编译失败: 编译失败: 
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[10,25] 找不到符号
    [ERROR]   符号:   类 HeuristicMixedException
    [ERROR]   位置: package javax.transaction
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[11,25] 找不到符号
    [ERROR]   符号:   类 HeuristicRollbackException
    [ERROR]   位置: package javax.transaction
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[12,25] 找不到符号
    [ERROR]   符号:   类 NotSupportedException
    [ERROR]   位置: package javax.transaction
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[13,25] 找不到符号
    [ERROR]   符号:   类 RollbackException
    [ERROR]   位置: package javax.transaction
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[14,25] 找不到符号
    [ERROR]   符号:   类 SystemException
    [ERROR]   位置: package javax.transaction
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[15,25] 找不到符号
    [ERROR]   符号:   类 UserTransaction
    [ERROR]   位置: package javax.transaction
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[31,13] 找不到符号
    [ERROR]   符号:   类 UserTransaction
    [ERROR]   位置: 类 controller.Delete<T>
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[77,49] 找不到符号
    [ERROR]   符号:   类 NotSupportedException
    [ERROR]   位置: 类 controller.Delete<T>
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[77,72] 找不到符号
    [ERROR]   符号

<details>
<summary>英文:</summary>

If I try to compile my webapp with `mvn clean install -U` I get the errorlog below.

    [INFO] Scanning for projects...
    [INFO] 
    [INFO] ---------------------&lt; com.mycompany:myproject &gt;---------------------
    [INFO] Building mycompany.com Scheduler 0.0.1-SNAPSHOT
    [INFO] --------------------------------[ war ]---------------------------------
    [INFO] 
    [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ myproject ---
    [INFO] Deleting /home/user/workspace JavaEE/myproject/target
    [INFO] 
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ myproject ---
    [INFO] Using &#39;UTF-8&#39; encoding to copy filtered resources.
    [INFO] Copying 1 resource
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ myproject ---
    [INFO] Changes detected - recompiling the module!
    [INFO] Compiling 19 source files to /home/user/workspace JavaEE/myproject/target/classes
    [INFO] -------------------------------------------------------------
    [ERROR] COMPILATION ERROR : 
    [INFO] -------------------------------------------------------------
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[10,25] cannot find symbol
      symbol:   class HeuristicMixedException
      location: package javax.transaction
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[11,25] cannot find symbol
      symbol:   class HeuristicRollbackException
      location: package javax.transaction
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[12,25] cannot find symbol
      symbol:   class NotSupportedException
      location: package javax.transaction
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[13,25] cannot find symbol
      symbol:   class RollbackException
      location: package javax.transaction
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[14,25] cannot find symbol
      symbol:   class SystemException
      location: package javax.transaction
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[15,25] cannot find symbol
      symbol:   class UserTransaction
      location: package javax.transaction
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[31,13] cannot find symbol
      symbol:   class UserTransaction
      location: class controller.Delete&lt;T&gt;
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[77,49] cannot find symbol
      symbol:   class NotSupportedException
      location: class controller.Delete&lt;T&gt;
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[77,72] cannot find symbol
      symbol:   class SystemException
      location: class controller.Delete&lt;T&gt;
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[78,36] cannot find symbol
      symbol:   class RollbackException
      location: class controller.Delete&lt;T&gt;
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[78,55] cannot find symbol
      symbol:   class HeuristicMixedException
      location: class controller.Delete&lt;T&gt;
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[78,80] cannot find symbol
      symbol:   class HeuristicRollbackException
      location: class controller.Delete&lt;T&gt;
    
    ...
    
    [INFO] 36 errors 
    [INFO] -------------------------------------------------------------
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  3.186 s
    [INFO] Finished at: 2020-04-10T13:50:37+02:00
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project myproject: Compilation failure: Compilation failure: 
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[10,25] cannot find symbol
    [ERROR]   symbol:   class HeuristicMixedException
    [ERROR]   location: package javax.transaction
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[11,25] cannot find symbol
    [ERROR]   symbol:   class HeuristicRollbackException
    [ERROR]   location: package javax.transaction
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[12,25] cannot find symbol
    [ERROR]   symbol:   class NotSupportedException
    [ERROR]   location: package javax.transaction
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[13,25] cannot find symbol
    [ERROR]   symbol:   class RollbackException
    [ERROR]   location: package javax.transaction
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[14,25] cannot find symbol
    [ERROR]   symbol:   class SystemException
    [ERROR]   location: package javax.transaction
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[15,25] cannot find symbol
    [ERROR]   symbol:   class UserTransaction
    [ERROR]   location: package javax.transaction
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[31,13] cannot find symbol
    [ERROR]   symbol:   class UserTransaction
    [ERROR]   location: class controller.Delete&lt;T&gt;
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[77,49] cannot find symbol
    [ERROR]   symbol:   class NotSupportedException
    [ERROR]   location: class controller.Delete&lt;T&gt;
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[77,72] cannot find symbol
    [ERROR]   symbol:   class SystemException
    [ERROR]   location: class controller.Delete&lt;T&gt;
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[78,36] cannot find symbol
    [ERROR]   symbol:   class RollbackException
    [ERROR]   location: class controller.Delete&lt;T&gt;
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[78,55] cannot find symbol
    [ERROR]   symbol:   class HeuristicMixedException
    [ERROR]   location: class controller.Delete&lt;T&gt;
    [ERROR] /home/user/workspace JavaEE/myproject/src/main/java/controller/Delete.java:[78,80] cannot find symbol
    [ERROR]   symbol:   class HeuristicRollbackException
    [ERROR]   location: class controller.Delete&lt;T&gt;
    
    ...
    
    [ERROR] -&gt; [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/MojoFailureException

The `pom.xml` content is

    &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
    &lt;!-- JBoss, Home of Professional Open Source Copyright 2013, Red Hat, Inc. 
    	and/or its affiliates, and individual contributors by the @authors tag. See 
    	the copyright.txt in the distribution for a full listing of individual contributors. 
    	Licensed under the Apache License, Version 2.0 (the &quot;License&quot;); you may not 
    	use this file except in compliance with the License. You may obtain a copy 
    	of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required 
    	by applicable law or agreed to in writing, software distributed under the 
    	License is distributed on an &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS 
    	OF ANY KIND, either express or implied. See the License for the specific 
    	language governing permissions and limitations under the License. --&gt;
    &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
    	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
    	xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd&quot;&gt;
    	&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    
    	&lt;groupId&gt;com.mycompany&lt;/groupId&gt;
    	&lt;artifactId&gt;mycompany&lt;/artifactId&gt;
    	&lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
    	&lt;packaging&gt;war&lt;/packaging&gt;
    	&lt;name&gt;mycompany.com application&lt;/name&gt;
    	&lt;description&gt;A starter Java EE 7 webapp project for use on JBoss WildFly / WildFly, generated from the jboss-javaee6-webapp archetype&lt;/description&gt;
    
    	&lt;url&gt;http://wildfly.org&lt;/url&gt;
    	&lt;licenses&gt;
    		&lt;license&gt;
    			&lt;name&gt;Apache License, Version 2.0&lt;/name&gt;
    			&lt;distribution&gt;repo&lt;/distribution&gt;
    			&lt;url&gt;http://www.apache.org/licenses/LICENSE-2.0.html&lt;/url&gt;
    		&lt;/license&gt;
    	&lt;/licenses&gt;
    
    	&lt;properties&gt;
    		&lt;!-- Explicitly declaring the source encoding eliminates the following 
    			message: --&gt;
    		&lt;!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered 
    			resources, i.e. build is platform dependent! --&gt;
    		&lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
    
    		&lt;!-- JBoss dependency versions --&gt;
    		&lt;version.wildfly.maven.plugin&gt;1.0.2.Final&lt;/version.wildfly.maven.plugin&gt;
    
    		&lt;!-- Define the version of the JBoss BOMs we want to import to specify 
    			tested stacks. --&gt;
    		&lt;version.jboss.bom&gt;8.2.1.Final&lt;/version.jboss.bom&gt;
    
    		&lt;!-- other plugin versions --&gt;
    		&lt;version.compiler.plugin&gt;3.1&lt;/version.compiler.plugin&gt;
    		&lt;version.surefire.plugin&gt;2.16&lt;/version.surefire.plugin&gt;
    		&lt;version.war.plugin&gt;2.5&lt;/version.war.plugin&gt;
    
    		&lt;!-- maven-compiler-plugin --&gt;
    		&lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
    		&lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
    	&lt;/properties&gt;
    
    
    	&lt;dependencyManagement&gt;
    		&lt;dependencies&gt;
    			&lt;!-- JBoss distributes a complete set of Java EE 7 APIs including a Bill 
    				of Materials (BOM). A BOM specifies the versions of a &quot;stack&quot; (or a collection) 
    				of artifacts. We use this here so that we always get the correct versions 
    				of artifacts. Here we use the jboss-javaee-7.0-with-tools stack (you can 
    				read this as the JBoss stack of the Java EE 7 APIs, with some extras tools 
    				for your project, such as Arquillian for testing) and the jboss-javaee-7.0-with-hibernate 
    				stack you can read this as the JBoss stack of the Java EE 7 APIs, with extras 
    				from the Hibernate family of projects) --&gt;
    			&lt;dependency&gt;
    				&lt;groupId&gt;org.wildfly.bom&lt;/groupId&gt;
    				&lt;artifactId&gt;jboss-javaee-7.0-with-tools&lt;/artifactId&gt;
    				&lt;version&gt;${version.jboss.bom}&lt;/version&gt;
    				&lt;type&gt;pom&lt;/type&gt;
    				&lt;scope&gt;import&lt;/scope&gt;
    			&lt;/dependency&gt;
    			&lt;dependency&gt;
    				&lt;groupId&gt;org.wildfly.bom&lt;/groupId&gt;
    				&lt;artifactId&gt;jboss-javaee-7.0-with-hibernate&lt;/artifactId&gt;
    				&lt;version&gt;${version.jboss.bom}&lt;/version&gt;
    				&lt;type&gt;pom&lt;/type&gt;
    				&lt;scope&gt;import&lt;/scope&gt;
    			&lt;/dependency&gt;
    		&lt;/dependencies&gt;
    	&lt;/dependencyManagement&gt;
    
    	&lt;dependencies&gt;
    
    		&lt;!-- First declare the APIs we depend on and need for compilation. All 
    			of them are provided by JBoss WildFly --&gt;
    
    		&lt;!-- Import the CDI API, we use provided scope as the API is included in 
    			JBoss WildFly --&gt;
    		&lt;dependency&gt;
    			&lt;groupId&gt;javax.enterprise&lt;/groupId&gt;
    			&lt;artifactId&gt;cdi-api&lt;/artifactId&gt;
    			&lt;scope&gt;provided&lt;/scope&gt;
    		&lt;/dependency&gt;
    
    		&lt;!-- Import the Common Annotations API (JSR-250), we use provided scope 
    			as the API is included in JBoss WildFly --&gt;
    		&lt;dependency&gt;
    			&lt;groupId&gt;org.jboss.spec.javax.annotation&lt;/groupId&gt;
    			&lt;artifactId&gt;jboss-annotations-api_1.2_spec&lt;/artifactId&gt;
    			&lt;scope&gt;provided&lt;/scope&gt;
    		&lt;/dependency&gt;
    
    		&lt;!-- Import the JAX-RS API, we use provided scope as the API is included 
    			in JBoss WildFly --&gt;
    		&lt;dependency&gt;
    			&lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
    			&lt;artifactId&gt;jaxrs-api&lt;/artifactId&gt;
    			&lt;scope&gt;provided&lt;/scope&gt;
    		&lt;/dependency&gt;
    
    		&lt;!-- Import the JPA API, we use provided scope as the API is included in 
    			JBoss WildFly --&gt;
    		&lt;dependency&gt;
    			&lt;groupId&gt;org.hibernate.javax.persistence&lt;/groupId&gt;
    			&lt;artifactId&gt;hibernate-jpa-2.1-api&lt;/artifactId&gt;
    			&lt;scope&gt;provided&lt;/scope&gt;
    		&lt;/dependency&gt;
    
    		&lt;!-- Import the EJB API, we use provided scope as the API is included in 
    			JBoss WildFly --&gt;
    		&lt;dependency&gt;
    			&lt;groupId&gt;org.jboss.spec.javax.ejb&lt;/groupId&gt;
    			&lt;artifactId&gt;jboss-ejb-api_3.2_spec&lt;/artifactId&gt;
    			&lt;scope&gt;provided&lt;/scope&gt;
    		&lt;/dependency&gt;
    
    		&lt;!-- JSR-303 (Bean Validation) Implementation --&gt;
    		&lt;!-- Provides portable constraints such as @Email --&gt;
    		&lt;!-- Hibernate Validator is shipped in JBoss WildFly --&gt;
    		&lt;dependency&gt;
    			&lt;groupId&gt;org.hibernate&lt;/groupId&gt;
    			&lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;
    			&lt;scope&gt;provided&lt;/scope&gt;
    			&lt;exclusions&gt;
    				&lt;exclusion&gt;
    					&lt;groupId&gt;org.slf4j&lt;/groupId&gt;
    					&lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
    				&lt;/exclusion&gt;
    			&lt;/exclusions&gt;
    		&lt;/dependency&gt;
    
    		&lt;!-- Import the JSF API, we use provided scope as the API is included in 
    			JBoss WildFly --&gt;
    		&lt;dependency&gt;
    			&lt;groupId&gt;org.jboss.spec.javax.faces&lt;/groupId&gt;
    			&lt;artifactId&gt;jboss-jsf-api_2.2_spec&lt;/artifactId&gt;
    			&lt;scope&gt;provided&lt;/scope&gt;
    		&lt;/dependency&gt;
    
    		&lt;!-- Now we declare any tools needed --&gt;
    
    		&lt;!-- Annotation processor to generate the JPA 2.0 metamodel classes for 
    			typesafe criteria queries --&gt;
    		&lt;dependency&gt;
    			&lt;groupId&gt;org.hibernate&lt;/groupId&gt;
    			&lt;artifactId&gt;hibernate-jpamodelgen&lt;/artifactId&gt;
    			&lt;scope&gt;provided&lt;/scope&gt;
    		&lt;/dependency&gt;
    
    		&lt;!-- Annotation processor that raising compilation errors whenever constraint 
    			annotations are incorrectly used. --&gt;
    		&lt;dependency&gt;
    			&lt;groupId&gt;org.hibernate&lt;/groupId&gt;
    			&lt;artifactId&gt;hibernate-validator-annotation-processor&lt;/artifactId&gt;
    			&lt;scope&gt;provided&lt;/scope&gt;
    		&lt;/dependency&gt;
    
    		&lt;!-- Needed for running tests (you may also use TestNG) --&gt;
    		&lt;dependency&gt;
    			&lt;groupId&gt;junit&lt;/groupId&gt;
    			&lt;artifactId&gt;junit&lt;/artifactId&gt;
    			&lt;scope&gt;test&lt;/scope&gt;
    		&lt;/dependency&gt;
    
    		&lt;!-- Optional, but highly recommended --&gt;
    		&lt;!-- Arquillian allows you to test enterprise code such as EJBs and Transactional(JTA) 
    			JPA from JUnit/TestNG --&gt;
    		&lt;dependency&gt;
    			&lt;groupId&gt;org.jboss.arquillian.junit&lt;/groupId&gt;
    			&lt;artifactId&gt;arquillian-junit-container&lt;/artifactId&gt;
    			&lt;scope&gt;test&lt;/scope&gt;
    		&lt;/dependency&gt;
    
    		&lt;dependency&gt;
    			&lt;groupId&gt;org.jboss.arquillian.protocol&lt;/groupId&gt;
    			&lt;artifactId&gt;arquillian-protocol-servlet&lt;/artifactId&gt;
    			&lt;scope&gt;test&lt;/scope&gt;
    		&lt;/dependency&gt;
    
    	&lt;/dependencies&gt;
    
    	&lt;build&gt;
    		&lt;!-- Maven will append the version to the finalName (which is the name 
    			given to the generated war, and hence the context root) --&gt;
    		&lt;finalName&gt;${project.artifactId}&lt;/finalName&gt;
    		&lt;plugins&gt;
    			&lt;plugin&gt;
    				&lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
    				&lt;version&gt;${version.war.plugin}&lt;/version&gt;
    				&lt;configuration&gt;
    					&lt;!-- Java EE 7 doesn&#39;t require web.xml, Maven needs to catch up! --&gt;
    					&lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
    				&lt;/configuration&gt;
    			&lt;/plugin&gt;
    			&lt;!-- The WildFly plugin deploys your war to a local WildFly container --&gt;
    			&lt;!-- To use, run: mvn package wildfly:deploy --&gt;
    			&lt;plugin&gt;
    				&lt;groupId&gt;org.wildfly.plugins&lt;/groupId&gt;
    				&lt;artifactId&gt;wildfly-maven-plugin&lt;/artifactId&gt;
    				&lt;version&gt;${version.wildfly.maven.plugin}&lt;/version&gt;
    			&lt;/plugin&gt;
    		&lt;/plugins&gt;
    	&lt;/build&gt;
    
    	&lt;profiles&gt;
    		&lt;profile&gt;
    			&lt;!-- The default profile skips all tests, though you can tune it to run 
    				just unit tests based on a custom pattern --&gt;
    			&lt;!-- Seperate profiles are provided for running all tests, including Arquillian 
    				tests that execute in the specified container --&gt;
    			&lt;id&gt;default&lt;/id&gt;
    			&lt;activation&gt;
    				&lt;activeByDefault&gt;true&lt;/activeByDefault&gt;
    			&lt;/activation&gt;
    			&lt;build&gt;
    				&lt;plugins&gt;
    					&lt;plugin&gt;
    						&lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
    						&lt;version&gt;${version.surefire.plugin}&lt;/version&gt;
    						&lt;configuration&gt;
    							&lt;skip&gt;true&lt;/skip&gt;
    						&lt;/configuration&gt;
    					&lt;/plugin&gt;
    				&lt;/plugins&gt;
    			&lt;/build&gt;
    		&lt;/profile&gt;
    
    		&lt;profile&gt;
    
    			&lt;!-- An optional Arquillian testing profile that executes tests in your 
    				WildFly instance --&gt;
    			&lt;!-- This profile will start a new WildFly instance, and execute the test, 
    				shutting it down when done --&gt;
    			&lt;!-- Run with: mvn clean test -Parq-wildfly-managed --&gt;
    			&lt;id&gt;arq-wildfly-managed&lt;/id&gt;
    			&lt;dependencies&gt;
    				&lt;dependency&gt;
    					&lt;groupId&gt;org.wildfly&lt;/groupId&gt;
    					&lt;artifactId&gt;wildfly-arquillian-container-managed&lt;/artifactId&gt;
    					&lt;scope&gt;test&lt;/scope&gt;
    				&lt;/dependency&gt;
    			&lt;/dependencies&gt;
    		&lt;/profile&gt;
    
    		&lt;profile&gt;
    			&lt;!-- An optional Arquillian testing profile that executes tests in a remote 
    				WildFly instance --&gt;
    			&lt;!-- Run with: mvn clean test -Parq-wildfly-remote --&gt;
    			&lt;id&gt;arq-wildfly-remote&lt;/id&gt;
    			&lt;dependencies&gt;
    				&lt;dependency&gt;
    					&lt;groupId&gt;org.wildfly&lt;/groupId&gt;
    					&lt;artifactId&gt;wildfly-arquillian-container-remote&lt;/artifactId&gt;
    					&lt;scope&gt;test&lt;/scope&gt;
    				&lt;/dependency&gt;
    			&lt;/dependencies&gt;
    		&lt;/profile&gt;
    
    		&lt;profile&gt;
    			&lt;!-- When built in OpenShift the &#39;openshift&#39; profile will be used when 
    				invoking mvn. --&gt;
    			&lt;!-- Use this profile for any OpenShift specific customization your app 
    				will need. --&gt;
    			&lt;!-- By default that is to put the resulting archive into the &#39;deployments&#39; 
    				folder. --&gt;
    			&lt;!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html --&gt;
    			&lt;id&gt;openshift&lt;/id&gt;
    			&lt;build&gt;
    				&lt;plugins&gt;
    					&lt;plugin&gt;
    						&lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
    						&lt;version&gt;${version.war.plugin}&lt;/version&gt;
    						&lt;configuration&gt;
    							&lt;outputDirectory&gt;deployments&lt;/outputDirectory&gt;
    							&lt;warName&gt;ROOT&lt;/warName&gt;
    						&lt;/configuration&gt;
    					&lt;/plugin&gt;
    				&lt;/plugins&gt;
    			&lt;/build&gt;
    		&lt;/profile&gt;
    
    	&lt;/profiles&gt;
    &lt;/project&gt;

The code for the Delete.java source is

    package controller;
    
    import java.io.Serializable;
    
    import javax.annotation.PostConstruct;
    import javax.annotation.Resource;
    import javax.persistence.EntityManager;
    import javax.persistence.EntityManagerFactory;
    import javax.persistence.PersistenceUnit;
    import javax.transaction.HeuristicMixedException;
    import javax.transaction.HeuristicRollbackException;
    import javax.transaction.NotSupportedException;
    import javax.transaction.RollbackException;
    import javax.transaction.SystemException;
    import javax.transaction.UserTransaction;
    
    import model.EntityType;
    import service.LogService;
    
    /** class for deleting SINGLE entities */
    public abstract class Delete&lt;T extends EntityType&gt; implements Serializable {
    
        private static final long serialVersionUID = 5315202645032974752L;
    
        @PersistenceUnit
        private EntityManagerFactory emf;
    
        private EntityManager entityManager;
    
        @Resource
        private UserTransaction ta;
    
        @PostConstruct
        private void postConstruct() {
            entityManager = emf.createEntityManager();
        }
    
        /**
         * {@link EntityManager} might be necessary in
         * {@link #removeForeignEntities(EntityType)}
         *
         * @return {@link EntityManager}
         */
        public EntityManager getEntityManager() {
            return entityManager;
        }
    
        /**
         * configure targeted face
         *
         * @return String null (no redirection per default)
         */
        protected String redirect() {
            return null;
        }
    
        /** remove foreign entities from entity {@link T} */
        protected void removeForeignEntities(final T entity) {
            // remove
        }
    
        /**
         * delete entity by adding selected record in JSF
         *
         * &lt;div&gt;e.g.:
         *
         * &lt;pre&gt;
         * &lt;code&gt;
         * &amp;lt;h:commandButton action=&quot;#{activityDelete.delete(item)}&quot; /&amp;gt;
         * &lt;/code&gt;
         * &lt;/pre&gt;
         *
         * &lt;/div&gt;
         *
         * @return {@link #redirect()}
         */
        public String delete(final T entity) throws NotSupportedException, SystemException, SecurityException,
                IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException {
            LogService.getLogger(this).info(new StringBuffer(&quot;delete(T): &quot;).append(entity).toString());
            ta.begin();
            // type safety already fulfilled by definition &lt;T extends EntityType&gt;
            @SuppressWarnings(&quot;unchecked&quot;)
            final T deleteEntity = (T) entityManager.find(entity.getClass(), entity.getId());
            removeForeignEntities(deleteEntity);
            entityManager.remove(deleteEntity);
            ta.commit();
            return redirect();
        }
    
    }

and for EntityType.java is

    package model;
    
    import java.io.Serializable;
    
    /**
     * This bean is necessary to inject the entity to the CRUD beans.
     *
     * This must not be an interface or an abstract class since its not supported
     * for the ORM (JBoss) implementation.
     *
     *
     * console warning
     *
     * &lt;pre&gt;
     * console warning &quot;Multiple beans are eligible for injection to the injection point&quot;
     * &lt;/pre&gt;
     *
     * Eclipse IDE error
     *
     * &lt;pre&gt;
     * Multiple markers at this line
        - Multiple beans are eligible for injection to the injection point [JSR-346
         &#167;5.2.2]
        - Injection point type cannot be a type variable [JSR-346 &#167;5.2.3]
     * &lt;/pre&gt;
     */
    public class EntityType implements Serializable {
    
        private static final long serialVersionUID = -6260606086182547955L;
    
        public EntityType() {
            // default constructor
        }
    
        public Long getId() {
            return null;
        }
    
    }

I guess I can solve this problem with changing `&lt;version.compiler.plugin&gt;3.1&lt;/version.compiler.plugin` to `&lt;version.compiler.plugin&gt;3.6&lt;/version.compiler.plugin` or `&lt;version.compiler.plugin&gt;3.6.0&lt;/version.compiler.plugin` but both gives the same results.

What do I misunderstand and what is here the solution to fix this problem?


</details>


# 答案1
**得分**: 0

我找到了解决方案来解决我的问题。一旦我在“Eclipse IDE”中在“Java Build Path”注册中手动添加了事务API。

我在`pom.xml`中添加了正确API的依赖项。
&lt;!-- https://mvnrepository.com/artifact/org.jboss.spec.javax.transaction/jboss-transaction-api_1.3_spec --&gt;

    &lt;dependency&gt;
        &lt;groupId&gt;org.jboss.spec.javax.transaction&lt;/groupId&gt;
        &lt;artifactId&gt;jboss-transaction-api_1.3_spec&lt;/artifactId&gt;
        &lt;version&gt;2.0.0.Final&lt;/version&gt;
    &lt;/dependency&gt;

在`project/dependencies`节点中。

执行命令`mvn clean install compile -U`的结果为

    [INFO] ------------------------------------------------------------------------
    [INFO] 构建成功
    [INFO] ------------------------------------------------------------------------
    [INFO] 总时间:  4.363 秒
    [INFO] 完成于: 2020-04-10T16:10:26+02:00
    [INFO] ------------------------------------------------------------------------

并且可以部署到wildfly服务器。

附注:在执行命令之前,我还从“Java Build Path”中删除了jboss-transaction-api_1.3_spec-2.0.0.Final.jar。

<details>
<summary>英文:</summary>

I found a solution for my problem. Once I added the transaction api manually in &quot;Eclipse IDE&quot; in the &quot;Java Build Path&quot; register.

[![enter image description here][1]][1]


  [1]: https://i.stack.imgur.com/ycXaI.png

I added to the `pom.xml` the dependency for the right api.
&lt;!-- https://mvnrepository.com/artifact/org.jboss.spec.javax.transaction/jboss-transaction-api_1.3_spec --&gt;

    &lt;dependency&gt;
        &lt;groupId&gt;org.jboss.spec.javax.transaction&lt;/groupId&gt;
        &lt;artifactId&gt;jboss-transaction-api_1.3_spec&lt;/artifactId&gt;
        &lt;version&gt;2.0.0.Final&lt;/version&gt;
    &lt;/dependency&gt;

within the `project/dependencies` node.

Executing the command `mvn clean install compile -U` results to

    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  4.363 s
    [INFO] Finished at: 2020-04-10T16:10:26+02:00
    [INFO] ------------------------------------------------------------------------

and can be deployed to the wildfly server.

P.S.: I also removed the jboss-transaction-api_1.3_spec-2.0.0.Final.jar from the &quot;Java Build Path&quot; before executing the command.

</details>



huangapple
  • 本文由 发表于 2020年4月10日 20:26:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/61140204.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定