我们在WAS8中运行了一个Java Entreprise应用程序。该应用程序需要运行SonarQube AntTask来分析某些类。
执行Ant任务时,SonarQube初始化Hibernate。这是SystemOut日志:
INFO - Load batch settings
INFO - User cache: /home/SVCEsDev0066/.sonar/cache
INFO - Install plugins
INFO - Install JDBC driver
INFO - Create JDBC datasource for jdbc:mysql://180.101.185.60:3306/sonar?useUnicode=true&characterEncoding=utf8
INFO - Initializing Hibernate
之后我们会收到以下错误消息:
org.sonar.runner.impl.RunnerException: Unable to execute Sonar
at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:91)
at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75)
at java.security.AccessController.doPrivileged(AccessController.java:229)
at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102)
at org.sonar.runner.api.Runner.execute(Runner.java:100)
at org.sonar.ant.SonarTask.launchAnalysis(SonarTask.java:53)
at org.sonar.ant.SonarTask.execute(SonarTask.java:48)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor152.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:613)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
at org.sgb.builder.jobs.BuilderJob.checkoutAndBuild(BuilderJob.java:277)
at org.sgb.builder.jobs.BuilderJob.execute(BuilderJob.java:90)
at org.quartz.core.JobRunShell.run(JobRunShell.java:216)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
Caused by: javax.persistence.PersistenceException: java.lang.ClassNotFoundException: com.ibm.websphere.persistence.PersistenceProviderImpl
at javax.persistence.Persistence.findAllProviders(Persistence.java:93)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:49)
at org.sonar.jpa.session.AbstractDatabaseConnector.createEntityManagerFactory(AbstractDatabaseConnector.java:66)
at org.sonar.jpa.session.AbstractDatabaseConnector.start(AbstractDatabaseConnector.java:46)
at org.sonar.jpa.session.DefaultDatabaseConnector.start(DefaultDatabaseConnector.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:88)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:613)
at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.invokeMethod(ReflectionLifecycleStrategy.java:110)
at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.start(ReflectionLifecycleStrategy.java:89)
at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.start(AbstractInjectionFactory.java:84)
at org.picocontainer.behaviors.AbstractBehavior.start(AbstractBehavior.java:169)
at org.picocontainer.behaviors.Stored$RealComponentLifecycle.start(Stored.java:132)
at org.picocontainer.behaviors.Stored.start(Stored.java:110)
at org.picocontainer.DefaultPicoContainer.potentiallyStartAdapter(DefaultPicoContainer.java:1015)
at org.picocontainer.DefaultPicoContainer.startAdapters(DefaultPicoContainer.java:1008)
at org.picocontainer.DefaultPicoContainer.start(DefaultPicoContainer.java:766)
at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:91)
at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77)
at org.sonar.batch.bootstrapper.Batch.startBatch(Batch.java:92)
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:74)
at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:88)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:613)
at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:87)
... 22 more
Caused by: java.lang.ClassNotFoundException: com.ibm.websphere.persistence.PersistenceProviderImpl
at java.net.URLClassLoader.findClass(URLClassLoader.java:599)
at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:743)
at java.lang.ClassLoader.loadClass(ClassLoader.java:720)
at java.lang.ClassLoader.loadClass(ClassLoader.java:690)
at javax.persistence.Persistence.findAllProviders(Persistence.java:79)
... 49 more
Sonar正在尝试加载类: com.ibm.websphere.persistence.PersistenceProviderImpl ,它是Application Server JPA配置的提供程序。我们尝试将提供程序从WAS控制台更改为使用OpenJPA,但没有任何改变:它尝试再次加载同一个类。
反正是否迫使Sonar不使用此提供商? 另一种方法是强制Sonar加载com.ibm.websphere.persistence.PersistenceProviderImpl类,但是,我们在哪里可以找到它?而且,我们怎么能强迫它?
我们已经开始使用SonarQube 4.3.2,在第一次出错后我们将其更新为4.5.1。 SonarAntTask版本是2.2。这是我们的AntTask代码:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="sonar" name="SonarAnt">
<target name="sonar">
<taskdef resource="org/sonar/ant/antlib.xml" uri="antlib:org.sonar.ant" classpath="sonar-ant-task-2.2.jar"/>
<sonar:sonar xmlns:sonar="antlib:org.sonar.ant"/>
</target>
<property name="sonar.java.source" value="1.7"/>
<property name="sonar.projectVersion" value="build_2"/>
<property name="sonar.jdbc.password" value="******"/>
<property name="sonar.host.url" value="http://***.***.***.***:9000"/>
<property name="sonar.jdbc.username" value="******"/>
<property name="sonar.jdbc.url" value="jdbc:mysql://***.***.***.***:3600/sonar? useUnicode=true&amp;characterEncoding=utf8"/>
<property name="sonar.projectKey" value="PortalSGS_V01R00F00"/>
<property name="sonar.projectName" value="PortalSGS Desc"/>
<property name="sonar.modules" value="sgs-business-review"/>
<property name="sgs-business-review.sonar.projectName" value="sgs-business-review"/>
<property name="sgs-business-review.sonar.projectBaseDir" value="C:\ARQDISP\tmp\CreavistaBL_xIS10460_20140806_110225\vSGS_Portal\SGS_Business_ALM\sgs-business-review"/>
<property name="sgs-business-review.sonar.sources" value="src"/>
我们还尝试在te ant任务定义中指定类路径,如下所示:
<target name="sonar">
<taskdef resource="org/sonar/ant/antlib.xml" uri="antlib:org.sonar.ant" classpath="sonar-ant-task-2.2.jar"/>
<sonar:sonar xmlns:sonar="antlib:org.sonar.ant"/>
但什么都没发生。
这是我们的应用程序调用任务的方式:
1.-创建一个类似于show
的antTask.xml2.-初始化一个org.apache.tools.ant.Project对象和一个org.apache.tools.ant.ProjectHelper
3.-它从Project类调用executeTarget方法。
提前致谢。