ProjectClassPathModifier and ProjectClassPathExtender - netbeans

I am trying to contribute a fix to a Netbeans 8 plugin which is currently broken. The plugin includes an "add support" menu item which is supposed to, amongst other things, add an entry to the project class path if the project is an ANT project. Currently it does this by manually rewriting the project properties file. This fails in certain cases, e.g. if the project has a dedicated library folder.
I have managed to code a fix which uses the ProjectClassExtender API class to add the library to the class, but this is a deprecated API. I've tried a couple of approaches to working via the replacement ProjectClassPathModifier, but I cannot get the right combination of parameters - I always get an Unsupported Operation exception or similar. Can someone please help here?
The code below condenses the three approaches I've tried:
FileObject projectRoot = project.getProjectDirectory();
Sources sources = ProjectUtils.getSources(project);
SourceGroup sourceGroup = sources.getSourceGroups(Sources.TYPE_GENERIC)[0];
FileObject sgRoot = sourceGroup.getRootFolder();
Library lib = libraryManager.getLibrary(LIB_NAME);
ProjectClassPathModifier pcpm = projectLookup.lookup(ProjectClassPathModifier.class);
ProjectClassPathExtender pcpe = pcpm.extenderForModifier(project);
pcpe.addLibrary(lib); // Works but deprecated
pcpm.addLibraries(new Library[]{lib}, projectRoot, ClassPath.COMPILE); // Fails regardless
pcpm.addLibraries(new Library[]{lib}, sgRoot, ClassPath.COMPILE); // Fails regardless
The call using projectRoot gives this error:
Java.lang.UnsupportedOperationException: Project in C:\Users\sparry\ownCloud\development\NetbeansProjects\JavaApplication16 of class org.netbeans.modules.java.j2seproject.J2SEProject has a ProjectClassPathModifierImplementation but it will not handle classpath/compile for C:\Users\sparry\ownCloud\development\NetbeansProjects\JavaApplication16 extensible source groups: C:\Users\sparry\ownCloud\development\NetbeansProjects\JavaApplication16\src
at org.netbeans.api.java.project.classpath.ProjectClassPathModifier.findExtensible(ProjectClassPathModifier.java:388)
at org.netbeans.api.java.project.classpath.ProjectClassPathModifier.addLibraries(ProjectClassPathModifier.java:93)
at org.nemesis.antlr.v4.netbeans.v8.project.AntBasedProject.addPropertiesToProject(AntBasedProject.java:615)
at org.nemesis.antlr.v4.netbeans.v8.project.AntBasedProject.addANTLRSupport(AntBasedProject.java:122)
at org.nemesis.antlr.v4.netbeans.v8.project.action.AddANTLRSupport.actionPerformed(AddANTLRSupport.java:134)
[catch] at org.openide.awt.InjectorExactlyOne.actionPerformed(InjectorExactlyOne.java:78)
at org.openide.awt.ContextAction$Performer.actionPerformed(ContextAction.java:226)
at org.openide.awt.ContextManager.actionPerformed(ContextManager.java:260)
at org.openide.awt.ContextAction.actionPerformed(ContextAction.java:109)
at org.openide.util.actions.ActionInvoker$1.run(ActionInvoker.java:93)
at org.openide.util.actions.ActionInvoker.doPerformAction(ActionInvoker.java:116)
at org.openide.util.actions.ActionInvoker.invokeAction(ActionInvoker.java:99)
at org.openide.awt.GeneralAction$BaseDelAction.actionPerformed(GeneralAction.java:234)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:842)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:886)
at java.awt.Component.processMouseEvent(Component.java:6539)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6304)
at java.awt.Container.processEvent(Container.java:2239)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2297)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476)
at java.awt.Container.dispatchEventImpl(Container.java:2283)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
at java.awt.EventQueue$4.run(EventQueue.java:733)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:159)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
The call using sgRoot gives this very similar error:
java.lang.UnsupportedOperationException: Project in C:\Users\sparry\ownCloud\development\NetbeansProjects\JavaApplication17 of class org.netbeans.modules.java.j2seproject.J2SEProject has a ProjectClassPathModifierImplementation but it will not handle classpath/compile for C:\Users\sparry\ownCloud\development\NetbeansProjects\JavaApplication17 extensible source groups: C:\Users\sparry\ownCloud\development\NetbeansProjects\JavaApplication17\src
at org.netbeans.api.java.project.classpath.ProjectClassPathModifier.findExtensible(ProjectClassPathModifier.java:388)
at org.netbeans.api.java.project.classpath.ProjectClassPathModifier.addLibraries(ProjectClassPathModifier.java:93)
at org.nemesis.antlr.v4.netbeans.v8.project.AntBasedProject.addPropertiesToProject(AntBasedProject.java:616)
at org.nemesis.antlr.v4.netbeans.v8.project.AntBasedProject.addANTLRSupport(AntBasedProject.java:122)
at org.nemesis.antlr.v4.netbeans.v8.project.action.AddANTLRSupport.actionPerformed(AddANTLRSupport.java:134)
[catch] at org.openide.awt.InjectorExactlyOne.actionPerformed(InjectorExactlyOne.java:78)
at org.openide.awt.ContextAction$Performer.actionPerformed(ContextAction.java:226)
at org.openide.awt.ContextManager.actionPerformed(ContextManager.java:260)
at org.openide.awt.ContextAction.actionPerformed(ContextAction.java:109)
at org.openide.util.actions.ActionInvoker$1.run(ActionInvoker.java:93)
at org.openide.util.actions.ActionInvoker.doPerformAction(ActionInvoker.java:116)
at org.openide.util.actions.ActionInvoker.invokeAction(ActionInvoker.java:99)
at org.openide.awt.GeneralAction$BaseDelAction.actionPerformed(GeneralAction.java:234)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:842)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:886)
at java.awt.Component.processMouseEvent(Component.java:6539)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6304)
at java.awt.Container.processEvent(Container.java:2239)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2297)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476)
at java.awt.Container.dispatchEventImpl(Container.java:2283)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
at java.awt.EventQueue$4.run(EventQueue.java:733)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:159)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

I think I have worked out the problem and a solution myself:
Sources sources = ProjectUtils.getSources(project);
SourceGroup sourceGroup = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)[0];
FileObject sgRoot = sourceGroup.getRootFolder();
Library lib = libraryManager.getLibrary(LIB_NAME);
ProjectClassPathModifier pcpm = projectLookup.lookup(ProjectClassPathModifier.class);
pcpm.addLibraries(new Library[]{lib}, sgRoot, ClassPath.COMPILE); // works!
The key is using the JavaProjectConstants.SOURCES_TYPE_JAVA source type, not Sources.TYPE_GENERIC. Generic returns the project main folder and the addLibraries call needs a java source folder. In most projects, that's the src folder.

Related

Strange exception using Jersey with embedded Jetty

I have created an embedded Jetty application which utilizes Jersey in order to implement several RESTful services. I am using some standard code as described here in Stack Overflow as well as other websites:
public static void main(String[] args)
{
Server server = new Server(8080);
ServletContextHandler ctx = new ServletContextHandler(
ServletContextHandler.SESSIONS);
ctx.setContextPath("/");
ServletHolder holder = ctx.addServlet(
"org.glassfish.jersey.servlet.ServletContainer.class", "/*");
holder.setInitOrder(0);
holder.setInitParameter("jersey.config.server.provider.classnames",
RestfulClass.class.getCanonicalName());
server.setHandler(ctx);
try
{
server.start();
server.join();
}
catch(Exception exe)
{
exe.printStackTrace();
}
}
I've used all the recommended jar files, and several other jar files that the various blogs and sites failed to mention. When running the Jetty application, I get the following exception:
java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer.class
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.eclipse.jetty.util.Loader.loadClass(Loader.java:86)
at org.eclipse.jetty.servlet.BaseHolder.doStart(BaseHolder.java:95)
<several lines omitted for brevty>
Caused by: javax.servlet.UnavailableException: org.glassfish.jersey.servlet.ServletContainer.class
at org.eclipse.jetty.servlet.BaseHolder.doStart(BaseHolder.java:102)
at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:361)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:874)
... 11 more
It is the "UnavailableException" that I do not understand. The ServletContainer class is actually in one of the Jar files (in jersey-container-servlet-core.jar, to be precise), but for some reason it is identified as "unavailable". This is causing a class that is actually in a referenced Jar file to be "not found"!
Can anyone tell me what is causing this UnavailableException and (more importantly) how I can prevent it from being thrown?
Someone please advise...
ServletHolder holder = ctx.addServlet(
"org.glassfish.jersey.servlet.ServletContainer.class", "/*");
You are using a String for the class name. When doing this, you don't use the .class suffix. That at only when you want to get the actual Class object. You have two options
Remove the .class from the String
ServletHolder holder = ctx.addServlet(
"org.glassfish.jersey.servlet.ServletContainer", "/*");
Remove the "" (double quotes) and just use the Class object1.
ServletHolder holder = ctx.addServlet(
org.glassfish.jersey.servlet.ServletContainer.class, "/*");
1 - See addServlet(Class, String)

Scala Compiler Error: assertion failed: scala.<none>

