How can I use different JARs for compiling and testing in maven? -


I compile my program against javaee-api. But for junit testing I should use a specific implementation such as the javaizer of glassfish. To avoid errors such as java.lang.ClassFormatError: The attribute in the absent code attribute that is not original or intangible in the class file javax / persistence / persistence (see also).

Avoid using the method, which is only available in the glassfish implementation, I want to compile my artifact with the normal API but execute the junit with the implementation jar. But both offer the same named classes and inferfaces, so the class loader gets bothered.

What is the best way to solve this problem? Can I solve this problem with Maven?

Thank you very much

I think this is possible. In fact, when starting with version 2.0.9, Maven uses POM commands to create a classpath, so that you can manipulate it anymore. And if you combine this with you, then it is possible to achieve whatever you want. In practice, if you have a first javaee-api scope of glassfish with javib dependence ( test ) , The former should be placed later in the test classpath and is thus used by the unit test, while later it will be used during the compilation. In principle, this should work, but it is a bit fragile, so it needs to be carefully documented.

Something like this (with a fictional GFv3 jar):

   & Lt; Version & gt; 6.0 & lt; / Edition & gt; & Lt; Scope & gt; Trial & lt; / Scope & gt; & Lt; Dependency & gt; & Lt; Dependency & gt; & Lt ;! - It will be used during a compilation - & gt; & Lt; Group & gt; Javax.javaee-api & lt; / Group & gt; & Lt; ArtifactId & gt; Javaee-api & lt; / ArtifactId> & Lt; Version & gt; 6.0 & lt; / Edition & gt; & Lt; Scope & gt; Provided & lt; / Scope & gt; & Lt; Dependency & gt; ... & lt; / Dependencies & gt;  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -