Running ant script from within scala program - scala

I tried
val cmd = sys.process.Process(Seq("C:\apache-ant-1.9.3\bin\ant", "everythingNoJunit"), new java.io.File(scriptDir))
cmd.lines
and got this error:
CreateProcess error=193, %1 is not a valid Win32 application
How do I run the ant script from within scala app?

The basic answer is that your should be using "ant.bat" instead of "ant" on a windows machine as in this answer
In addition to that, I would suggest using a non-windows styled path so you don't have to escape the backslashes:
val cmd = sys.process.Process(Seq("/apache-ant-1.9.3/bin/ant.bat", "everythingNoJunit"), new java.io.File(scriptDir))
Using this approach, I'm able to run an an ant target successfully when my scala application is also in "c:".

Related

How to run an EXE file compiled from a F# source on the Mac Terminal?

I have a hello world program in F#.
open System
[<EntryPoint>]
let main argv =
printfn "Hello World from F#!"
0 // return an integer exit code%
On an Mac OS, I can compile it with "fsharpc", which generates two files
FSharp.Core.dll hello.exe
The EXE file certainly looks strange on a Mac. But how can I execute it from the command line, without using a project structure (because it seems an overkill) like what is explained here: https://dotnet.microsoft.com/learn/languages/fsharp-hello-world-tutorial/create
Actually if I run "dotnet hello.exe", I get this error:
A fatal error was encountered. The library 'libhostpolicy.dylib'
required to execute the application was not found in
'/Users/zell/hello/'. Failed to run as a self-contained app. If this
should be a framework-dependent app, add the
/Users/zell/hello/hello.runtimeconfig.json file specifying the
appropriate framework.
You can create and build/run F# apps like so:
dotnet new console -lang F# -o SomeDirectory && cd SomeDirectory
dotnet run
Building it without running is:
dotnet build
You can see a reference for all commands here: https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet
You appear to have Mono installed, which is where fsharpc comes from. I wouldn't recommend using that unless you are doing mobile development with Xamarin, which currently requires Mono.
By trial and error, I found to run my new .exe file, I needed a .runtimeconfig.json file in the same folder with same without-the-extension-name, i.e. hello.runtimeconfig.json:
{
"runtimeOptions": {
"tfm": "net5.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "5.0.0"
}
}
}
Then dotnet hello.exe will work.

Java Illegal Argument Exception thrown when opening NetLogo model in Jython

