[ 
https://issues.apache.org/jira/browse/SUREFIRE-1427?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16805780#comment-16805780
 ] 

Martin Gainty commented on SUREFIRE-1427:
-----------------------------------------

2 years later I have a axiom-dom jar that is not found

 <plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-surefire-plugin</artifactId>
 <version>2.22.0</version>
 <configuration>
 <tempDir>target/surefire</tempDir>
 <forkMode>never</forkMode>
 <forkedProcessExitTimeoutInSeconds>600</forkedProcessExitTimeoutInSeconds>
 <forkedProcessTimeoutInSeconds>600</forkedProcessTimeoutInSeconds>
 <excludesFile>src/test/resources/exclude.txt</excludesFile>
 <exclude>org.apache.axiom.ts.om.xop.XOPRoundtripTest</exclude>
 <exclude>org.apache.axiom.ts.om.xpath.TestAddNamespaces2</exclude>
 <exclude>org.apache.axiom.ts.om.xpath.TestAddNamespaces</exclude>
 <exclude>org.apache.axiom.ts.soap.body.TestAddFault1</exclude>
 <exclude>org.apache.axiom.ts.om.xop.TestSetOptimize</exclude>
 <exclude>org.apache.axiom.ts.soap.body.TestAddFault2</exclude>
 <exclude>org.apache.axiom.ts.om.xpath.TestGetAttributeQName</exclude>
 <excludes>
 <exclude>**/XOPRoundtripTest*</exclude>
 <exclude>**/org/apache/axiom/ts/om/xop</exclude>
 <exclude>**/TestGetAttributeQName*</exclude>
 <exclude>**/TestDigestWithoutNamespace*</exclude>
 <exclude>**/TestAddFault*</exclude>
 <exclude>**/SOAPTestCase*</exclude>
 </excludes>
 </configuration>
 <dependencies>
 <dependency>
 <groupId>org.apache.ws.commons.axiom</groupId>
 <artifactId>axiom-dom</artifactId>
 <version>1.3.0</version>
 </dependency>

its clear axiom-dom is declared on classpath  for surefire
but i get:
[ERROR] org.apache.axiom.ts.om.attribute.TestSetNamespace [uri=urn:test] 
[PrefixFromSetNamespaceTestCase=p] [invalid=false] [declare=false] 
[owner=false](OMAbstractFactory::getMetaFactory LINE 163 locator=null
OMAbstractFactory::getMetaFactory LINE 165 
defaultMetaFactoryLocator=org.apache.axiom.locator.PriorityBasedOMMetaFactoryLocator@2bca0ace
OMAbstractFactory::getMetaFactory LINE 168 before 
locator.getOMMetaFactory(feature) where feature=dom
OMAbstractFactory::getMetaFactory LINE 170 metaFactory=null
OMAbstractFactory::getMetaFactory LINE 180 jarHint = axiom-dom.jar
OMAbstractFactory::getMetaFactory LINE 186 new OMException buffer=No meta 
factory found for feature 'dom'; this usually means that axiom-dom-1.3.jar is 
not in the classpath

//BUT IT IS ON TEST CLASSPATH

so in OMAbstractFactory i can resolve this CNFE with 
1)get OMAbstractFactory.class
2)get the isolated TEST classloader
3)run thru all of the loaded classes for TEST classloader
and find the class
4)use new instance() for the previously loaded DOM class
here is legacy code:

 public OMMetaFactory getMetaFactory(String feature) {
 System.out.println("OMAbstractFactory::getMetaFactory LINE 161 
feature="+feature);
 OMMetaFactoryLocator locator = metaFactoryLocator;
 System.out.println("OMAbstractFactory::getMetaFactory LINE 163 
locator="+locator);

 if (locator == null) {
 System.out.println("OMAbstractFactory::getMetaFactory LINE 165 
defaultMetaFactoryLocator="+defaultMetaFactoryLocator);
 locator = defaultMetaFactoryLocator;
 }
 System.out.println("OMAbstractFactory::getMetaFactory LINE 168 before 
locator.getOMMetaFactory(feature) where feature="+feature);
//in my case it is axiom-dom-1.3.jar

 OMMetaFactory metaFactory = null;
 if(locator!=null) metaFactory=locator.getOMMetaFactory(feature);
 System.out.println("OMAbstractFactory::getMetaFactory LINE 170 
metaFactory="+metaFactory);

 if (metaFactory == null)
 {
 String jarHint;
 if (feature.equals(FEATURE_DEFAULT)) {
 jarHint = "axiom-impl-1.3.jar";
 } else if (feature.equals(FEATURE_DOM)) {
 jarHint = "axiom-dom-1.3.jar";
 } else {
 jarHint = "axiom-dom-1.3.jar";
 }
 System.out.println("OMAbstractFactory::getMetaFactory LINE 180 jarHint = 
"+jarHint);
 StringBuilder buffer = new StringBuilder();
 buffer.append("No meta factory found for feature 
'").append(feature).append("'");
 if (jarHint != null) {
 buffer.append("; this usually means that ").append(jarHint).append(" is not in 
the classpath");
 }
 throw new OMException(buffer.toString());
}

i would do anything not to be forced to use TEST ClassLoader
i had similar situations with Kristian when he was chair but thus far
no resolution (except to use Reflection with Classloader) code

Thoughts?

> Surefire-plugin throws NoClassDefFoundError with static initialiser
> -------------------------------------------------------------------
>
>                 Key: SUREFIRE-1427
>                 URL: https://issues.apache.org/jira/browse/SUREFIRE-1427
>             Project: Maven Surefire
>          Issue Type: Bug
>          Components: Maven Surefire Plugin
>    Affects Versions: 2.20
>         Environment: jdk 1.8
> maven 3.3.3
>            Reporter: Martin Gainty
>            Assignee: Tibor Digana
>            Priority: Minor
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> when maven-surefire-plugin encounters static initialiser such as
> public class AxisDescription {
>         org.apache.axiom.om.OMFactory omFactory = 
> org.apache.axiom.om.OMAbstractFactory.getOMFactory();
> //surefire throws NoClassDefFoundError on OMAbstractFactory ?!?!?
> //but if i remove static initialiser to wait until runtime to load 
> OMAbstractFactory it loads ok
> org.apache.axis2.description.AxisDescription:
>   public void setDocumentation(String documentation) {
>         org.apache.axiom.om.OMFactory omFactory = 
> org.apache.axiom.om.OMAbstractFactory.getOMFactory();
>         if (!"".equals(documentation)) {
>             this.documentation = omFactory.createOMText(documentation);
>         }
>     }
> why does surefire not find classes referenced by static initialiser?



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to