Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Deployment as jar

  1. #1
    Join Date
    Dec 2008
    Posts
    13

    Default Deployment as jar

    Hello,

    I have the following problem:

    I realize an application with swt and spring. I use annotation config like:

    Code:
    	
    <context:annotation-config />
    <context:component-scan base-package="de.xxx..." />
    When I start the application in my development enviroment all looks fine but when I export it to an executable jar file the starting process failed.

    During starting the jar file the the log message:

    Code:
    2009-07-20 09:37:42,759 DEBUG [org.springframework.core.io.support.PathMatchingResourcePatternResolver] Resolved location pattern [classpath*:de/xxx/**/*.class] to resources []
    2009-07-20 09:37:42,760 DEBUG [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] Loaded 4 bean definitions from location pattern [client-services.xml]
    I think he found the xml file inside the jar because it founds the base-package and try to find the classes for autowiring. But he didn't find any classes inside the jars to complete the autoconfiguration. In my development enviroment it find the classes.

    Can somebody help me to solve the problem? What is a best pratice to deploy a desktop application in jar with spring?

    Regards
    Christoph

  2. #2
    Join Date
    May 2007
    Location
    Saint Petersburg, Russian Federation
    Posts
    1,189

    Default

    Spring relies to the standard ClassLoader.getResources() method. I assume that it just doesn't return expected values during 'java -jar' usage. Try to use 'java -cp myapp.jar MyStartClass' instead.

  3. #3
    Join Date
    Dec 2008
    Posts
    13

    Default

    Thx for this advice but the result is the same. The ApplicationContext want's to find the classes and make the beans but it don't find it.

    Does someone more advices to help me?

    Christoph

  4. #4
    Join Date
    May 2007
    Location
    Saint Petersburg, Russian Federation
    Posts
    1,189

    Default

    Quote Originally Posted by pushdown View Post
    Thx for this advice but the result is the same. The ApplicationContext want's to find the classes and make the beans but it don't find it.

    Does someone more advices to help me?

    Christoph
    If you create complete standalone test-case that illustrates the problem and post it here I take a look.

  5. #5
    Join Date
    Dec 2008
    Posts
    13

    Default

    Hello,

    I have made a simple testapplication for this problem.

    You can download the jar for executing:
    http://thodte.de/upload/TestDeployProject.zip

    or the eclipse project from here:
    http://thodte.de/upload/TestDeploy.zip

    The project contains a simple main, which is a component and another bean. After starting the main 2 beans should be available. Additionally the app writes a log to the disk.

    Christoph

  6. #6
    Join Date
    May 2007
    Location
    Saint Petersburg, Russian Federation
    Posts
    1,189

    Default

    Christoph,

    I modified your ajnt script a little:

    build.xml
    HTML Code:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <project default="create_run_jar" name="Create Runnable Jar for Project PC-WARE Client with Jar-in-Jar Loader">
    
        <path id="cp">
            <fileset dir="lib"/>
        </path>
        
    
        <target name="create_run_jar">
            <delete dir="bin/de"/>
            <javac srcdir="src" destdir="bin" classpathref="cp" />
            <jar destfile="lib/test.jar">
                <manifest>
                    <attribute name="Main-Class" value="de.testdeploy.TestExecutor"/>
                    <attribute name="Class-Path" value="log4j-1.2.15.jar swt.jar org.eclipse.jface_3.4.2.M20090107-0800.jar org.eclipse.jface.databinding_1.2.1.M20080827-0800a.jar org.eclipse.jface.text_3.4.2.r342_v20081119-0800.jar commons-logging.jar commons-io.jar httpcore-4.0.jar httpcore-nio-4.0.jar commons-codec-1.3.jar commons-httpclient-3.1.jar org.springframework.beans-3.0.0.M3.jar org.springframework.context-3.0.0.M3.jar org.springframework.context.support-3.0.0.M3.jar org.springframework.core-3.0.0.M3.jar org.springframework.asm-3.0.0.M3.jar org.springframework.expression-3.0.0.M3.jar antlr-runtime-3.0.1.jar org.springframework.web-3.0.0.M3.jar org.eclipse.swt.win32.win32.x86_3.5.0.v3550b.jar org.eclipse.jface_3.5.0.I20090525-2000.jar org.eclipse.core.commands_3.5.0.I20090525-2000.jar org.eclipse.equinox.common_3.5.0.v20090520-1800.jar"/>
                </manifest>
                <fileset dir="bin"/>
            </jar>
        </target>
    </project>
    When I start created jar via 'java -jar test.jar' I get expected input:
    Code:
    ...
    19:53:05,140 DEBUG [DefaultListableBeanFactory] Returning cached instance of singleton bean 'loggerService'
    19:53:05,156 DEBUG [AutowiredAnnotationBeanPostProcessor] Autowiring by type from bean name 'testExecutor' to bean named 'loggerService'
    19:53:05,156 DEBUG [DefaultListableBeanFactory] Finished creating instance of bean 'testExecutor'
    19:53:05,156 DEBUG [DefaultListableBeanFactory] Returning cached instance of singleton bean 'testExecutor'
    Successful started
    In the loggerService

  7. #7
    Join Date
    Dec 2008
    Posts
    13

    Default

    Hello,

    thx for this solution but what was the failure?

    My jar contains the lib you jar not. Is that the only thing thats different?

    When spring is in another jar then it doesn't find the beans? That's right?

    Christoph

  8. #8
    Join Date
    May 2007
    Location
    Saint Petersburg, Russian Federation
    Posts
    1,189

    Default

    I tried your example and it works fine when spring jar is located outside of the application jar. I.e. spring was able to locate the beans located at the application jar.

    I'm afraid I don't understand your last question

  9. #9
    Join Date
    Dec 2008
    Posts
    13

    Default

    I mean that the spring.jar must outside the app jar.

    Is it a bug when the spring jar is in the app jar that it don't find the beans?

  10. #10
    Join Date
    May 2007
    Location
    Saint Petersburg, Russian Federation
    Posts
    1,189

    Default

    Adding Classes to the JAR File's Classpath:
    Note : The Class-Path header points to classes or JAR files on the local network, not JAR files within the JAR file or classes accessible over internet protocols. To load classes in JAR files within a JAR file into the class path, you must write custom code to load those classes. For example, if MyJar.jar contains another JAR file called MyUtils.jar, you cannot use the Class-Path header in MyJar.jar's manifest to load classes in MyUtils.jar into the class path.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •