Developing add-on - problem with dependencies?

Hello,
I need to develope a jar file for Vaadin application - so this is an add-one :wink:
When I run my project as Vaadin application it works properly, but when I pack it as a jar file and add to another project I get:

javax.servlet.ServletException: com.vaadin.server.ServiceException: java.lang.NoClassDefFoundError: com/vaadin/ui/CustomComponent I believe, that problem is with class loaders as vaadin core classes are once loaded from the main application and, at the same time, from another jar, but I don’t know how to reslove the problem.
My “add-on” requires vaadin-server.jar and one another vaadin add-on.
The full stack strace is:

java.lang.NoClassDefFoundError: com/vaadin/ui/CustomComponent
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1629)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    at cz.is.common.ui.view.PxTabWithTableAndMenu.createContent(PxTabWithTableAndMenu.java:352)
    at cz.is.common.ui.view.PxTabWithTableAndMenu.attach(PxTabWithTableAndMenu.java:282)
    at com.vaadin.server.AbstractClientConnector.attach(AbstractClientConnector.java:583)
    at com.vaadin.ui.AbstractComponent.attach(AbstractComponent.java:571)
    at com.vaadin.server.AbstractClientConnector.attach(AbstractClientConnector.java:583)
    at com.vaadin.ui.AbstractComponent.attach(AbstractComponent.java:571)
    at com.vaadin.server.AbstractClientConnector.attach(AbstractClientConnector.java:583)
    at com.vaadin.ui.AbstractComponent.attach(AbstractComponent.java:571)
    at com.vaadin.ui.AbstractComponent.setParent(AbstractComponent.java:478)
    at com.vaadin.ui.AbstractSingleComponentContainer.setContent(AbstractSingleComponentContainer.java:137)
    at com.vaadin.ui.UI.setContent(UI.java:1158)
    at cz.is.common.ui.PxUI.init(PxUI.java:89)
    at com.vaadin.ui.UI.doInit(UI.java:610)
    at com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:223)
    at com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:73)
    at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:37)
    at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1371)
    at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:238)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.ClassNotFoundException: com.vaadin.ui.CustomComponent
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 73 more

Hi,

how exactly are you packaging your add-on? Are you using the vaadin eclipse plugin? At least for the add-ons I’ve written, there’s no need to put any vaadin jar files into the add-on package, since those will be included in the main project anyway.

Hello Teppo,
it doesn’t work, when built with ant. I’ve just tried it with your plugin and works properly :-). Thank you.
But I need to get working automatic build. Where can be the problem?
Agata

Hi,

difficult to say without seeing the contents of your ant-built jar file. But you could extract the jar made by the plugin, compare that to what your ant script creates and change your script to correct the differences?

This is what I can’t figure out ;-). The add-on works when run from Eclipse (set as
project
dependency in main Vaadin project) and when built with vaadin export plugin, but doesn’t work when built with ant. Resulting jars have a bit different sizes (some compiled classed have difference in size of about 10-100 bytes).
Here is my ivy.xml file:

<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
    <info organisation="cz.pse" module="filtertableconfigurator" />
    <configurations>
        <conf name="default"/>
        <conf name="compile"/>
    </configurations>
    <publications>
        <artifact type="jar" ext="jar"/>
        <artifact type="descriptor" ext="pom"/>
    </publications>
     <dependencies>
        <dependency org="org.vaadin.addons" name="filteringtable" rev="0.9.1.v7" conf="default->default"/>
        <dependency org="com.vaadin" name="vaadin-server" rev="7.1.7" conf="default->default"/>
        <dependency org="org.apache.commons" name="commons-lang3" rev="3.1" conf="default->default"/>
        <dependency org="log4j" name="log4j" rev="1.2.17" conf="default->default"/>
    </dependencies>
</ivy-module>

and build.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project name="FilterTableConfigurator" default="makejar" basedir="." xmlns:ivy="antlib:org.apache.ivy.ant">

    <property name="major" value="1"/>
    <property name="minor" value="0"/>
    <property name="destJar" value="dist/filtertableconfigurator.jar"/>
    <property name="lib.dir" value="lib"/>
    <property name="class.dir" value="build/classes"/>

    <target name="makejar" description="Create a jar for the FilterTableConfigurator project" depends="clean, compile, resolve">
        <jar destfile="${destJar}" basedir="${class.dir}" />
    </target>

    <target name="compile" description="Compile sources" depends="clean, retrieve">
        <mkdir dir="${class.dir}" />
        <javac target="1.7" debug="true" srcdir="src" destdir="${class.dir}" encoding="Cp1250" >
            <classpath>
                <fileset dir="${lib.dir}" includes="**/*"/>
            </classpath>
        </javac>
    </target>

    <target name="clean" >
        <delete file="${destJar}"/>
        <delete dir="${lib.dir}"/>
        <delete dir="${class.dir}"/>
        <ivy:cleancache/>
    </target>

    <target name="retrieve" depends="clean, resolve" >
        <mkdir dir="${lib.dir}/default"/>
        <mkdir dir="${lib.dir}/compile"/>
        <ivy:retrieve conf="default, compile" pattern="${lib.dir}/[conf]
/[artifact]
.[ext]
"/>
    </target>

    <target name="resolve">
        <ivy:resolve file="ivy.xml" conf="default" type="jar,bundle"/>
    </target>

    <target name="publish" depends="makejar">
        <ivy:deliver deliverpattern="ivy.xml" pubrevision="${major}.${minor}" status="snapshot"  />
        <ivy:makepom ivyfile="ivy.xml" pomfile="dist/filtertableconfigurator.pom" />
          <ivy:resolve/>
        <ivy:publish resolver="nexus-snapshots"
                            update="true"
                            revision="${major}.${minor}-SNAPSHOT"
                            overwrite="true"
                            publishivy="true" >
            <artifacts pattern="dist/[artifact]
.[ext]
"/>
        </ivy:publish>
    </target>
    
</project>

Ps. I haven’t found the way how to publish pom file to nexus (it has nothing to do with vaadin :wink: and I have a suspection, that it can also influence a buld process.

The problem is really with compiler :-(. Adding: <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>

to build.xml and ejc.jar to ant classpath resolves the problem. But I don’t like the solution and don’t understand a clue of the problem :frowning: