Juan Ayala
Juan Ayala

Reputation: 3528

JCR Node imported as nt:file when using content-package-maven-plugin

I created an OSGI config JCR node in XML within my Adobe CQ project under /apps/myproject/config/org.apache.sling.commons.log.LogManager.factory.config-MYPROJECT.xml

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root
    xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
    xmlns:jcr="http://www.jcp.org/jcr/1.0"
    jcr:primaryType="sling:OsgiConfig"
    org.apache.sling.commons.log.level="Trace"
    org.apache.sling.commons.log.file="logs/myproject.log"
    org.apache.sling.commons.log.file.number="5"
    org.apache.sling.commons.log.file.size="5MB"
    org.apache.sling.commons.log.pattern="\{0,date,HH:mm:ss.SSS} *{4}* {3} {5}"
    org.apache.sling.commons.log.names="[com.mycompany.myproject]" />

Problem is that when it gets imported into the JCR, it is showing up as an nt:file instead of what it should be according to its jcr:primaryType so that it look like this in CRXDE

incorrect import as nt:file

when it should look like this

expected import as sling:OsgiConfig

Upvotes: 0

Views: 976

Answers (3)

Juan Ayala
Juan Ayala

Reputation: 3528

So my XML markup starts EXACTLY as follows:

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root
    xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
    ...

What I had done originally was to create a new xml file and put in my config. There are 2 other ways I know to create nodes

  1. By doing it in CRXDE and then using vault to export
  2. By doing it in Eclipse using the AEM developer tools (Eclipse plugin for Apache Sling)

In the case of a vault export, the XML starts like this:

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" ...

and in the case of the plugin, it starts like this

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root 
    xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
    ...

but wait, you can't see it here, the plugin actually adds a friggin blank space right after jcr:root.

So whatever XML parser is acting on these XML files to create nodes in the JRC, it behaves oddly if there is no space right after the root node name. I'm on Windows, using Maven 3.2.3, using version 0.0.20 of content-package-maven-plugin, and AEM 5.6.1.

Upvotes: 1

Vivek Dhiman
Vivek Dhiman

Reputation: 1997

You need to add jcr:mixinTypes="[]" type as a property to your logger. So Your configuration will be like :

 <?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
        jcr:mixinTypes="[]"
        jcr:primaryType="sling:OsgiConfig"
        org.apache.sling.commons.log.level="Trace"
        org.apache.sling.commons.log.file="logs/myproject.log"
        org.apache.sling.commons.log.file.number="5"
        org.apache.sling.commons.log.file.size="5MB"
        org.apache.sling.commons.log.pattern="\{0,date,HH:mm:ss.SSS} *{4}* {3} {5}"
        org.apache.sling.commons.log.names="[com.mycompany.myproject]" />

Hope this will help.

Upvotes: 0

Thomas
Thomas

Reputation: 1312

Please check your filter definition of the content-package-maven-plugin. If your filter root is set to

<filter>
<root>
/apps/myproject/config/org.apache.sling.commons.log.LogManager.factory.config-MYPROJECT.xml
</root>
</filter> 

instead of

<filter>
<root>
/apps/myproject/config/org.apache.sling.commons.log.LogManager.factory.config-MYPROJECT
</root>
</filter> 

then it will likely just put the file into your repository instead of creating the configuration node. The latter one without .xml file extension is correct.

Upvotes: 0

Related Questions