2

I am exporting the class file from grails in java.but it doesn't working for me.is this is possible to do or not?? if yes then how??


Its a simple groovy service file. Bookservice.groovy

package com.compnyname.testingJar

class BookService {

    List<Book> getallBooks(String name){
            List<Book> bookList= Book.findAllByName(name);
            return bookList;

        }
}

Book.groovy(Domain class)

package com.compnyname.testingJar

class Book {
    String name;
    String description;
    static constraints = {
    }
}

java file in which i am using this service is as follows

import com.compnyname.testingJar.*;
public List<Groups> listGroup() {
        List<Groups> groups = null;
        try {
            BookService bService = new BookService();
            logger.debug("class of bookservice is" + bService.getClass());
            List<Book> books = bService.getallBooks("xyz");
            logger.debug("List of books is" + books);
            groups = sessionFactoryHibernate.getCurrentSession().createQuery("from Groups").list();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return groups;
    }
4

2 回答 2

2

当您创建 Grails 插件时,您可以将其导出为 jar,然后您可以将其添加到 Spring/Struts 项目的类路径中。

于 2012-07-23T19:13:58.613 回答
0

您需要将服务放在插件项目中,并从您希望使用服务的其他项目中导入插件

于 2012-07-23T07:35:49.207 回答