Add a scala file into parent package - scala

I am in this situation:
The package "vu.co.kaiyin.clipboard" has been created and has a package object in it. Now I want to add a new scala file in the package "vu.co.kaiyin". How can I do that?

Do it on scala folder. Just add vu.co.kaiyin.new_package there - putting all path.

Related

Error: Could not resolve the package 'app' in 'package:app/app_controller.dart

In my last flutter project, I included files placed in my lib/ directory by using import 'package:app/file_name.dart'.
For example, my file located at lib/app_controller.dart was imported via:
import 'package:app/app_controller.dart'
I just started a new flutter project, and it is giving me the error:
Error: Could not resolve the package 'app' in 'package:app/app_controller.dart'
When I remove the portion package:app/, it builds fine. I find this very strange because my previous project is still building just fine without any changes. Does anyone know what's happening here?
What is allowing my old project to respect package:app/..., but not my new project?
package:app/ would work only for an application that is called app. What is the name of your new application? When you import items from your own project, it goes like this:
package:{{YOUR APPLICATION NAME}}/{{DIRECTORIES}}
What is the name in your pubspec.yaml file? It's usually on the very first line.
it is because a dart class can be imported in two ways(AFAIK),
local import from the root of current file where import is being used for example import '../folder/file.dart
with a package name which should begin from package for example import package:packagename/any_file_in_the_lib_folder.dart, a package will have a pubspec.yml which defines a package name which will be used to import the content of the lib folder of that package, in your case your first project is named app so it respected this import style but your second project isn't respecting it because its not named app but something else.

Get relative path from inside a scala library (while developing that library)

I'm currently developing a scala library and wanted to get a file that is inside it, event when compiled as a Jar dependency. The problem is that when executed from another project where the library is imported, the path is relative to that project. Here is the code to get the file :
private val pathToDocker: Path = Paths.get("src", "main", "resources", "docker-compose")
What can I do to look for my file inside the imported dependency ?
The file won't be in a file system -- it'll be in the compiled JAR.
You can get a JAR resource using a class loader. Here's an example of how to do that in another codebase.
Utility function:
https://github.com/hail-is/hail/blob/6db198ae06/hail/src/main/scala/is/hail/utils/package.scala#L468
Usage to load version info:
https://github.com/hail-is/hail/blob/6db198ae06/hail/src/main/scala/is/hail/package.scala#L21
There is a JarUtil - from an answer of access-file-in-jar-file translate to Scala:
import java.util.jar.JarFile
val jar = new JarFile("path_to_jar/shapeless_2.12-2.3.3.jar")
val entry = jar.getEntry("shapeless/Annotation.class")
val inStream = jar.getInputStream(entry)
As you mentioned scala.io.Source.fromResource works only within your project:
Source.fromResource("tstdir/source.txt")
Make sure the file is in the resources directory, like:
The way I found to achieve getting the path inside a jar depedency was creating a singleton (scala object) that has a method that loads the files. Since it is inside the Jar, the resulting path is relative to the jar itself. Here is the code :
object ClassLoaderTest {
def dockerFile: File =
new File(getClass.getClassLoader.getResource("docker/docker-compose.yml").getPath)
}
When called from a Trait (or an interface), the resulting path is :
jar:file:/home/myname/.ivy2/cache/com.mypackage/libraryname/jars/libraryname.libraryversion.jar!/docker/docker-compose.yml

Can't import the Svg library in elm?

Trying to use Svg and Svg.Attributes. Getting the error message
I cannot find module 'Svg'.
Module 'Main' is trying to import it.
Potential problems could be:
* Mispelled the module name
* Need to add a source directory or new dependency to elm-package.json
I'm certain that there aren't any spelling errors because I copy and pasted the imports from a tutorial. Where do I install this library?
The tutorial I'm going through is the one elm-lang.org, specifically the section on time.
You need the elm-lang/svg package as a dependency in your elm-package.json. Run elm package install elm-lang/svg in the project directory.

Expose a package object's declarations to subpackages in Scala

I have the following packages hierarchy:
rootpackage
---firstpackage
---secondpackage
rootpackage contains a package object.
I know that if a file from firstpackage has package declaration in the form:
package rootpackage.firstpackage
the content of rootpackage package object will not be in the file scope, but with the following declaration it will:
package rootpackage
package firstpackage
How this strange difference is explained? And is there more transparent way to expose the package object's content to subpackages, like importing rootpackage package object content to firstpackage one?
Package object members can be imported in the following way:
import rootpackage.SomeMember

Create a package in dart

How do I create a package in the new Dart Editor?
There is no "Add Pub support" checkbox?
Also how to create "packages" with the new editor?
Is a tutorial out there that describes the process with the new Editor?
To create a package named mypackage.
For Dart package:
dart create --template=package-simple mypackage
For Flutter package:
flutter create --template=package mypackage
From the Dart/Flutter Documentation:
Step 1: Create the package
To create a Flutter package, use the --template=package flag with flutter create:
flutter create --template=package hello
This creates a package project in the hello folder with the following content:
LICENSE
A (mostly) empty license text file.
test/hello_test.dart
The unit tests for the package.
hello.iml
A configuration file used by the IntelliJ IDEs.
.gitignore
A hidden file that tells Git which files or folders to ignore in a project.
.metadata
A hidden file used by IDEs to track the properties of the Flutter project.
pubspec.yaml
A yaml file containing metadata that specifies the package’s dependencies. Used by the pub tool.
README.md
A starter markdown file that briefly describes the package’s purpose.
lib/hello.dart
A starter app containing Dart code for the package.
.idea/modules.xml, .idea/modules.xml, .idea/workspace.xml**
A hidden folder containing configuration files for the IntelliJ IDEs.
CHANGELOG.md
A (mostly) empty markdown file for tracking version changes to the package.
There's no such possibilty in the Dart Editor for now. To create a package follow these steps :
create an New Application mylib without sample content
add a pubspec.yaml file
add a lib folder
create a mylib.dart containing the code you want to package
See the Package layout conventions for more informations.
You can create a dart project following the flutter way that allow you to auto generate the structure and the hierarchy of the package.
Follow below steps to create a package in DART:
Step 1: Create the package
$ flutter create --template=package hello
Step 2: Implement the package
For pure Dart packages, simply add the functionality inside the main lib/.dart file, or in several files in the lib directory.
To test the package, add unit tests in a test directory.
For additional details on how to organize the package contents, see the Dart library package documentation:
https://flutter.dev/docs/development/packages-and-plugins/developing-packages
Any dart app is a package. To create a new Dart app use:
dart create my_package