Has anyone seen this before? The error below happens when I build my Scala/Play project in Intellij. As you can see none of my code is part of the call-stack.
Error:scalac: Error: assertion failed: scala.<none>
java.lang.AssertionError: assertion failed: scala.<none>
at scala.reflect.internal.Trees$AppliedTypeTree.<init>(Trees.scala:579)
at scala.reflect.internal.TreeGen.mkTupleType(TreeGen.scala:293)
at scala.tools.nsc.ast.parser.TreeBuilder.makeTupleType(TreeBuilder.scala:44)
at scala.tools.nsc.ast.parser.Parsers$Parser$PatternContextSensitive$class.scala$tools$nsc$ast$parser$Parsers$Parser$PatternContextSensitive$$tupleInfixType(Parsers.scala:877)
at scala.tools.nsc.ast.parser.Parsers$Parser$PatternContextSensitive$$anonfun$typ$1.apply(Parsers.scala:910)
at scala.tools.nsc.ast.parser.Parsers$Parser$PatternContextSensitive$$anonfun$typ$1.apply(Parsers.scala:907)
at scala.tools.nsc.ast.parser.Parsers$Parser.placeholderTypeBoundary(Parsers.scala:487)
at scala.tools.nsc.ast.parser.Parsers$Parser$PatternContextSensitive$class.typ(Parsers.scala:907)
at scala.tools.nsc.ast.parser.Parsers$Parser$outPattern$.typ(Parsers.scala:1995)
at scala.tools.nsc.ast.parser.Parsers$Parser$outPattern$.argType(Parsers.scala:1996)
at scala.tools.nsc.ast.parser.Parsers$Parser$PatternContextSensitive$$anonfun$types$1.apply(Parsers.scala:1042)
at scala.tools.nsc.ast.parser.Parsers$Parser$PatternContextSensitive$$anonfun$types$1.apply(Parsers.scala:1042)
at scala.tools.nsc.ast.parser.Parsers$Parser.tokenSeparated(Parsers.scala:761)
at scala.tools.nsc.ast.parser.Parsers$Parser$PatternContextSensitive$class.types(Parsers.scala:1042)
at scala.tools.nsc.ast.parser.Parsers$Parser$outPattern$.types(Parsers.scala:1995)
at scala.tools.nsc.ast.parser.Parsers$Parser$PatternContextSensitive$class.typeArgs(Parsers.scala:924)
at scala.tools.nsc.ast.parser.Parsers$Parser$outPattern$.typeArgs(Parsers.scala:1995)
at scala.tools.nsc.ast.parser.Parsers$Parser$PatternContextSensitive$class.simpleTypeRest(Parsers.scala:963)
at scala.tools.nsc.ast.parser.Parsers$Parser$outPattern$.simpleTypeRest(Parsers.scala:1995)
at scala.tools.nsc.ast.parser.Parsers$Parser$PatternContextSensitive$class.simpleType(Parsers.scala:943)
at scala.tools.nsc.ast.parser.Parsers$Parser$outPattern$.simpleType(Parsers.scala:1995)
at scala.tools.nsc.ast.parser.Parsers$Parser$PatternContextSensitive$$anonfun$annotType$1.apply(Parsers.scala:930)
at scala.tools.nsc.ast.parser.Parsers$Parser$PatternContextSensitive$$anonfun$annotType$1.apply(Parsers.scala:930)
at scala.tools.nsc.ast.parser.Parsers$Parser.placeholderTypeBoundary(Parsers.scala:487)
at scala.tools.nsc.ast.parser.Parsers$Parser$PatternContextSensitive$class.annotType(Parsers.scala:930)
at scala.tools.nsc.ast.parser.Parsers$Parser$outPattern$.annotType(Parsers.scala:1995)
at scala.tools.nsc.ast.parser.Parsers$Parser.startAnnotType(Parsers.scala:2017)
at scala.tools.nsc.ast.parser.Parsers$Parser.readAppliedParent$1(Parsers.scala:2822)
at scala.tools.nsc.ast.parser.Parsers$Parser.templateParents(Parsers.scala:2828)
at scala.tools.nsc.ast.parser.Parsers$Parser.template(Parsers.scala:2855)
at scala.tools.nsc.ast.parser.Parsers$Parser.templateOpt(Parsers.scala:2886)
at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$classDef$1.apply(Parsers.scala:2753)
at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$classDef$1.apply(Parsers.scala:2733)
at scala.tools.nsc.ast.parser.Parsers$Parser.savingClassContextBounds(Parsers.scala:329)
at scala.tools.nsc.ast.parser.Parsers$Parser.classDef(Parsers.scala:2733)
at scala.tools.nsc.ast.parser.Parsers$Parser.tmplDef(Parsers.scala:2710)
at scala.tools.nsc.ast.parser.Parsers$Parser.defOrDcl(Parsers.scala:2467)
at scala.tools.nsc.ast.parser.Parsers$Parser.nonLocalDefOrDcl(Parsers.scala:2475)
at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$templateStat$1$$anonfun$applyOrElse$3.apply(Parsers.scala:3032)
at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$templateStat$1$$anonfun$applyOrElse$3.apply(Parsers.scala:3032)
at scala.tools.nsc.ast.parser.Parsers$Parser.joinComment(Parsers.scala:702)
at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$templateStat$1.applyOrElse(Parsers.scala:3032)
at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$templateStat$1.applyOrElse(Parsers.scala:3027)
at scala.tools.nsc.ast.parser.Parsers$Parser.statSeq(Parsers.scala:2959)
at scala.tools.nsc.ast.parser.Parsers$Parser.templateStats(Parsers.scala:3026)
at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$templateStatSeq$1.apply(Parsers.scala:3013)
at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$templateStatSeq$1.apply(Parsers.scala:2990)
at scala.tools.nsc.ast.parser.Parsers$Parser.checkNoEscapingPlaceholders(Parsers.scala:464)
at scala.tools.nsc.ast.parser.Parsers$Parser.templateStatSeq(Parsers.scala:2990)
at scala.tools.nsc.ast.parser.Parsers$Parser.templateBody(Parsers.scala:2919)
at scala.tools.nsc.ast.parser.Parsers$Parser.templateBodyOpt(Parsers.scala:2926)
at scala.tools.nsc.ast.parser.Parsers$Parser.template(Parsers.scala:2856)
at scala.tools.nsc.ast.parser.Parsers$Parser.templateOpt(Parsers.scala:2886)
at scala.tools.nsc.ast.parser.Parsers$Parser.objectDef(Parsers.scala:2775)
at scala.tools.nsc.ast.parser.Parsers$Parser.tmplDef(Parsers.scala:2714)
at scala.tools.nsc.ast.parser.Parsers$Parser.topLevelTmplDef(Parsers.scala:2695)
at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$topStat$1$$anonfun$applyOrElse$2.apply(Parsers.scala:2982)
at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$topStat$1$$anonfun$applyOrElse$2.apply(Parsers.scala:2982)
at scala.tools.nsc.ast.parser.Parsers$Parser.joinComment(Parsers.scala:702)
at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$topStat$1.applyOrElse(Parsers.scala:2982)
at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$topStat$1.applyOrElse(Parsers.scala:2975)
at scala.tools.nsc.ast.parser.Parsers$Parser.statSeq(Parsers.scala:2959)
at scala.tools.nsc.ast.parser.Parsers$Parser.topStatSeq(Parsers.scala:2974)
at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$compilationUnit$1.topstats$1(Parsers.scala:3172)
at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$compilationUnit$1.apply(Parsers.scala:3178)
at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$compilationUnit$1.apply(Parsers.scala:3140)
at scala.tools.nsc.ast.parser.Parsers$Parser.checkNoEscapingPlaceholders(Parsers.scala:464)
at scala.tools.nsc.ast.parser.Parsers$Parser.compilationUnit(Parsers.scala:3140)
at scala.tools.nsc.ast.parser.Parsers$SourceFileParser$$anonfun$parseStartRule$1.apply(Parsers.scala:146)
at scala.tools.nsc.ast.parser.Parsers$SourceFileParser$$anonfun$parseStartRule$1.apply(Parsers.scala:146)
at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$parse$1.apply(Parsers.scala:354)
at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$parse$1.apply(Parsers.scala:354)
at scala.tools.nsc.ast.parser.Parsers$Parser.parseRule(Parsers.scala:347)
at scala.tools.nsc.ast.parser.Parsers$Parser.parse(Parsers.scala:354)
at scala.tools.nsc.ast.parser.Parsers$UnitParser.smartParse(Parsers.scala:243)
at scala.tools.nsc.ast.parser.SyntaxAnalyzer.scala$tools$nsc$ast$parser$SyntaxAnalyzer$$initialUnitBody(SyntaxAnalyzer.scala:87)
at scala.tools.nsc.ast.parser.SyntaxAnalyzer$ParserPhase.apply(SyntaxAnalyzer.scala:99)
at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:430)
at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:397)
at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:397)
at scala.collection.Iterator$class.foreach(Iterator.scala:743)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1174)
at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:397)
at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1625)
at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1610)
at scala.tools.nsc.Global$Run.compileSources(Global.scala:1605)
at scala.tools.nsc.Global$Run.compile(Global.scala:1703)
at xsbt.CachedCompiler0.run(CompilerInterface.scala:126)
at xsbt.CachedCompiler0.run(CompilerInterface.scala:102)
at xsbt.CompilerInterface.run(CompilerInterface.scala:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:102)
at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:48)
at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:41)
at org.jetbrains.jps.incremental.scala.local.IdeaIncrementalCompiler.compile(IdeaIncrementalCompiler.scala:28)
at org.jetbrains.jps.incremental.scala.local.LocalServer.compile(LocalServer.scala:25)
at org.jetbrains.jps.incremental.scala.remote.Main$.make(Main.scala:64)
at org.jetbrains.jps.incremental.scala.remote.Main$.nailMain(Main.scala:22)
at org.jetbrains.jps.incremental.scala.remote.Main.nailMain(Main.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.martiansoftware.nailgun.NGSession.run(NGSession.java:319)
The build was working fine previously so I wonder if it's an environmental issue.
Based on this PasteBin I know I'm not the first person to see this issue: http://pastebin.com/VtFy12UJ
Have you tried compiling outside of Intellij to see if that fixed the issue?
It's probably because you have a tuple with more than 22 items. Relevant Scala ticket: https://issues.scala-lang.org/browse/SI-9572
Double check your code.

Infinispan with MongoDB error: Unable to start cache loaders

I'm writing a web service layer using Resteasy and I tried to configure infinispan as a server side response cache, as described here: http://docs.jboss.org/resteasy/docs/3.0.1.Final/userguide/html_single/index.html#server_cache
Because this layer is stateless and might be deployed on a multitude of nodes on heroku, I wanted to use a mongodb cache loader to store the cache data. This way, the cache would be synched between all nodes.
However, when starting my server in my local machine, I get the following error:
org.infinispan.CacheException: Unable to start cache loaders (full stack trace at the end of this message)
Here's my declared dependencies:
compile 'org.jboss.resteasy:resteasy-jaxrs:3.0.1.Final'
compile 'org.jboss.resteasy:resteasy-client:3.0.1.Final'
compile 'org.jboss.resteasy:resteasy-spring:3.0.1.Final'
compile 'org.jboss.resteasy:resteasy-cache-core:3.0.1.Final'
compile 'org.infinispan:infinispan-cachestore-mongodb:5.3.0.Final'
(It's strange that the org.infinispan:infinispan-cachestore-mongodb:5.3.0.Final jar includes almost all the classes also present in org.jboss.resteasy:resteasy-cache-core:3.0.1.Final. I wonder if that's what is causing the problem. I played a lot with the dependency graph trying to exclude the duplicates to a point where I built my own mongo cache loader jar with only the pertinent classes, but doing that or removing the core jar and leaving only the mongo cache loader jar thrown an exception like Unexpected element '{urn:infinispan:config:5.3}infinispan'
)
I also configured infinispan.xml following the documentation on the site: https://docs.jboss.org/author/display/ISPN/Cache+Loaders+and+Stores#CacheLoadersandStores-MongoDBcacheloader
<?xml version="1.0" encoding="UTF-8"?>
<infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:infinispan:config:5.3
http://www.infinispan.org/schemas/infinispan-config-5.3.xsd
urn:infinispan:config:mongodb:5.3
https://raw.github.com/infinispan/infinispan/5.3.x/cachestore/mongodb/src/main/resources/schema/mongodb-cachestore-config-5.3.xsd"
xmlns="urn:infinispan:config:5.3">
<namedCache name="nf-demo">
<eviction strategy="LIRS" maxEntries="10" />
<loaders>
<mongodbStore xmlns="urn:infinispan:config:mongodb:5.3">
<connection host="localhost" port="27017" timeout="2000"
acknowledgment="0" />
<storage database="infinispan_test_database" collection="infispan_cachestore" />
</mongodbStore>
</loaders>
</namedCache>
</infinispan>
I'm not sure if it's a version conflict which is causing the issue or if it is a bug on the mongodb cache laoder. I'm also not sure if there's an additional step I need to perform to register the mongo db loader within infospan config. On another thread, someone had the same error when creating a custom loader because he didn't implement the CacheLoaderConfig.getCacheLoaderClassName(). I fussed around the mongo db loader source code in github but couldn't find any reference to this method. Here's the thread for reference: https://community.jboss.org/thread/218305
Any help would be appreciated. Let me know if you need more info.
Full Stacktrace:
Failed startup of context org.gradle.api.plugins.jetty.internal.JettyPluginWebAppContext#6823bf90{/avivoca,/Users/daniel.freitas/dev/projects/mtl-lp-notification-layer/src/main/webapp}
org.infinispan.CacheException: Unable to invoke method public void org.infinispan.loaders.CacheLoaderManagerImpl.start() on object of type CacheLoaderManagerImpl
at org.infinispan.util.ReflectionUtil.invokeAccessibly(ReflectionUtil.java:207)
at org.infinispan.factories.AbstractComponentRegistry$PrioritizedMethod.invoke(AbstractComponentRegistry.java:889)
at org.infinispan.factories.AbstractComponentRegistry.invokeStartMethods(AbstractComponentRegistry.java:658)
at org.infinispan.factories.AbstractComponentRegistry.internalStart(AbstractComponentRegistry.java:647)
at org.infinispan.factories.AbstractComponentRegistry.start(AbstractComponentRegistry.java:550)
at org.infinispan.factories.ComponentRegistry.start(ComponentRegistry.java:221)
at org.infinispan.CacheImpl.start(CacheImpl.java:691)
at org.infinispan.manager.DefaultCacheManager.wireAndStartCache(DefaultCacheManager.java:685)
at org.infinispan.manager.DefaultCacheManager.createCache(DefaultCacheManager.java:648)
at org.infinispan.manager.DefaultCacheManager.getCache(DefaultCacheManager.java:544)
at org.jboss.resteasy.plugins.cache.server.ServerCacheFeature.getXmlCache(ServerCacheFeature.java:88)
at org.jboss.resteasy.plugins.cache.server.ServerCacheFeature.getCache(ServerCacheFeature.java:61)
at org.jboss.resteasy.plugins.cache.server.ServerCacheFeature.configure(ServerCacheFeature.java:36)
at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:1673)
at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:1310)
at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:1232)
at org.jboss.resteasy.spi.ResteasyDeployment.registerProvider(ResteasyDeployment.java:531)
at org.jboss.resteasy.spi.ResteasyDeployment.registration(ResteasyDeployment.java:346)
at org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:241)
at org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap.contextInitialized(ResteasyBootstrap.java:28)
at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:548)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1272)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:489)
at org.gradle.api.plugins.jetty.internal.JettyPluginWebAppContext.doStart(JettyPluginWebAppContext.java:112)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:224)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.gradle.api.plugins.jetty.internal.Jetty6PluginServer.start(Jetty6PluginServer.java:111)
at org.gradle.api.plugins.jetty.AbstractJettyRunTask.startJettyInternal(AbstractJettyRunTask.java:247)
at org.gradle.api.plugins.jetty.AbstractJettyRunTask.startJetty(AbstractJettyRunTask.java:198)
at org.gradle.api.plugins.jetty.AbstractJettyRunTask.start(AbstractJettyRunTask.java:169)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1047)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:877)
at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:216)
at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:122)
at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147)
at org.gradle.api.plugins.jetty.JettyRun_Decorated.invokeMethod(Unknown Source)
at groovy.lang.GroovyObject$invokeMethod.call(Unknown Source)
at org.gradle.util.ReflectionUtil.invoke(ReflectionUtil.groovy:23)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:217)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:210)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:199)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:526)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:509)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
at org.gradle.api.internal.changedetection.state.CacheLockReleasingTaskExecuter$1.run(CacheLockReleasingTaskExecuter.java:35)
at org.gradle.internal.Factories$1.create(Factories.java:22)
at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:179)
at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:232)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:142)
at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:83)
at org.gradle.api.internal.changedetection.state.CacheLockReleasingTaskExecuter.execute(CacheLockReleasingTaskExecuter.java:33)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.ContextualisingTaskExecuter.execute(ContextualisingTaskExecuter.java:34)
at org.gradle.api.internal.changedetection.state.CacheLockAcquiringTaskExecuter$1.run(CacheLockAcquiringTaskExecuter.java:39)
at org.gradle.internal.Factories$1.create(Factories.java:22)
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:124)
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:112)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:134)
at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.useCache(DefaultTaskArtifactStateCacheAccess.java:79)
at org.gradle.api.internal.changedetection.state.CacheLockAcquiringTaskExecuter.execute(CacheLockAcquiringTaskExecuter.java:37)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:57)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:41)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:52)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:42)
at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:282)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.executeTask(DefaultTaskPlanExecutor.java:48)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.processTask(DefaultTaskPlanExecutor.java:34)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:27)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:89)
at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
at org.gradle.api.internal.changedetection.state.TaskCacheLockHandlingBuildExecuter$1.run(TaskCacheLockHandlingBuildExecuter.java:31)
at org.gradle.internal.Factories$1.create(Factories.java:22)
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:124)
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:112)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:134)
at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.useCache(DefaultTaskArtifactStateCacheAccess.java:79)
at org.gradle.api.internal.changedetection.state.TaskCacheLockHandlingBuildExecuter.execute(TaskCacheLockHandlingBuildExecuter.java:29)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
at org.gradle.api.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
at org.gradle.launcher.Main.doAction(Main.java:48)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at org.gradle.launcher.Main.main(Main.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
at org.gradle.launcher.GradleMain.main(GradleMain.java:26)
Caused by: org.infinispan.CacheException: Unable to start cache loaders
at org.infinispan.loaders.CacheLoaderManagerImpl.start(CacheLoaderManagerImpl.java:163)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.infinispan.util.ReflectionUtil.invokeAccessibly(ReflectionUtil.java:205)
... 130 more
Caused by: java.lang.IllegalArgumentException: Cannot load null class!
at org.infinispan.util.Util.getInstance(Util.java:224)
at org.infinispan.loaders.CacheLoaderManagerImpl.createCacheLoader(CacheLoaderManagerImpl.java:346)
at org.infinispan.loaders.CacheLoaderManagerImpl.createCacheLoader(CacheLoaderManagerImpl.java:336)
at org.infinispan.loaders.CacheLoaderManagerImpl.start(CacheLoaderManagerImpl.java:149)
... 135 more
UPDATE
I step traced the source code for Infinispan and I narrowed down the error to this method on class org.infinispan.loaders.CacheLoaderManagerImpl. The cfg instance is of type org.infinispan.loaders.mongodb.MongoDBCacheStoreConfig, which interestingly I can't find on any library in Eclipse's classpath. So I assume this class is created at runtime? The NPE error is reported because cfg.getCacheLoaderClassName() returns null on the very 1st line.
CacheLoader createCacheLoader(CacheLoaderConfig cfg, AdvancedCache<Object, Object> cache) throws Exception {
CacheLoader tmpLoader = (CacheLoader) Util.getInstance(cfg.getCacheLoaderClassName(), cache.getClassLoader());
if (tmpLoader != null) {
if (cfg instanceof CacheStoreConfig) {
CacheStore tmpStore = (CacheStore) tmpLoader;
// async?
CacheStoreConfig cfg2 = (CacheStoreConfig) cfg;
if (cfg2.getAsyncStoreConfig().isEnabled()) {
tmpStore = createAsyncStore(tmpStore, cfg2);
tmpLoader = tmpStore;
}
// read only?
if (cfg2.isIgnoreModifications()) {
tmpStore = new ReadOnlyStore(tmpStore);
tmpLoader = tmpStore;
}
// singleton?
SingletonStoreConfig ssc = cfg2.getSingletonStoreConfig();
if (ssc != null && ssc.isSingletonStoreEnabled()) {
tmpStore = new SingletonStore(tmpStore, cache, ssc);
tmpLoader = tmpStore;
}
}
// load props
tmpLoader.init(cfg, cache, m);
}
return tmpLoader;
}

How can i pass a URL explicitly in Scala

Hello i am new to Scala . I tried this code
def web ( url : Any) {
| val ur= new URL("url")
| val content=fromInputStream(ur.openStream).getLines.mkString("\n")
| print(content)
| }
when i pass a url like web("http://contentexplore.com/iphone-6-amazing-looks/")
it is showing error
java.net.MalformedURLException: no protocol: url
at java.net.URL.<init>(URL.java:585)
at java.net.URL.<init>(URL.java:482)
at java.net.URL.<init>(URL.java:431)
at .web(<console>:22)
at .<init>(<console>:23)
at .<clinit>(<console>)
at .<init>(<console>:11)
at .<clinit>(<console>)
at $print(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:704)
at scala.tools.nsc.interpreter.IMain$Request$$anonfun$14.apply(IMain.scala:920)
at scala.tools.nsc.interpreter.Line$$anonfun$1.apply$mcV$sp(Line.scala:43)
at scala.tools.nsc.io.package$$anon$2.run(package.scala:25)
at java.lang.Thread.run(Thread.java:722)
My question is how can i pass a url explicitly in scala .Kindly suggest me an idea .Thanks in advance
As mentioned in the comments, this line is the problem:
val ur= new URL("url")
If you want to create a URL from the input param url, the code should be:
val ur= new URL(url)
With the error, the java URL class was trying to parse a String with value "url", looking first for a recognized protocol (http, https, etc...) and not finding one, so that's why you were seeing that error.

Using Google Caliper with Scala

I am trying to use Caliper with Scala(2.10) in Eclipse Juno(4.2). For the start I've set up a benchmark that simply iterates a foreachloop over an array.
import com.google.caliper.Param
import com.google.caliper.SimpleBenchmark
class Benchmark extends SimpleBenchmark {
#Param(Array("10", "100", "1000", "10000"))
val length: Int = 0
var array: Array[Int] = _
override def setUp() {
array = new Array(length)
}
def timeForeach(reps: Int) = {
var result = 0
array.foreach {
result += _
}
result
}
When I start the benchmark with:
object myRunner {
def main(args: Array[String]) {
Runner.main(classOf[Benchmark], args)
}
}
I get these exceptions that I dont understand
0% Scenario{vm=java, trial=0, benchmark=Foreach, length=10} Failed to execute java -cp C:\Users\bob\workspace\myBenchmark\bin;C:\Users\bob\workspace\caliper\caliper\target>\classes;C:\Users\bob\workspace\caliper\caliper\target\test-classes;C:\Users\bob\.m2\repository\com\google\code\findbugs\jsr305\1.3.9\jsr305-1.3.9.jar;C:\Users\bob\.m2\repository\com\google\code\gson\gson\1.7.1\gson-1.7.1.jar;C:\Users\bob\.m2\repository\com\google\guava\guava\11.0.1\guava-11.0.1.jar;C:\Users\bob\.m2\repository\com\google\code\java-allocation-instrumenter\java-allocation-instrumenter\2.0\java-allocation-instrumenter-2.0.jar;C:\Users\bob\.m2\repository\asm\asm\3.3.1\asm-3.3.1.jar;C:\Users\bob\.m2\repository\asm\asm-analysis\3.3.1\asm-analysis-3.3.1.jar;C:\Users\bob\.m2\repository\asm\asm-commons\3.3.1\asm-commons-3.3.1.jar;C:\Users\bob\.m2\repository\asm\asm-tree\3.3.1\asm-tree-3.3.1.jar;C:\Users\bob\.m2\repository\asm\asm-util\3.3.1\asm-util-3.3.1.jar;C:\Users\bob\.m2\repository\asm\asm-xml\3.3.1\asm-xml-3.3.1.jar;C:\Users\bob\.m2\repository\junit\junit\3.8.2\junit-3.8.2.jar com.google.caliper.InProcessRunner --warmupMillis 3000 --runMillis 1000 --measurementType TIME --marker //ZxJ/ -Dbenchmark=Foreach -Dlength=10 org.example.Benchmark
Exception in thread "main" java.lang.NoClassDefFoundError: scala/Function1
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.google.caliper.ScenarioSelection.getClassByName(ScenarioSelection.java:154)
at com.google.caliper.ScenarioSelection.prepareSuite(ScenarioSelection.java:123)
at com.google.caliper.ScenarioSelection.select(ScenarioSelection.java:83)
at com.google.caliper.InProcessRunner.run(InProcessRunner.java:38)
at com.google.caliper.InProcessRunner.main(InProcessRunner.java:103)
Caused by: java.lang.ClassNotFoundException: scala.Function1
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
An exception was thrown from the benchmark code.
com.google.caliper.ConfigurationException: Failed to execute java -cp C:\Users\bob\workspace\myBenchmark\bin;C:\Users\bob\workspace\caliper\caliper\target\classes;C:\Users\bob\workspace\caliper\caliper\target\test-classes;C:\Users\bob\.m2\repository\com\google\code\findbugs\jsr305\1.3.9\jsr305-1.3.9.jar;C:\Users\bob\.m2\repository\com\google\code\gson\gson\1.7.1\gson-1.7.1.jar;C:\Users\bob\.m2\repository\com\google\guava\guava\11.0.1\guava-11.0.1.jar;C:\Users\bob\.m2\repository\com\google\code\java-allocation-instrumenter\java-allocation-instrumenter\2.0\java-allocation-instrumenter-2.0.jar;C:\Users\bob\.m2\repository\asm\asm\3.3.1\asm-3.3.1.jar;C:\Users\bob\.m2\repository\asm\asm-analysis\3.3.1\asm-analysis-3.3.1.jar;C:\Users\bob\.m2\repository\asm\asm-commons\3.3.1\asm-commons-3.3.1.jar;C:\Users\bob\.m2\repository\asm\asm-tree\3.3.1\asm-tree-3.3.1.jar;C:\Users\bob\.m2\repository\asm\asm-util\3.3.1\asm-util-3.3.1.jar;C:\Users\bob\.m2\repository\asm\asm-xml\3.3.1\asm-xml-3.3.1.jar;C:\Users\bob\.m2\repository\junit\junit\3.8.2\junit-3.8.2.jar com.google.caliper.InProcessRunner --warmupMillis 3000 --runMillis 1000 --measurementType TIME --marker //ZxJ/ -Dbenchmark=Foreach -Dlength=10 org.example.Benchmark
at com.google.caliper.Runner.measure(Runner.java:309)
at com.google.caliper.Runner.runScenario(Runner.java:229)
at com.google.caliper.Runner.runOutOfProcess(Runner.java:378)
at com.google.caliper.Runner.run(Runner.java:97)
at com.google.caliper.Runner.main(Runner.java:423)
at com.google.caliper.Runner.main(Runner.java:436)
at org.example.myRunner$.main(myRunner.scala:7)
at org.example.myRunner.main(myRunner.scala)
I think I have some issues with the classpath but i am not sure.
I hope someone can help me :)
thanks in advance
Davram Bashere
It looks very much as though Caliper is running a new JVM and doesn't know that it needs to include the Scala libraries on the classpath.
This question describes how to run a Scala app with the java command on the command line. It should be a good starting point to solving this problem.
Even if you are editing scala sources in Eclipse you may still use sbt to run your code. Sbt is a great tool for managing your projects classpath in addition to providing a plugin system for providing the kinds of features like running Caliper benchmarks. I recently worked on a project where I needed just that and factored it out into an published sbt plugin. This may be of some help for you as well.
Thanks for your help. The problem was as expected the stupid classpath. I have downloaded the caliper project from googlecode and added the scala dependency. Now I've build my own jar-with-dependencies and it works quite fine.
Thanks for the answeres anyway :-)