Tag: groovy

在子类中强制执行toString()实现

我有一个抽象的父类,我希望它强制所有子类实现toString()方法。 但是放: public abstract String toString(); 导致编译错误: Repetitive method name/signature for method ‘java.lang.String toString()’ in class … 我相信这可能是由已经定义了toString的groovy引起的。 谢谢

Grails – 无法从Controller调用服务 – >总是得到“无法调用null对象上的方法错误”

我有一个grails应用程序,我在这里按照教程: http://www.grails.org/Services 我有一些代码 import org.springframework.beans.factory.InitializingBean class SubmitRequestService implements InitializingBean{ def GrailsApplication1 def setting void afterPropertiesSet(){ this.setting = GrailsApplication1.config.setting } def void sendHistoricalContract(HistoricalContract hc_instance){ //… blah blah whatever code } } class SubmitRequestController { def submitRequestService static allowedMethods = [save: “POST”, update: “POST”, delete: “POST”] def index = { // …. blah blah whatever code submitRequestService.sendHistoricalContract(historicalContractInstance) […]

在java中保持换行符和回车符(groovy)

我试图从Linux框中获取命令输出 例如: tnsping 我想保留它的换行符。 下面是我向frows添加命令并将其传递给函数执行的代码 def oracleCommand(csm,pluginOutputs) { HashMap params = IntermediateResults.get(“userparams”) Map env=AppContext.get(AppCtxProperties.environmentVariables) def fClass = new GroovyClassLoader().parseClass( new File( ‘plugins/infa9/Infa9CommandExecUtil.groovy’ ) ) List frows frows=[“tnsping $params.tns”] //for the time being only one command is here List resultRows = fClass.newInstance().fetchCommandOutput( params, env, frows ) csm.oracleCommand(){ oracle_input(frows[0]){} oracle_output(resultRows[0]){} } } 在下面的代码中,我正在读取结果,根据换行分割结果,所以我的所有新行都消失了 public List fetchCommandOutput( Map […]

从外部jar或外部类路径动态加载的Map实体

我需要映射未在hibernate.cfg.xml中列出的实体,这些类是从arbitraty文件夹动态加载的。 我正在尝试注册一个ClassLoaderService以更改加载行为,如果类在编译时定义并存在于类路径中,则以下代码运行正常,但如果我尝试映射一个以dinamically加载的类,则会得到ClassNotFoundException。 关于同一问题有一些问题,但我没有找到任何有效的解决方案。 URL file = ConsultaBase.class.getProtectionDomain().getCodeSource().getLocation().toURI().resolve(“implementacao/”).resolve(“hibernate.cfg.xml”).toURL(); Configuration configuration = new Configuration() .addAnnotatedClass(Registro.class).configure(file); ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder ( new BootstrapServiceRegistryImpl( new ClassLoaderServicePirilampo(Registro.class.getClassLoader()), new LinkedHashSet() ) ) .applySettings(configuration.getProperties()) .addService(ClassLoaderService.class, new ClassLoaderServicePirilampo()) .build(); //this line throws ClassNotFoundException sessionFactory = configuration.buildSessionFactory(serviceRegistry); 我扩展了ClassLoaderServiceImpl以便记录所请求的类,并注意到从JUnit运行,从定义类的项目运行,它工作正常,我从服务获取类加载日志。 但是,如果我添加了以语音方式加载的注释类(来自GroovyClassLoader),则服务永远不会收到对同一类的请求。 最后一行抛出了以下错误: 17:06:49 ERROR [AssertionFailure] HHH000099: an assertion failure occured (this may indicate a bug […]

没有正确读取xml节点

我写了一个脚本,假设比较休假日和xml文件采取的假期,我不知道为什么不考虑假期。 当假设要通过度假系统时,它会在休假日创建工作日志。 我的脚本和我的xml文件代码都可以在下面看到: XML: 脚本: import com.onresolve.scriptrunner.runner.ScriptRunnerImpl; import com.onresolve.scriptrunner.runner.customisers.PluginModule; import com.onresolve.scriptrunner.runner.customisers.WithPlugin; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.IssueManager; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.MutableIssue; import com.atlassian.jira.issue.customfields.manager.OptionsManager import com.onresolve.scriptrunner.runner.ScriptRunnerImpl import com.onresolve.scriptrunner.runner.customisers.PluginModule import com.onresolve.scriptrunner.runner.customisers.WithPlugin import java.lang.Object import com.atlassian.jira.issue.worklog.WorklogImpl2 import java.text.SimpleDateFormat import com.atlassian.crowd.embedded.api.User import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.worklog.DefaultWorklogManager import com.atlassian.jira.security.roles.ProjectRoleManager import com.atlassian.jira.issue.worklog.Worklog import com.atlassian.jira.datetime.LocalDate import org.apache.commons.lang.RandomStringUtils import groovy.xml.MarkupBuilder import groovy.util.* […]

在数据库中存储BLOB的最流行的方法?

在编写实用程序脚本以将图像插入数据库时​​,我想知道是否有一种更加便捷的方式。 最终解决了这个问题: def sql = Sql.newInstance(…) // … Connection conn = sql.getConnection() PreparedStatement stmt.prepareStatment(…) stmt.setBinary(…) stmt.executeUpate() 必须有一种更加时髦的方式,能有人开导我吗?

如何用java或groovy计算目录上的md5校验和?

我希望使用java或groovy来获取完整目录的md5校验和。 我必须将源目录,校验和源和目标以及删除源目录后的目录复制。 我发现这个文件的脚本,但如何与目录做同样的事情? import java.security.MessageDigest def generateMD5(final file) { MessageDigest digest = MessageDigest.getInstance(“MD5”) file.withInputStream(){ is -> byte[] buffer = new byte[8192] int read = 0 while( (read = is.read(buffer)) > 0) { digest.update(buffer, 0, read); } } byte[] md5sum = digest.digest() BigInteger bigInt = new BigInteger(1, md5sum) return bigInt.toString(16).padLeft(32, ‘0’) } 有更好的方法吗?

限制嵌入式Groovy中的某些API

我只是在我的应用程序中嵌入了Groovy,并想知道是否可以限制对某些API的访问,即java.io.File,java.net.URL等 或者不是完全限制java.io.File访问,我想只允许访问机器上的某些目录。 非常感谢任何指导!

有没有办法编译隐藏源代码?

使用Play或Grails或任何其他JVM框架; 有没有办法(或者是什么方式)完全编译生成的war / jar文件,以便隐藏源代码,而不可能反编译? 或者甚至在编译之后,是否可以轻松地反编译并获取字符串和类? 例如db connection等。 谢谢。

具有临时Web报告的Java商业智能框架?

我需要一个报告框架,它支持带有临时报告的Web视图,以及带样式的固定PDF报告。 我的用户将是非高级用户,因此我需要提供可用于临时报告的内容。 什么是Java世界中最好的当前解决方案?