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"

Ashwin Jayaprakash
  • 2,168
  • 24
  • 29

3 Answers3

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>
Riduidel
  • 22,052
  • 14
  • 85
  • 185
Dar Whi
  • 822
  • 5
  • 14
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>
Otávio Garcia
  • 1,372
  • 1
  • 15
  • 27
4

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

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • guess it's time for you to remove that answer, @Bozho : previous one is perfectly valid. – Riduidel Mar 12 '12 at 10:53
  • 4
    @Riduidel 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. – Bozho Mar 12 '12 at 11:21
  • 1
    Indeed, I forgot the non-standard aspect, thanks for explaination. – Riduidel Mar 12 '12 at 12:41