Can the classpath scanning be controlled in Weld?
Asked Answered
P

3

12

I was playing with Weld-SE (Java SE) and noticed that if there are a lot of JARs in the classpath, the JVM startup time runs into several seconds.

Isn't there a way to specify/restrict the scan path as a package pattern or path pattern like in Apache Ant or AspectJ?

PS: Registration on Weld forum just does not work - it keeps saying "your password is trivial"

Permanent answered 18/8, 2011 at 22:28 Comment(0)
D
14

Starting with weld 1.1.0, it is possible according to Weld reference documentation :

<beans xmlns="http://java.sun.com/xml/ns/javaee" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xmlns:weld="http://jboss.org/schema/weld/beans" 
       xsi:schemaLocation="
          http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd
          http://jboss.org/schema/weld/beans http://jboss.org/schema/weld/beans_1_1.xsd">
    <weld:scan>
        <weld:exclude name="mypackage.MyClass"/>
    </weld:scan>
</beans>
Dancy answered 21/8, 2011 at 19:3 Comment(0)
B
6

You can with CDI 1.1. The 1st answer works fine, but this snippet works on any provider:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
    version="1.1" bean-discovery-mode="all">

    <scan>
        <exclude name="my.cool.package" />

        <!-- you can exclude with condition -->
        <exclude name="my.cool.package.for.jodatime" />
            <if-class-not-available name="org.joda.time.LocalDate"/>
        </exclude>
    </scan>
</beans>
Because answered 21/1, 2014 at 3:57 Comment(0)
C
4

Good questions, but I don't think it is possible. Each archive is scanned for beans.xml, by spec.

Circumfluous answered 21/8, 2011 at 16:7 Comment(3)
guess it's time for you to remove that answer, @Circumfluous : previous one is perfectly valid.Doityourself
@Doityourself thanks. I thought of deleting it, but as per the CDI spec there is no way. Weld is just one implementation. I have upvoted the other answer, as it is practically the most applicable one.Circumfluous
Indeed, I forgot the non-standard aspect, thanks for explaination.Doityourself

© 2022 - 2024 — McMap. All rights reserved.