I'm new to both Scala and IntelliJ. I've installed Scala plugin for IntelliJ
I've installed Scala in my Ubuntu system with
sudo apt-get install scala
When I try to create new scala project, I'm required to do Scala Settings.
But the problem is I couldn't find the the home directory for my Scala installation.
What is the home directory for Scala in my ubuntu?
Thanks.
The plugin wants to know where the Scala libraries are installed (as it would want to know where the Java SDK is located for a Java module). Note that for different Scala projects you might use different versions of Scala: 2.9.0 or 2.10.2, etc. The dialog offers to download them or you can go to the Scala site and download them yourself. For example, I downloaded scala-2.10.2.tgz from http://www.scala-lang.org/download/ and expanded it in /home/glenn/Applications/Scala/ to
/home/glenn/Applications/Scala/scala-2.10.2/. This latter path is what goes in the "Set Scala Home" field in the dialog.
Note that in my case this is preferable to using the apt-get installation of Scala because the API changes so much that I usually end up with different versions of Scala for different projects that I experiment with.
Follow the version links at http://www.scala-lang.org/download/all.html to the version page with the download for the docs.
Note that for me, IDEA wanted the docs to be in the "doc/scala-devel-docs" directory, whereas the downloaded docs decompressed to "scala-docs-2.10.2". I made a link so that IDEA can find them. My 2.10.2 directory looks like this, now.
scala-2.10.2
├── bin
├── doc
│ ├── scala-devel-docs -> scala-docs-2.10.2
│ ├── scaladoc
│ │ └── lib
│ ├── scala-docs-2.10.2
│ │ └── api
│ └── tools
│ ├── css
│ └── images
├── examples
│ ├── actors
│ ├── monads
│ ├── parsing
│ │ └── lambda
│ ├── tcpoly
│ │ └── monads
│ └── xml
│ └── phonebook
├── lib
├── man
│ └── man1
├── misc
│ └── scala-devel
│ └── plugins
└── src
Run
$ dpkg -L scala
It will show a list of files in that package. Search for scalac:
$ dpkg -L scala | grep scalac
It will be something like /usr/share/scala/bin/scalac. Strip off /bin/scalac part and you will get Scala home: /usr/share/scala.
Update
It seems that there is no dedicated Scala home in Ubuntu. scala-library package files are installed simply to /usr/share/java. I guess then that the most simple way to get proper Scala home is to download a tarball from http://scala-lang.org/, extract it somewhere and use extracted directory as Scala home.
Related
I have a flutter project, and updated it to nullsafety just now. And I found that intl_translation plugin are not support for nullsafety. So I remove it and want to use the intl comes with the framwork of flutter.
According to the official documents, I add 2 lines: intl: ^0.17.0 # , generate: true and new a file named l10n.yaml .
l10n.yaml 's content as follow:
arb-dir: lib/l10n
template-arb-file: intl_en.arb
output-localization-file: lib/generated/intl/l10n.dart
Then my file tree as follow:
lib
├── data
│ ├── ......
├── generated
│ ├── intl
│ │ ├── messages_all.dart
│ │ ├── messages_en.dart
│ │ └── messages_zh.dart
│ └── l10n.dart
├── l10n
│ ├── intl_en.arb
│ └── intl_zh.arb
├── ......
├── ......
├── ui
│ ├── ......
└── utilities.dart
Then I flutter run my project. The ERRORS show that
Invalid ARB resource name "UPCredit" in LocalFile: '.../lib/l10n/intl_en.arb'.
Resources names must be valid Dart method names: they have to be camel case, cannot start with a number or underscore, and cannot contain non-alphanumeric characters.
Generating synthetic localizations package has failed.
The error position is in my intl_en.arb as follows:
"UPxxt": "Uxxx Cxxxit",
"UPxit": "Unxxx Dxxxt",
"UPSxit": "Uxxx Sxxxed xxxit",
MY PROBLEM:
NoBody talk me not to do like this(Maybe I can not find something about it). Can anybody help me about how to solve it? Something about document(how to find this?).
Basically, the means exactly camelCase this kind of naming convention to be used hence you'll need to stick with upCredit instead of UpCredit.
I have a project that uses akka in version 2.11_2.5.21 which is assembly in my fat jar.
I have download the scala binary 2.11.12 and it is shipped with a lib/akka-actor_2.11-2.3.16.jar (next to bin/scala)
When I run my project : scala -cp target/scala-2.11/project-assembly-2.4.0.jar foo.MyClass I get
java.lang.NoSuchMethodError: akka.actor.OneForOneStrategy.withMaxNrOfRetries(I)Lakka/actor/OneForOneStrategy;
If i remove lib/akka-actor_2.11-2.3.16.jar in my scala directory it works.
Of course it also works with sbt run as sbt used its own scala version.
Why does scala binary use its own akka version instead of the one shipped in the fat jar?
Assuming by "Scala binary" you are referring to the decompressed structure of say https://downloads.lightbend.com/scala/2.11.12/scala-2.11.12.tgz
➜ scala-2.11.12 tree -L 2
.
├── bin
│ ├── fsc
│ ├── fsc.bat
│ ├── scala
│ ├── scala.bat
│ ├── scalac
│ ├── scalac.bat
│ ├── scaladoc
│ ├── scaladoc.bat
│ ├── scalap
│ └── scalap.bat
├── doc
│ ├── LICENSE.md
│ ├── License.rtf
│ ├── README
│ ├── licenses
│ └── tools
├── lib
│ ├── akka-actor_2.11-2.3.16.jar
│ ├── config-1.2.1.jar
│ ├── jline-2.14.3.jar
│ ├── scala-actors-2.11.0.jar
│ ├── scala-actors-migration_2.11-1.1.0.jar
│ ├── scala-compiler.jar
│ ├── scala-continuations-library_2.11-1.0.2.jar
│ ├── scala-continuations-plugin_2.11.12-1.0.2.jar
│ ├── scala-library.jar
│ ├── scala-parser-combinators_2.11-1.0.4.jar
│ ├── scala-reflect.jar
│ ├── scala-swing_2.11-1.0.2.jar
│ ├── scala-xml_2.11-1.0.5.jar
│ └── scalap-2.11.12.jar
└── man
└── man1
then everything inside lib/ will take precedence over what you specify with -cp. To see this analyse the following snippet of bin/scala runner script
execCommand \
"${JAVACMD:=java}" \
$JAVA_OPTS \
"${java_args[#]}" \
"${classpath_args[#]}" \
-Dscala.home="$SCALA_HOME" \
$OVERRIDE_USEJAVACP \
"$EMACS_OPT" \
$WINDOWS_OPT \
scala.tools.nsc.MainGenericRunner "$#"
Note that "${classpath_args[#]}" which holds jars from lib precedes the last "$#" which holds your arguments such as -cp. Finally JVM will pick the first matching class it finds on the classpath which in your case will be the one from lib/akka-actor_2.11-2.3.16.jar. For example
scala -cp target/scala-2.11/project-assembly-2.4.0.jar
would expand to something like
java -Xbootclasspath/a:/scala-2.11.12/lib/akka-actor_2.11-2.3.16.jar ... scala.tools.nsc.MainGenericRunner -cp target/scala-2.11/project-assembly-2.4.0.jar
hence Xbootclasspath would take precedence over -cp.
I have downloaded a rpm in my ansible-playbook:
(djangoenv)~/P/c/apache-installer ❯❯❯ tree .
.
├── defaults
│ └── main.yml
├── files
│ ├── apache2latest.tar
│ ├── httpd_final.conf
│ ├── httpd_temp.conf
│ └── sshpass-1.05-9.1.i686.rpm
├── handlers
│ └── main.yml
├── hosts
├── meta
│ └── main.yml
├── README.md
├── tasks
│ └── main.yml
├── templates
├── tests
│ ├── inventory
│ └── test.yml
└── vars
└── main.yml
My question is why can't I just install it using:
- yum: name=files/sshpass-1.05-9.1.i686.rpm
? It complains that files/sshpass-1.05-9.1.i686.rpm is not found in the system. Now I am doing it in two steps:
- copy: src=files/sshpass-1.05-9.1.i686.rpm dest=/tmp/sshpass-1.05-9.1.i686.rpm force=no
- yum: name=/tmp/sshpass-1.05-9.1.i686.rpm state=present
No, there is no simple way around coping the package to the remote host before installing. Ansible yum module expects a local file when you define a file in the name parameter.
IMHO it is not a good idea to keep packages inside the Ansible code base. Because they are binary and not exactly part of the actual Ansible code. It would be cleaner to setup a private repository and store those files there. That is the only way around coping a package in this situation I'm aware of.
I'm using Eclipse Mars, and I have a Maven application using build-helper-maven-plugin, that is not covered by m2e by default, so I need to add a connector. The point is, I can add the connector when importing the maven project:
However, I have no idea how I would do this manually, when the project is already in the workspace. The pom have an error, Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:build-helper-maven-plugin:1.10:add-source, but I can't find the option install m2e connector or something like that.
The P2 Update site is here:
https://repo1.maven.org/maven2/.m2e/connectors/m2eclipse-buildhelper/0.15.0/N/0.15.0.201207090124/
This answer helped me to discover how Eclipse knows it.
There is a Catalog that can be opened from the preferences:
You can follow the link manually: http://download.eclipse.org/technology/m2e/discovery/directory-1.8.xml
If you download the org.eclipse.m2e.discovery.oss-catalog-1.6.jar referenced as entry and you unzip it, the you will find a plugin.xml file:
org.eclipse.m2e.discovery.oss-catalog-1.6
├── META-INF
│ └── MANIFEST.MF
├── images
│ ├── extras-48.png
│ └── scm-32.png
├── lifecycle
│ ├── com.coderplus.m2e.jaxws.feature.group.pluginxml
│ ├── com.coderplus.m2e.jaxws.feature.group.xml
│ ├── ..
│ ├── org.eclipse.m2e.discovery.lifecycles.tycho.pluginxml
│ ├── org.eclipse.m2e.discovery.lifecycles.tycho.xml
│ ├── org.maven.ide.eclipse.ajdt.pluginxml
│ └── org.maven.ide.eclipse.ajdt.xml
└── plugin.xml
And this file contains the information with the P2 Update site:
<connectorDescriptor siteUrl="http://repo1.maven.org/maven2/.m2e/connectors/m2eclipse-buildhelper/0.15.0/N/0.15.0.201207090124/" id="org.eclipse.m2e.discovery.lifecyclemapping.buildhelper" groupId="lifecycles" description="buildhelper" categoryId="org.eclipse.m2e.discovery.category.lifecycles" name="buildhelper" provider="Takari, Inc." license="EPL" kind="lifecycles">
<iu id="org.sonatype.m2e.buildhelper.feature.feature.group" />
<overview summary="buildhelper" />
</connectorDescriptor>
I've been using Gradle for most of my Scala projects, but I want to evaluate the suitability of SBT as a replacement. One of the things I've done in Gradle is to exclude a certain resource directory from the final build (for example, using CoffeeScript to write JavaScript files that will be included as final resources).
In Gradle, I'd do this by:
sourceSets {
main {
resources {
exclude 'com/example/export/dev' // exclude development resources
}
}
}
And this would exclude the resource package com.example.export.dev package from the final build.
How would I do the same in SBT? I've tried
unmanagedResourceDirectories in Compile -= (resourceDirectory in Compile).value / "com/example/export/dev"
but that doesn't do a thing (I understand why, but that doesn't really help). And the documentation on the SBT web site only talks about excluding file patterns (at Classpaths, sources, and resources).
As a more descriptive image, say we have the following resource directory structure:
com
\---example
\---export
\---dev
\---something
In the final output, I want:
com
\---example
\---export
\---something
The way to think in SBT is a bit different and I know it can be hard at first.
In your example, you need to modify the task that generate the resource files (or the task that selects the folders to look for resource files).
Here is an example of how I can select only the resource files that start with character 'a'.
(unmanagedResources in Compile) := (unmanagedResources in Compile).value.filter(_.getName.startsWith("a"))
Similarly if you want to modify the entire directory of the resource files you can do that like this:
(unmanagedResourceDirectories in Compile) := (unmanagedResourceDirectories in Compile).value.filter(_.getName.startsWith("a"))
Obviously my filters here are just and example, you can have any complex pattern that Scala supports.
The nice thing about SBT is that it's interactive. So you can check the result of your task by simply typing these at the REPL of your project:
> show compile:unmanagedResources
> show compile: unmanagedResourceDirectories
To check all the dependencies to the task do this from the REPL:
> inspect tree compile:unmanagedResources
Assumption:
SBT knows where to find all resources using the standard maven build directory layout. The above solution assumes that all resources are under the /resources directory. You can then access them from your Scala code using getClass.getResource("/folderInsideResources/file.txt").
Here is a sample directory layout for a mixed Java/Scala project with resources:
.
├── main
│ ├── java
│ │ └── com
│ │ └── a
│ │ └── b
│ │ └── Hello.java
│ ├── resources
│ │ ├── a.tx
│ │ └── b.tx
│ └── scala
│ └── com
│ └── a
│ └── b
│ └── ScalaHello.scala
└── test
├── resources
└── scala
└── com
└── a
└── b
└── ScalaHello.scala
To access the resource file just use:
getClass.getResource("/a.txt")
getClass.getResource("/b.txt")
From https://github.com/sbt/sbt-jshint/issues/14:
excludeFilter in unmanagedResources := {
val public = ((resourceDirectory in Compile).value / "com" / "example" / "export" / "dev").getCanonicalPath
new SimpleFileFilter(_.getCanonicalPath startsWith public)
}