I am trying to control NetLogo's API using Jython 2.7.0 (on Java 1.8.0_131) running on OS X El Capitan (10.11.6) to run experiments. In trying to run the following code:
import site
site.addsitedir("/Users/nqe/NetLogo/NetLogo 6.0.1/Java/")
import org.nlogo.headless.HeadlessWorkspace as hw
workspace = hw.newInstance()
workspace.open("models/Sample Models/Earth Science/Fire.nlogo")
workspace.command("set density 62")
workspace.command("random-seed 0")
workspace.command("setup")
workspace.command("repeat 50 [ go ]")
print (workspace.report("burned-trees"))
workspace.dispose()
I get the following error:
at scala.Predef$.require(Predef.scala:264)
at org.nlogo.generate.PrimitiveCache$.read$1(PrimitiveCache.scala:22)
at org.nlogo.generate.PrimitiveCache$.$anonfun$getClassReader$1(PrimitiveCache.scala:26)
at scala.collection.mutable.AbstractMap.getOrElseUpdate(Map.scala:80)
at org.nlogo.generate.PrimitiveCache$.getClassReader(PrimitiveCache.scala:26)
at org.nlogo.generate.PeepholeSafeChecker.processClass(PeepholeSafeChecker.scala:49)
at org.nlogo.generate.PeepholeSafeChecker.isSafe(PeepholeSafeChecker.scala:42)
at org.nlogo.generate.Generator$InstructionGenerator.generateInstruction(Generator.scala:190)
at org.nlogo.generate.Generator$InstructionGenerator.generateBodyMethod(Generator.scala:124)
at org.nlogo.generate.Generator$InstructionGenerator.generate(Generator.scala:99)
at org.nlogo.generate.Generator.org$nlogo$generate$Generator$$recurse(Generator.scala:29)
at org.nlogo.generate.Generator.$anonfun$recurse$1(Generator.scala:31)
at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:234)
at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:193)
at scala.collection.TraversableLike.map$(TraversableLike.scala:234)
at scala.collection.mutable.ArrayOps$ofRef.map(ArrayOps.scala:193)
at org.nlogo.generate.Generator.org$nlogo$generate$Generator$$recurse(Generator.scala:31)
at org.nlogo.generate.Generator.$anonfun$generate$1(Generator.scala:25)
at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:234)
at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:193)
at scala.collection.TraversableLike.map$(TraversableLike.scala:234)
at scala.collection.mutable.ArrayOps$ofRef.map(ArrayOps.scala:193)
at org.nlogo.generate.Generator.generate(Generator.scala:25)
at org.nlogo.compile.CompilerMain$.assembleProcedure(CompilerMain.scala:79)
at org.nlogo.compile.CompilerMain$.$anonfun$compile$2(CompilerMain.scala:55)
at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:234)
at scala.collection.immutable.List.foreach(List.scala:378)
at scala.collection.TraversableLike.map$(TraversableLike.scala:234)
at scala.collection.immutable.List.map(List.scala:284)
at org.nlogo.compile.CompilerMain$.compile(CompilerMain.scala:55)
at org.nlogo.compile.Compiler.compileProgram(Compiler.scala:52)
at org.nlogo.headless.HeadlessModelOpener.openFromModel(HeadlessModelOpener.scala:54)
at org.nlogo.headless.HeadlessWorkspace.openModel(HeadlessWorkspace.scala:532)
at org.nlogo.headless.HeadlessWorkspace.open(HeadlessWorkspace.scala:499)
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)
java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: requirement failed
In case the "import site" part is not clear, I did the following:
Create a jython script to write all .jar files in "/Users/nqe/NetLogo/NetLogo 6.0.1/Java/" to a .pth file.
I then placed this .pith file into said the .../Java/ directory with the .jar files.
This allows me to access all the .jar dependencies from sys.path when needing to the import various API features of NetLogo.
I can't figure out exactly what causes this error, for in running on python interactive mode, I was able to successfully create a new instance of NetLogo JVM using the hw.newInstance() command (I could see a Java icon pop up when running this code), and the open command threw the appropriate errors if I fail to specify a url, for example.
Because of this, I thought it might have something to do with my JVM not being configured properly, so I tried a few things.
First, I checked that I was able to actually run the java example of controlling NetLogo API in headless mode found here: https://github.com/NetLogo/NetLogo/wiki/Controlling-API. I was able to run the code given here using these commands:
javadir=/Users/nqe/NetLogo/ControlAPI/
netjardir=/Users/nqe/NetLogo/NetLogo\ 6.0.1/Java/netlogo-mac-app.jar
javaname=Example1
javac -cp "${javadir}":"${netjardir}" $javaname.java
java -cp "${javadir}":"${netjardir}" $javaname
without changing any JVM settings manually. Nevertheless, I went ahead and tried changing things in my JVM settings when running the jython code such as the path to docs and extensions, but in particular, to the ./lib directory. Unfortunately, specifying the following JVM setting:
-Djava.library.path=~/JRE/Contents/Home/jre/lib/
does nothing to help the cause. Note that the ~ here is short for being in the NetLogo 6.0.1 directory and that this was the only lib directory I could find.
Finally, I discord this: when I try to run the above jython script when only specifying the path to netlogo-mac-app.jar, I AM NOT ABLE TO IMPORT the headless class stuff. Hence, the compilation/ running of the java while specifying only this one .jar classpath could possibly be somehow accessing some useful meta-data necessary for NetLogo to work (I don't know if this is possible with my level of Java background).
Upon thinking this, I found a NetLogo.cfg file in ~/NetLogo 6.0.1.app/Contents/Java/ that contains the following info:
[Application]
app.name=NetLogo
app.mainjar=netlogo-mac-app.jar
app.version=6.0.1
app.preferences.id=org/nlogo/app
app.mainclass=org/nlogo/app/MacApplication
app.classpath=$APPDIR/../../Java/args4j-2.0.12.jar:$APPDIR/../../Java/asm-5.0.3.jar:$APPDIR/../../Java/asm-5.0.3.jar:$APPDIR/../../Java/asm-all-5.0.4.jar:$APPDIR/../../Java/asm-all-5.0.4.jar:$APPDIR/../../Java/asm-analysis-5.0.3.jar:$APPDIR/../../Java/asm-analysis-5.0.3.jar:$APPDIR/../../Java/asm-tree-5.0.3.jar:$APPDIR/../../Java/asm-tree-5.0.3.jar:$APPDIR/../../Java/asm-util-5.0.3.jar:$APPDIR/../../Java/asm-util-5.0.3.jar:$APPDIR/../../Java/behaviorsearch.jar:$APPDIR/../../Java/commons-codec-1.10.jar:$APPDIR/../../Java/commons-codec-1.10.jar:$APPDIR/../../Java/commons-logging-1.1.1.jar:$APPDIR/../../Java/commons-logging-1.1.1.jar:$APPDIR/../../Java/gluegen-rt-2.3.2.jar:$APPDIR/../../Java/gluegen-rt-2.3.2.jar:$APPDIR/../../Java/httpclient-4.2.jar:$APPDIR/../../Java/httpclient-4.2.jar:$APPDIR/../../Java/httpcore-4.2.jar:$APPDIR/../../Java/httpcore-4.2.jar:$APPDIR/../../Java/httpmime-4.2.jar:$APPDIR/../../Java/httpmime-4.2.jar:$APPDIR/../../Java/java-objc-bridge-1.0.0.jar:$APPDIR/../../Java/jcommon-1.0.16.jar:$APPDIR/../../Java/jfreechart-1.0.13.jar:$APPDIR/../../Java/jhotdraw-6.0b1.jar:$APPDIR/../../Java/jhotdraw-6.0b1.jar:$APPDIR/../../Java/jmf-2.1.1e.jar:$APPDIR/../../Java/jmf-2.1.1e.jar:$APPDIR/../../Java/jna-4.2.2.jar:$APPDIR/../../Java/jogl-all-2.3.2.jar:$APPDIR/../../Java/jogl-all-2.3.2.jar:$APPDIR/../../Java/json-simple-1.1.1.jar:$APPDIR/../../Java/json-simple-1.1.1.jar:$APPDIR/../../Java/log4j-1.2.16.jar:$APPDIR/../../Java/log4j-1.2.16.jar:$APPDIR/../../Java/macro-compat_2.12-1.1.1.jar:$APPDIR/../../Java/macro-compat_2.12-1.1.1.jar:$APPDIR/../../Java/netlogo-6.0.1.jar:$APPDIR/../../Java/netlogo-6.0.1.jar:$APPDIR/../../Java/netlogo-mac-app.jar:$APPDIR/../../Java/parboiled-core-1.1.7.jar:$APPDIR/../../Java/parboiled-core-1.1.7.jar:$APPDIR/../../Java/parboiled-java-1.1.7.jar:$APPDIR/../../Java/parboiled-java-1.1.7.jar:$APPDIR/../../Java/parboiled_2.12-2.1.3.jar:$APPDIR/../../Java/parboiled_2.12-2.1.3.jar:$APPDIR/../../Java/pegdown-1.6.0.jar:$APPDIR/../../Java/pegdown-1.6.0.jar:$APPDIR/../../Java/picocontainer-2.13.6.jar:$APPDIR/../../Java/picocontainer-2.13.6.jar:$APPDIR/../../Java/rsyntaxtextarea-2.6.0.jar:$APPDIR/../../Java/rsyntaxtextarea-2.6.0.jar:$APPDIR/../../Java/scala-library-2.12.0.jar:$APPDIR/../../Java/scala-library-2.12.1.jar:$APPDIR/../../Java/scala-library-2.12.1.jar:$APPDIR/../../Java/scala-parser-combinators_2.12-1.0.5.jar:$APPDIR/../../Java/scala-parser-combinators_2.12-1.0.5.jar:$APPDIR/../../Java/shapeless_2.12-2.3.2.jar:$APPDIR/../../Java/shapeless_2.12-2.3.2.jar
app.runtime=$APPDIR/../../JRE
app.identifier=org.nlogo.app
[JVMOptions]
-Dnetlogo.extensions.dir=$APPDIR/../../extensions
-Dnetlogo.models.dir=$APPDIR/../../models
-Dnetlogo.docs.dir=$APPDIR/../../docs
-Xdock:name=NetLogo
-Dorg.nlogo.mac.appClassName=org.nlogo.app.App$
-Xmx1024m
-Dfile.encoding=UTF-8
-Dapple.awt.graphics.UseQuartz=true
[JVMUserOptions]
[ArgOptions]
This seemed promising, but literally deleting this file had no affect on my ability to run NetLogo by opening the application/ using the Control API with Java method. As such, I am stumped, so any help would be greatly appreciated.

sbt: Unable to specify application configuration in mingw

I am trying to launch an application using sbt's application launcher.
This application is defined as:
#!/bin/sh
java -jar /home/salil.wadnerkar/.conscript/sbt-launch.jar #"/home/salil.wadnerkar/.conscript/n8han/conscript/cs/launchconfig" "$#"
However, when I launch it, it gives me this error:
$ ~/bin/cs n8han/giter8
Error during sbt execution: Could not find configuration file 'C:/MinGW/msys/1.0/home/salil.wadnerkar/.conscript/n8han/conscript/cs/launchconfig'. Searched:
file:/C:/MinGW/msys/1.0/home/salil.wadnerkar/
file:/C:/Users/salil.wadnerkar/
file:/C:/MinGW/msys/1.0/home/salil.wadnerkar/.conscript/
However, the file is present there. So, I think it's because of some quirk in the way sbt handles mingw file path.
Does anybody know how I can get it working?
In Cygwin I used
java -jar "`cygpath -m "$HOME/.conscript/sbt-launch.jar"`" "#file:///C:/Users/cvanvranken/.conscript/n8han/conscript/cs/launchconfig" "$#"
I expect you will be able to get yours to work with something similar, perhaps this:
java -jar /home/salil.wadnerkar/.conscript/sbt-launch.jar "#file:///C:/Users/salil.wadnerkar/.conscript/n8han/conscript/cs/launchconfig" "$#"
or
java -jar /home/salil.wadnerkar/.conscript/sbt-launch.jar "#file:///C:/MinGW/msys/1.0/home/salil.wadnerkar/.conscript/n8han/conscript/cs/launchconfig" "$#"
if those fail, you still definitely need to use the file:// protocol.
Also note the three directories it is searching in the error message
file:/C:/MinGW/msys/1.0/home/salil.wadnerkar/
file:/C:/Users/salil.wadnerkar/
file:/C:/MinGW/msys/1.0/home/salil.wadnerkar/.conscript/
no matter what you put in the launchconfig parameter, if it is not recognized then those directories are searched by default. So you could have gibberish in your parameter and still see the same exact error you are getting now.
you can set the launch config path relative to the .conscript folder -
java -jar /home/salil.wadnerkar/.conscript/sbt-launch.jar #n8han/conscript/cs/launchconfig "$#"

Why would Eclipse not be able to include a file when running a PHPUnit test?

I have the following class and unit test in a PHP project in Eclipse:
I know my unit test works as I can run it at the command line:
Now I want to run this test from Eclipse. I set up PHP Unit in Eclipse like this:
However, when I run the PHPUnit tests:
It tells me that it can't include the class file:
/usr/bin/php -c /var/folders/UA/UAv38snBHd0QMgEPMCmM9U+++TM/-Tmp-/zend_debug/session4910937990995915704.tmp -d asp_tags=off /Applications/eclipse/plugins/org.phpsrc.eclipse.pti.tools.phpunit_0.5.0.R20101103000000/php/tools/phpunit.php --log-junit /var/folders/UA/UAv38snBHd0QMgEPMCmM9U+++TM/-Tmp-/pti_phpunit/phpunit.xml /Volumes/data/domains/et/extjslayout/phpunittest/tests
PHP Warning: include_once(../Product.php): failed to open stream: No such file or directory in /Volumes/data/domains/et/extjslayout/phpunittest/tests/ProductTest.php on line 3
PHP Warning: include_once(): Failed opening '../Product.php' for inclusion (include_path='/usr/local/PEAR') in /Volumes/data/domains/et/extjslayout/phpunittest/tests/ProductTest.php on line 3
PHP Fatal error: Class 'Product' not found in /Volumes/data/domains/et/extjslayout/phpunittest/tests/ProductTest.php on line 9
Why would PHPUnit be able to find the class when run from the command line but not when run from Eclipse?
When you start something from the command line, the "current directory" has a well-defined meaning: It's the directory where you started the command.
In Eclipse, what is the "current directory"? It's probably the directory from which you started Eclipse or maybe the folder in which Eclipse is installed.
I haven't used PHP in Eclipse before but for other languages, I can set the current directory in the launch config somewhere. If that doesn't work, define a variable which points to your project and then use absolute paths (using that variable as a starting point).
Have same problem. Found only solution by creating tests with internal PHPUnit wizard like at this screenshot:
Source: HowTo create a Test Case Class from a PHP Class
But following investigate show that your test case file should contain reference to tested code for example like this: require_once 'C:\Apache2\htdocs\jobeet\src\Ibw\JobeetBundle\Utils\Jobeet.php';
Other experiments with plugin config not bringing luck. So in my opinion PHPUnit from PHP Tools not well developed plugin. Consider using MakeGood plugin as better alternative.

GWT Junit - error='no compilation unit for that type was seen'

I'm trying to run a GWT unit test in a sample app. I ran
cmd /c /java/gwt-windows-1.6.4/webAppCreator.cmd -out gwttasks com.gwttasks.GwtTasks
Copied in junit-4.5.jar into a lib directory, and added that to the classpath.
Ran:
cmd /c /java/gwt-windows-1.6.4/junitCreator.cmd -junit lib/junit-4.5.jar -module com.gwttasks.GwtTasks -eclipse GwtTasks com.gwt
tasks.unit.GwtJunit
When I try to run any of the generated cmd file (such as GwtJunit-hosted.cmd) or any of the launch files, I get the following error. All the web pages I've seen say to add the test source to the classpath, but it's already there, so that's not the problem. Anyone else seen this?
com.google.gwt.junit.JUnitFatalLaunchException: The test class 'com.gwttasks.unit.GwtJunit' was not found in module 'com.gwttasks.GwtTasks'; no compilation unit for that type was seen
at com.google.gwt.junit.JUnitShell.checkTestClassInCurrentModule(JUnitShell.java:390)
at com.google.gwt.junit.JUnitShell.runTestImpl(JUnitShell.java:626)
...
The answer could be found here :
http://raibledesigns.com/rd/entry/testing_gwt_applications
In netbeans I added the src/java and test to the class path and debugging worked!!!!!
THANKS
I just want to add that I had the same problem, because I did the (very silly) mistake to not put the GWTTestCase class into the "client" directory, but into another one. No wonder it wasn't found ;)