I have OutOfMemoryError when I compile my project using sbt. So I need to enlarge the java compiler heap space. I use java 6. And I have set JAVA_HOME to java 6 in my bash env.
I tried to add this line to build.sbt
javacOptions ++= Seq(<other arguments>,"-J-Xmx1028m")
When I compile, I have error like this:
[error] javac: invalid flag: -J-Xmx1028m
[error] Usage: javac <options> <source files>
[error] use -help for a list of possible options
The funny thing is: this error disappears when I specify the javaHome in build.sbt, which I have already done it in my bash env:
javaHome := Some(file("path to java 6"))
Does it mean that I have to specify JAVA_HOME twice? once in bash env, once in build.sbt? I don't want to specify a absolute path in build.sbt, which makes it may not work properly on other computers.
Related
I used to be able to use the following in my build.sbt file to allow me to executed a run command while in my root project, but the run command would only run in the context of my migrations project:
lazy val root = project.dependsOn(rest,migrations).settings(publish := { }).disablePlugins(RevolverPlugin, AssemblyPlugin)
lazy val rest = project.enablePlugins(BuildInfoPlugin)
lazy val migrations = project.dependsOn(rest).settings(mainClass in (Compile, run) := Some("com.myapp.Migrations"), fork in run := true).disablePlugins(RevolverPlugin)
run in Compile <<= (run in Compile in migrations)
I would then execute run like so:
> run up
(p.s. up is an argument to be passed to com.myapp.Migrations)
However, when updating to sbt v0.13.17 I now receive the warning:
See http://www.scala-sbt.org/0.13/docs/Migrating-from-sbt-012x.html
run in Compile <<= (run in Compile in migrations)
In the referenced url, it seems to indicate that I can replace the <<= with :=, however if I change it like so:
run in Compile := (run in Compile in migrations)
And then I type in run up in sbt, I get the error:
[error] Expected ID character
[error] Not a valid command: run (similar: plugin, new)
[error] Expected project ID
[error] Expected configuration
[error] Expected ':' (if selecting a configuration)
[error] Expected key
[error] Expected '::'
[error] Expected end of input.
[error] run up
[error] ^
Does anyone know how I can update the aforementioned line to be compliant with 0.13.x and still work as expected?
See https://www.scala-sbt.org/0.13/docs/Migrating-from-sbt-012x.html#Migrating+with
Migrating with InputKey
When using InputKey instead of:
run <<= docsRunSetting
when migrating you mustn’t use .value but .evaluated:
run := docsRunSetting.evaluated
In your case try run in Compile := (run in Compile in migrations).evaluated.
I access code in Docker($docker pull mreif/fse2016:evaluation), the code could be compiled and run without errors in remote server. While i download it to local machine, i suffered some errors in compiling(using: sbt compile):
[error] (*:update) sbt.ResolveException: unresolved dependency: de.opal-project#abstract-interpretation-framework_2.11;0.9.0-SNAPSHOT: not
[What i have done] I added follow lines into "build.sbt":
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
[error] evaluation/src/main/scala/org/opalj/evaluation/EntryPointAndCallEdgeCountAnalysis.scala:90: not found:
[What i have done] I added follow lines into "build.sbt":
libraryDependencies += "de.opal-project" % "fixpoint-computations-framework-analyses_2.11" % "0.9.0- SNAPSHOT"
3.[error] /src/main/scala/org/opalj/evaluation/EntryPointAndCallEdgeCountAnalysis.scala:130: not found: value LibraryEntryPointsAnalysis
I have checked the related code, LibraryEntryPointsAnalysis has been actually imported but doesn't work.
Could you please help me to confirm is there any operations i missed for compile the source code?
Thank you very much!
Jiang
The reason why it is not working is a version mismatch of the OPAL framework. The reason why it doesn't find the "LibraryEntryPointAnalysis" is, that it has been renamed.
You have to options:
Use the version of OPAL that is used in the Docker container
make a check out of OPAL at from version tag "ArtifactEvaluationFSE2016"
copy OPAl from the container like you did with the evaluation project
Adapt the Evaluation Project to the new API
the LibraryEntryPointsAnalysis is now called EntryPointAnalysis
there are probably other breaking changes that you have to fix
If you want to go with option one you have to build OPAL on your own because the eval version is not published on maven.
I'm trying to get smaller scalar executable jar file with sbt-proguard.
I added project/plugin.sbt these two lines of code:
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.13.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-proguard" % "0.2.2")
The first one is to get uberjar file, and I could get uberjar with sbt assembly that works fine.
Then, I executed sbt proguard:proguard to get this error message.
[error] Error: Can't read [/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/jre/lib/rt.jar] (Can't process class [apple/applescript/AppleScriptEngine.class] (Unsupported class version number [52.0] (maximum 51.0, Java 1.7)))
java.lang.RuntimeException: Proguard failed with exit code [1]
at scala.sys.package$.error(package.scala:27)
...
at java.lang.Thread.run(Thread.java:745)
[error] (proguard:proguard) Proguard failed with exit code [1]
From the hint from this post: ProGuard says Unsupported class version number [52.0] (maximum 51.0, Java 1.7) with sbt-proguard,
I switched to both Java 1.7 and Java 1.6 with export JAVA_HOME=/usr/libexec/java_home -v '1.6*' command to run proguard to get the slim-lined jar file, but this doesn't run.
Invalid or corrupt jarfile target/scala-2.11/proguard/myproject_2.11-1.0.jar
What might be wrong? These are the lines that are added to build.sbt.
proguardSettings
ProguardKeys.options in Proguard ++= Seq("-dontnote", "-dontwarn", "-ignorewarnings")
ProguardKeys.options in Proguard += ProguardOptions.keepMain("core.HelloWorld")
I believe this is documented in the pro guard docs.
Running your application with java -classpath <jarpath> --class classname <program-arguments> should work.
This happens because pro guard by default removes all MANIFEST files from the jar hence the java runtime cannot find the jar class entries. Another way to do this would be to keep the MANIFEST.md file and run it using the java -jar option but I have never tried that.
Define a recent Proguard version that supports Java 1.8
ProguardKeys.proguardVersion in Proguard := "5.3.3"
Also a couple of useful ones if you run out of mem are
javaOptions in (Proguard, ProguardKeys.proguard) := Seq("-Xmx2G")
javaOptions in (Proguard, ProguardKeys.proguard) += "-Xss1G"
I'm trying to configure metaspace for SBT
export SBT_OPTS="-XX:+CMSClassUnloadingEnabled -XX:MaxMetaspaceSize=512M -XX:MetaspaceSize=256M -Xms2G -Xmx2G"
but when I run sbt -v, I have the following output :
[process_args] java_version = '1.8.0_11'
# Executing command line:
java
-XX:+CMSClassUnloadingEnabled
-XX:MaxMetaspaceSize=512M
-XX:MetaspaceSize=256M
-Xms2G
-Xmx2G
-Xms1024m
-Xmx1024m
-XX:ReservedCodeCacheSize=128m
-XX:MaxMetaspaceSize=256m
-jar
/usr/local/Cellar/sbt/0.13.7/libexec/sbt-launch.jar
The problem seems that my custom value for MaxMetaspaceSize is overrided with another value, as shown in output above.
SBT version : 0.13.7
Java version : 1.8
OS : OSX
(copy-pasted from a dear coworker who found the solution)
sbt -mem 2048
=>
-Xms2048m
-Xmx2048m
-XX:ReservedCodeCacheSize=256m
-XX:MaxMetaspaceSize=512m
the default metaspace is based on the xmx value specified with the "-mem" option ;-)
When using sbt 0.13.6 or higher you can create a .sbtopts file in your project root with:
-J-XX:MaxMetaspaceSize=512M
It seems that memory options are only correctly handled when they are specified in JAVA_OPTS
setting export JAVA_OPTS="-XX:+CMSClassUnloadingEnabled -XX:MaxMetaspaceSize=512M -XX:MetaspaceSize=256M -Xms2G -Xmx2G"
gives
sbt -v
[process_args] java_version = '1.8.0_40'
# Executing command line:
java
-XX:+CMSClassUnloadingEnabled
-XX:MaxMetaspaceSize=512M
-XX:MetaspaceSize=256M
-Xms2G
-Xmx2G
-jar
/usr/local/Cellar/sbt/0.13.8/libexec/sbt-launch.jar
[info] Loading global plugins from /Users/ant/.sbt/0.13/plugins
[info] Set current project to ant (in build file:/Users/ant/)
>
Not sure if it's a bug or a feature
export SBT_OPTS="-XX:MaxMetaspaceSize=512m -Xms1024m -Xmx1024m"
works for me in sbt 0.13.11:
sbt -v
[process_args] java_version = '1.8.0_91'
# Executing command line:
java
-XX:MaxMetaspaceSize=512m
-Xms1024m
-Xmx1024m
-jar
I am trying to compile a project containing some Java 8 source files using lambdas using SBT 0.13.7.
Now, I set
-java-home /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Home
in
/usr/local/etc/sbtopts
And apparently SBT does take this into consideration, because if I supply the wrong path it complains about no java being present.
However, when I try compiling, I get the following
[error] /Users/edafinov/GitRepos/Java8SBTTest/src/main/java/Main.java:10: error: illegal start of expression
[error] new ArrayList<Integer>().stream().filter(i -> i%2 ==0).count();
[error] ^
[error] 1 error
[error] (compile:compile) javac returned nonzero exit code
[error] Total time: 1 s, completed Dec 26, 2014 12:28:55 PM
This seems to indicate that SBT does not use javac 1.8, but rather the 1.7 one which is the default one for my system.
What am I doing wrong?
Thank you in advance
Apparently if you have a JDK in the path, SBT would try to use that one, even when you have explicitly set the -java-home option. I solved my problem by removing the default JDK from $PATH