java classpath wildcard behaviour - classpath

I've used the java -classpath wildcard expansion feature previously and successfully. I'm currently experiencing a strange problem with it.
The wildcard is supposed to expand to every jar in the named folder. Here's a quote from Oracle:
Class path entries can contain the basename wildcard character *,
which is considered equivalent to specifying a list of all the files
in the directory with the extension .jar or .JAR. For example, the
class path entry foo/* specifies all JAR files in the directory
named foo. A classpath entry consisting simply of * expands to a
list of all the jar files in the current directory.
This is a link to Oracle doc on Java 6 on the subject of classpath.
The behaviour I am seeing contradicts this. Here are 3 runs. The first explicitly names the jar and so it works. The others use a wildcard and fail. Why? This matters to me because I rely on wildcards (elsewhere) and so an understanding of this unexpected behaviour is important to me.
#!/bin/bash
printf "The EV is...\n"
echo $CLASSPATH
printf "The working directory is...\n"
pwd
printf "Directory listing...\n"
ls
printf "END of directory listing.\n"
printf "Test with named jar.\n"
java -javaagent:../sizeof/sizeof.jar -classpath ./testsizeof.jar info.zqxj.test.Tester
printf "Test with star.\n"
java -javaagent:../sizeof/sizeof.jar -classpath * info.zqxj.test.Tester
printf "Test with dot slash star.\n"
java -javaagent:../sizeof/sizeof.jar -classpath ./* info.zqxj.test.Tester
The output:
The EV is...
The working directory is...
/home/b/Documents/workspace/testsizeof
Directory listing...
bin run.sh src testsizeof.jar
END of directory listing.
Test with named jar.
40
Test with star.
Exception in thread "main" java.lang.NoClassDefFoundError: run/sh
Caused by: java.lang.ClassNotFoundException: run.sh
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: run.sh. Program will exit.
Test with dot slash star.
Exception in thread "main" java.lang.NoClassDefFoundError: //run/sh
Caused by: java.lang.ClassNotFoundException: ..run.sh
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: ./run.sh. Program will exit.

Solution, double quote the classpath argument. Example: -classpath "*" This is necessary on the command line as well as inside a bash script.
A subsequent addendum:
Furthermore, note that -classpath "~/folder/*" fails but -classpath ~/folder/"*" is good. Quote the wildcard but do not quote the ~. It seems that you need the operating system to interpret ~ but you need to quote the * wildcard because you want to pass it to java for expansion in Java-fashion.
Note also that you should not ask java to expand *.jar because that will have an unintended result. The Java spec says that the correct wildcard is just the * alone.

Related

Adding custom handler to jetty throws ClassNotFoundException

I am trying to inject a custom handler to jetty.
I have written the handler in my application code which is packaged as a war.
package com.foo.bar
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
import org.eclipse.jetty.server.Request
import org.eclipse.jetty.server.handler.AbstractHandler
// scalastyle:off println
class CustomJettyHandler extends AbstractHandler {
override def handle(target: String, baseRequest: Request,
request: HttpServletRequest, response: HttpServletResponse): Unit = {
println("This is a custom jetty handler")
}
}
// scalastyle:on println
I have then injected this handler in the jetty.xml file:
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
........
........
<Call name="insertHandler">
<Arg>
<New id="CustomJettyHandler" class="com.foo.bar.CustomJettyHandler"/>
</Arg>
</Call>
........
I am now running jetty in standalone mode. Note that I am passing the location where CustomJettyHandler.class resides to jetty-start.jar.
java -server -Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog -jar lib/jetty-start.jar OPTIONS=All --lib=lib/* --lib=webapps/root/WEB-INF/classes/com/foo/bar/* etc/jetty.xml etc/jetty-jmx.xml --debug
In my application logs, I can see jetty loading my custom handler to its classpath but then eventually failing because of ClassNotFoundException. Can someone point out where could this be going wrong?
.......
rawlibref = webapps/root/WEB-INF/classes/com/foo/bar/*
expanded = webapps/root/WEB-INF/classes/com/foo/bar/*
getPaths('webapps/root/WEB-INF/classes/com/foo/bar/*')
Using relative path pattern: glob:**/webapps/root/WEB-INF/classes/com/foo/bar/*
Found [webapps/root/WEB-INF/classes/com/foo/bar/CustomJettyHandler.class] /Users/...path_to_application.../webapps/root/WEB-INF/classes/com/foo/bar/CustomJettyHandler.class
Adding classpath component: /Users/...path_to_application.../webapps/root/WEB-INF/classes/com/foo/bar/CustomJettyHandler.class
.......
.......
.......
URLClassLoader.url[33] = file:/Users/...path_to_application.../webapps/root/WEB-INF/classes/com/foo/bar/CustomJettyHandler.class
Loaded 34 URLs into URLClassLoader
class org.eclipse.jetty.xml.XmlConfiguration - 9.4.24.v20191120
Command Line Args: /var/folders/z5/dmt38gq54kxcrrzpgvbl5m_c0000gp/T/start_6046998329479549547.properties /Users/...path_to_application.../etc/jetty.xml /Users/...path_to_application.../etc/jetty-jmx.xml
2020-05-27 14:46:13.676:INFO::main: Logging initialized #477ms to org.eclipse.jetty.util.log.StdErrLog
2020-05-27 14:46:13.934:INFO:oeju.TypeUtil:main: JVM Runtime does not support Modules
2020-05-27 14:46:14.007:WARN:oejx.XmlConfiguration:main: Config error at <Call name="insertHandler"><Arg>| <New id="CustomJettyHandler" class="com.foo.bar.CustomJettyHandler"/>| </Arg></Call> java.lang.ClassNotFoundException: com.foo.bar.CustomJettyHandler in file:///Users/...path_to_application.../etc/jetty.xml
2020-05-27 14:46:14.007:WARN:oejx.XmlConfiguration:main:
java.security.PrivilegedActionException: java.lang.ClassNotFoundException: com.foo.bar.CustomJettyHandler
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1837)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.jetty.start.Main.invokeMain(Main.java:218)
at org.eclipse.jetty.start.Main.start(Main.java:491)
at org.eclipse.jetty.start.Main.main(Main.java:77)
Caused by:
java.lang.ClassNotFoundException: com.foo.bar.CustomJettyHandler
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.eclipse.jetty.util.Loader.loadClass(Loader.java:64)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:1028)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.itemValue(XmlConfiguration.java:1638)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.value(XmlConfiguration.java:1539)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.access$500(XmlConfiguration.java:369)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration$AttrOrElementNode.getList(XmlConfiguration.java:1768)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration$AttrOrElementNode.getList(XmlConfiguration.java:1744)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.call(XmlConfiguration.java:919)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:512)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:454)
at org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:354)
at org.eclipse.jetty.xml.XmlConfiguration.lambda$main$0(XmlConfiguration.java:1874)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1837)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.jetty.start.Main.invokeMain(Main.java:218)
at org.eclipse.jetty.start.Main.start(Main.java:491)
at org.eclipse.jetty.start.Main.main(Main.java:77)
Where did you get this command line from?
java -server \
-Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog\
-jar lib/jetty-start.jar\
OPTIONS=All \
--lib=lib/* \
--lib=webapps/root/WEB-INF/classes/com/foo/bar/* \
etc/jetty.xml \
etc/jetty-jmx.xml \
--debug
That's not valid for use with Jetty 9.x's start.jar
Some advice
don't use XML directly on the java command line, that's the responsibility of the start.jar and the jetty-home module system (order is SUPER IMPORTANT).
Your choices of etc/jetty.xml and etc/jetty-jmx.xml is an incomplete list of xmls. (you are missing all dependent XML files)
don't edit the standard Jetty XML files, leave them be, otherwise you'll complicate upgrades later. Use XML to inject your behavior instead (see below for example)
OPTIONS is not supported by Jetty 9.x (that's old school Codehaus / Jetty 6 behavior)
Your usage of --lib= is discouraged, it only supports fully qualified paths to jars or directories with exploded class trees (not relative paths, no globs supported).
-Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog is a harsh way of setting up logging. Create a jetty-logging.properties files and make sure it's present on the classpath.
Example contents of jetty-logging.properties
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
org.eclipse.jetty.LEVEL=INFO
#org.eclipse.jetty.deploy.LEVEL=DEBUG
Do this instead.
Create an injection based XML for your new handler.
my-handler.xml
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Call name="insertHandler">
<Arg>
<New id="CustomJettyHandler" class="com.foo.bar.CustomJettyHandler" />
</Arg>
</Call>
</Configure>
Next create your jetty-base directory properly (for jetty's start.jar)
# Create your "jetty-base" directory
$ mkdir /path/to/myjettybase
$ cd /path/to/myjettybase
# Establish the basic files / directories / modules that you want to use
# You can find the configuration in start.ini or start.d/*.ini
$ java -jar /path/to/jetty-home/start.jar --add-to-start=http,jmx,deploy,ext,resources
# Copy your custom handler JAR into place
$ cp /path/to/my-handlers.jar /path/to/myjettybase/lib/ext/
# Copy your custom handler XML into place
$ cp /path/to/my-handler.xml /path/to/myjettybase/etc/
# Ensure that the custom handler XML is loaded into the jetty instance at the right point in the XML load order by declaring it to be used in a custom INI
$ mkdir start.d
$ echo "etc/my-handler.xml" >> start.d/my-handlers.ini
# Copy your jetty-logging.properties into place
$ cp /path/to/my-jetty-logging.properties /path/to/myjettybase/resources/jetty-logging.properties
# verify that your configuration looks sane (including the server classpath)
$ cd /path/to/myjettybase
$ java -jar /path/to/jetty-home/start.jar --list-config
# run your instance
$ cd /path/to/myjettybase
$ java -jar /path/to/jetty-home/start.jar
But that's not all, seeing as you seem to want to use jetty-home from a maven-style project (or project layout), you can do that too!
An example project showing this can be found at ...
https://github.com/jetty-project/servlet-error-page-handling
That maven project is also a valid jetty-base directory suitable for execution by a jetty-home archive somewhere else on your machine.

Headless Behavior Space with table extension

I currently have a project that I've completed using the netlogo interface.
My project includes multiple .nls files and one of my .nls files use the table extension. I've created a behavior space experiment and named it experiment for simplicity.
I'm trying to run the experiment headless using the following commands in my Netlogo application's directory where the Netlogo.jar is located.
java -Xmx1024m -Dfile.encoding=UTF-8 -cp ./Netlogo.jar org.nlogo.headless.Main --model /path/to/file/experiment.nlogo --experiment experiment --table /path/to/output/table-output.csv --spreadsheet /path/to/output/spreadsheet-output.csv
I'm getting the following error. It seems that I can't detect my extension from the .nls file. How can this be fixed?
Exception in thread "main" Nothing named TABLE:PUT has been defined at position 895 in
at org.nlogo.compiler.CompilerExceptionThrowers$.exception(CompilerExceptionThrowers.scala:26)
at org.nlogo.compiler.IdentifierParser.org$nlogo$compiler$IdentifierParser$$getAgentVariableReporter(IdentifierParser.scala:107)
at org.nlogo.compiler.IdentifierParser$$anonfun$processToken2$2.apply(IdentifierParser.scala:75)
at org.nlogo.compiler.IdentifierParser$$anonfun$processToken2$2.apply(IdentifierParser.scala:68)
at scala.Option.getOrElse(Option.scala:108)
at org.nlogo.compiler.IdentifierParser.processToken2(IdentifierParser.scala:68)
at org.nlogo.compiler.IdentifierParser.processToken$1(IdentifierParser.scala:31)
at org.nlogo.compiler.IdentifierParser$$anonfun$process$1.apply(IdentifierParser.scala:34)
at org.nlogo.compiler.IdentifierParser$$anonfun$process$1.apply(IdentifierParser.scala:34)
at scala.collection.Iterator$$anon$19.next(Iterator.scala:401)
at scala.collection.Iterator$class.toStream(Iterator.scala:1181)
at scala.collection.Iterator$$anon$19.toStream(Iterator.scala:399)
at scala.collection.Iterator$$anonfun$toStream$1.apply(Iterator.scala:1181)
at scala.collection.Iterator$$anonfun$toStream$1.apply(Iterator.scala:1181)
at scala.collection.immutable.Stream$Cons.tail(Stream.scala:1060)
at scala.collection.immutable.Stream$Cons.tail(Stream.scala:1052)
at scala.collection.immutable.StreamIterator$$anonfun$next$1.apply(Stream.scala:952)
at scala.collection.immutable.StreamIterator$$anonfun$next$1.apply(Stream.scala:952)
at scala.collection.immutable.StreamIterator$LazyCell.v(Stream.scala:941)
at scala.collection.immutable.StreamIterator.hasNext(Stream.scala:946)
at scala.collection.Iterator$class.isEmpty(Iterator.scala:329)
at scala.collection.immutable.StreamIterator.isEmpty(Stream.scala:933)
at scala.collection.immutable.StreamIterator.next(Stream.scala:948)
at scala.collection.Iterator$$anon$2.next(Iterator.scala:898)
at scala.collection.Iterator$$anon$2.head(Iterator.scala:885)
at org.nlogo.compiler.ExpressionParser.recurse$1(ExpressionParser.scala:474)
at org.nlogo.compiler.ExpressionParser.delayBlock(ExpressionParser.scala:479)
at org.nlogo.compiler.ExpressionParser.parseExpressionInternal(ExpressionParser.scala:339)
at org.nlogo.compiler.ExpressionParser.org$nlogo$compiler$ExpressionParser$$parseArgExpression(ExpressionParser.scala:290)
at org.nlogo.compiler.ExpressionParser$$anonfun$parseArguments$1.apply$mcVI$sp(ExpressionParser.scala:96)
at scala.collection.immutable.Range.foreach$mVc$sp(Range.scala:81)
at org.nlogo.compiler.ExpressionParser.parseArguments(ExpressionParser.scala:95)
at org.nlogo.compiler.ExpressionParser.parseStatement(ExpressionParser.scala:80)
at org.nlogo.compiler.ExpressionParser.parse(ExpressionParser.scala:55)
at org.nlogo.compiler.CompilerMain$$anonfun$compile$1.apply(CompilerMain.scala:34)
at org.nlogo.compiler.CompilerMain$$anonfun$compile$1.apply(CompilerMain.scala:29)
at scala.collection.Iterator$class.foreach(Iterator.scala:772)
at scala.collection.JavaConversions$JIteratorWrapper.foreach(JavaConversions.scala:573)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:73)
at scala.collection.JavaConversions$JCollectionWrapper.foreach(JavaConversions.scala:592)
at org.nlogo.compiler.CompilerMain$.compile(CompilerMain.scala:29)
at org.nlogo.compiler.Compiler$.compileProgram(Compiler.scala:28)
at org.nlogo.headless.HeadlessModelOpener.openFromMap(HeadlessModelOpener.scala:53)
at org.nlogo.headless.HeadlessWorkspace.openString(HeadlessWorkspace.scala:531)
at org.nlogo.headless.HeadlessWorkspace.open(HeadlessWorkspace.scala:513)
at org.nlogo.headless.Main$.newWorkspace$1(Main.scala:19)
at org.nlogo.headless.Main$$anonfun$runExperiment$1.apply(Main.scala:24)
at org.nlogo.headless.Main$$anonfun$runExperiment$1.apply(Main.scala:24)
at org.nlogo.lab.Lab$$anonfun$1.apply(Lab.scala:33)
at org.nlogo.lab.Lab$$anonfun$1.apply(Lab.scala:33)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:233)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:233)
at scala.collection.immutable.Range.foreach(Range.scala:78)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:233)
at scala.collection.immutable.Range.map(Range.scala:46)
at org.nlogo.lab.Lab.run(Lab.scala:33)
at org.nlogo.headless.Main$.runExperiment(Main.scala:24)
at org.nlogo.headless.Main$$anonfun$main$1.apply(Main.scala:14)
at org.nlogo.headless.Main$$anonfun$main$1.apply(Main.scala:14)
at scala.Option.foreach(Option.scala:197)
at org.nlogo.headless.Main$.main(Main.scala:14)
at org.nlogo.headless.Main.main(Main.scala)
It seems that the .nlogo file must contain the extension declaration rather than the .nls file.

IDEA Scala: Could not find output directory

Trying to play with scala in IDEA with scala plug-in:
My HelloWorld object:
object HelloWorld {
def main(args: Array[String]) {
println("Hello")
}
}
And sometimes I getting next error when pressing 'Run HelloWorld' from context menu.
scalac: Error: Could not find an output directory for /Users/username/Work/src/sandbox/src/HelloWorld.scala in List((/Users/username/work/src/sandbox/src,/Users/username/work/src/sandbox/out/production/sandbox))
scala.reflect.internal.FatalError: Could not find an output directory for /Users/username/Work/src/sandbox/src/HelloWorld.scala in List((/Users/username
/work/src/sandbox/src,/Users/username/work/src/sandbox/out/production/sandbox))
at scala.tools.nsc.settings.MutableSettings$OutputDirs.outputDirFor(MutableSettings.scala:303)
at scala.tools.nsc.backend.jvm.BytecodeWriters$class.outputDirectory(BytecodeWriters.scala:26)
at scala.tools.nsc.backend.jvm.BytecodeWriters$class.scala$tools$nsc$backend$jvm$BytecodeWriters$$getFile(BytecodeWriters.scala:37)
at scala.tools.nsc.backend.jvm.BytecodeWriters$ClassBytecodeWriter$class.writeClass(BytecodeWriters.scala:89)
at scala.tools.nsc.backend.jvm.GenASM$AsmPhase$$anon$4.writeClass(GenASM.scala:67)
at scala.tools.nsc.backend.jvm.GenASM$JBuilder.writeIfNotTooBig(GenASM.scala:458)
at scala.tools.nsc.backend.jvm.GenASM$JMirrorBuilder.genMirrorClass(GenASM.scala:2954)
at scala.tools.nsc.backend.jvm.GenASM$AsmPhase.run(GenASM.scala:113)
at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1583)
at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1557)
at scala.tools.nsc.Global$Run.compileSources(Global.scala:1553)
at scala.tools.nsc.Global$Run.compile(Global.scala:1662)
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:26)
at org.jetbrains.jps.incremental.scala.local.LocalServer.compile(LocalServer.scala:25)
at org.jetbrains.jps.incremental.scala.remote.Main$.make(Main.scala:58)
at org.jetbrains.jps.incremental.scala.remote.Main$.nailMain(Main.scala:21)
at org.jetbrains.jps.incremental.scala.remote.Main.nailMain(Main.scala)
at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
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)
This error very annoying because to fix it I need to restart IDEA, clean/compile my project, add/remove launch configuration few times. Also command line from the error properly can be executed from the terminal manually.
Looking at the error comment:
Could not find an output directory for:
/Users/username/Work/src/sandbox/src/HelloWorld.scala
in
/Users/username/work/src/sandbox/src
/Users/username/work/src/sandbox/out/production/sandbox
Depending on the environment you're running the IntelliJ in the upper/lower case difference matters. Please make sure your user.home property is set correctly.
Answer from Norbert Radyk didn't apply to me. Paths were correct in my case. I had to delete target/scala-2.11/test-classes folder in order to compel Intellij to recompile the test class. A bit of a pain though as it will work as long as I don't have to modify the test itself. So not really a solution but a bit of a hack in case you really need to debug a test.

How to set environmental variable from Scala?

I need to set environmental variable (PATH) from Scala.
I tried this:
val cmd = Seq("export", "PATH='bla'")
cmd.lines
but I got error:
java.io.IOException: Cannot run program "export": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)
at scala.sys.process.ProcessBuilderImpl$Simple.run(ProcessBuilderImpl.scala:68)
at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.lines(ProcessBuilderImpl.scala:140)
at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.lines(ProcessBuilderImpl.scala:106)
at .<init>(<console>:12)
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:606)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:704)
at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:914)
at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:546)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:577)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:543)
at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:694)
at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:745)
at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:651)
at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:542)
at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:550)
at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:822)
at scala.tools.nsc.interpreter.ILoop.main(ILoop.scala:851)
at xsbt.ConsoleInterface.run(ConsoleInterface.scala:57)
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:73)
at sbt.compiler.AnalyzingCompiler.console(AnalyzingCompiler.scala:64)
at sbt.Console.console0$1(Console.scala:23)
at sbt.Console$$anonfun$apply$2$$anonfun$apply$1.apply$mcV$sp(Console.scala:24)
at sbt.TrapExit$.executeMain$1(TrapExit.scala:33)
at sbt.TrapExit$$anon$1.run(TrapExit.scala:42)
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:135)
at java.lang.ProcessImpl.start(ProcessImpl.java:130)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1022)
... 35 more
Is there some other way to do that?
Example from doc for sys.process.Process:
apply("java", new java.ioFile("/opt/app"), "CLASSPATH" -> "library.jar")
Edit for more helpful verbiage:
That is, you specify the env when you spawn a child process.
The environment of the current process is read-only; see System.getenv, or compare the abstractions sys.props and sys.env.
The fact that a shell augments the environment it bestows on subshells with exported variables is a shell convention. See 3.7.4 in the bash reference, for example:
On invocation, the shell scans its own environment and creates a
parameter for each name found, automatically marking it for export to
child processes. Executed commands inherit the environment. The export
and ‘declare -x’ commands allow parameters and functions to be added
to and deleted from the environment. If the value of a parameter in
the environment is modified, the new value becomes part of the
environment, replacing the old. The environment inherited by any
executed command consists of the shell's initial environment, whose
values may be modified in the shell, less any pairs removed by the
unset and ‘export -n’ commands, plus any additions via the export and
‘declare -x’ commands.
This is the first time my answer was longer than the Daniel Sobral answer it duplicates.
'export' isn't an executable, it's a shell built-in command. If you're trying to set the path in the parent shell, well, you can't. You can set it for a new shell that you execute. This is really more of a unix FAQ.

Eval not working on unexpanded macro quote

In common lisp I can do this:
src-> (defmacro macro-hello ()
`"hello")
(eval '(macro-hello))
no problem.
In clojure:
(defmacro macro-hello []
`"hello")
(eval '(macro-hello))
gives me an error. Have I done something wrong?
Clojure Error:
Exception in thread "main" java.lang.Exception: Unable to resolve symbol: macro-hello in this context (NO_SOURCE_FILE:12)
at clojure.lang.Compiler.analyze(Compiler.java:4340)
at clojure.lang.Compiler.analyze(Compiler.java:4286)
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:2767)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:4498)
at clojure.lang.Compiler.analyze(Compiler.java:4325)
at clojure.lang.Compiler.analyze(Compiler.java:4286)
at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:3862)
at clojure.lang.Compiler$FnMethod.parse(Compiler.java:3697)
at clojure.lang.Compiler$FnMethod.access$1100(Compiler.java:3574)
at clojure.lang.Compiler$FnExpr.parse(Compiler.java:2963)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:4494)
at clojure.lang.Compiler.analyze(Compiler.java:4325)
at clojure.lang.Compiler.eval(Compiler.java:4530)
at clojure.core$eval__3990.invoke(core.clj:1728)
at com.yourcompany.defpackage$_main__4.invoke(defpackage.clj:12)
at clojure.lang.AFn.applyToHelper(AFn.java:171)
at clojure.lang.AFn.applyTo(AFn.java:164)
at com.yourcompany.defpackage.main(Unknown Source)
Caused by: java.lang.Exception: Unable to resolve symbol: macro-hello in this context
at clojure.lang.Compiler.resolveIn(Compiler.java:4682)
at clojure.lang.Compiler.resolve(Compiler.java:4628)
at clojure.lang.Compiler.analyzeSymbol(Compiler.java:4605)
at clojure.lang.Compiler.analyze(Compiler.java:4307)
... 17 more
Java Result: 1
[Edited]: added ending double quote
Your code works for me.
user> (defmacro macro-hello [] `"hello")
#'user/macro-hello
user> (eval '(macro-hello))
"hello"
This is via bleeding-edge Clojure. "Unable to resolve symbol" means it can't find the macro called macro-hello in the current namespace. Are you running this from the REPL or in a source file? I typed your statements at a REPL literally.
Not sure if this is a cause of problems for you, but please note the difference between ` and ' in Clojure. ` does namespace resolution and ' doesn't.
user> `macro-hello
user/macro-hello
user> 'macro-hello
macro-hello
This is different from Common Lisp's behavior. Backtick-quoting a String like `"hello" doesn't make much sense, since Strings don't belong to namespaces, but it also doesn't hurt anything.
(I'm assuming you made a typo in your Clojure code, with the missing double-quote.)
I like to work out of /opt on Mac and Linux boxes. To get the Clojure source. (% is Unix prompt)
% cd /opt
% git clone git://github.com/richhickey/clojure.git; #From Unix command line, you'll have an /opt/clojure dir
% cd /opt/clojure
% /opt/netbeans-6.7.1/java2/ant/bin/ant; # Run ant. It ships with Netbeans.
% cd /opt; # mkdir /opt if it's not there.
% git clone git://github.com/richhickey/clojure-contrib.git; # Get contrib
% /opt/netbeans-6.7.1/java2/ant/bin/ant -Dclojure.jar=../clojure/clojure.jar ; # Tell ant where clojure.jar is located
I rename jars to clojure.jar and clojure-contrib.jar
Copy these jars to your Netbean's project lib directory.