Is there Kotlin equivalent of scala.io.Source.fromFile()? I want to read a file located in a folder outside the module folder but still under the root project. I used to use Source.fromFile("<path-to-the-file-from-root-project>") in Scala.
Related
I've been using dart projects in order to practice dart programs and wondered why there are two folders bin and lib both can contain dart files.
I did some research about this and they said bin folder is for creating console application but that didn't help me. I don't have a clear idea about console application.
and why should I bother about these folder if I'm only using dart projects just for practicing dart language?
The bin folder is where you put the public entrypoints for your project to compile it to executable binaries for console applications.
If you are just practing dart code, you can leave it there and just use the lib folder. Just make sure you'll have a file inside bin with the same name as the project/package you created (defined in pubspec.yaml) and a main() function, so you can use dart run.
The lib folder is for all the other code you write. You can add in there all your classes files of your project as a additional code to be called by the files from the bin folder. Or you can use just the lib folder to write a package/library for other apps, without needing to have a bin folder.
But the bin folder can have a file for each command, with a main() inside each file.
For example, you could have in it bin/sum.dart and bin/subtract.dart. Then you can compile each to a executable binary (sum.exe and subtract.exe) to use it as a command-line/console program.
To run each file without compiling just use dart run :COMMAND (in the example above, dart run :sum).
If you want to know more about it, see the documentation explaining how to compile and how to write a package that has a command-line tool
I'm following a Udemy course that uses Eclipse for Scala. Using Eclipse, he creates a package, then right-clicks on that package, selects Import, then General, then FileSystem and selects an existing resource that he provides in the course.
I'd like to know how to do this in Intellij. I created a package but see no way to import an existing resource into it.
Many thanks.
You either configure content root in the existing module or add a new module with the source roots, then make your main module depend on it.
IntelliJ IDEA will not copy the files from some other location, so you have two options:
set up a module with the content roots for the existing location with the sources
copy files to the existing module source root using your favorite file manager.
I am trying to convert an existing Maven multi-module project over to use sbt instead. One of the module subdirectories has .scala at the end of its name (because it's a pure Scala implementation of a library that was originally written in Java). Maven had no problem with this. However, sbt sees the .scala and thinks that the directory is a Scala source file and tries to compile it, which fails, of course.
How can I configure sbt so that it doesn't try to compile a directory as a source file? Note that the top-level (root) project doesn't contain any source code itself, so disabling compilation altogether at that level would be an acceptable solution (as long as it doesn't prevent the submodules from being compiled).
Yes, I have considered simply renaming the submodule directory so that it doesn't contain .scala, but I would prefer to avoid restructuring my build tree if possible.
Let's say the name of your directory is ./directory.scala (located in the root of the project). Then this should do the trick:
excludeFilter in Compile := "directory.scala"
I created an Eclipse project and I need to use the Super CSV library with Dozer. I downloaded the Super CSV and created a new folder "super-csv" in /usr/lib.
Now I have: /usr/lib/super-csv/super-csv that contains the super csv jar (+ javadoc and source),
/usr/lib/super-csv/super-csv-dozer that contains the super csv dozer jar, javadoc and source plus a "lib" folder.
Inside /usr/lib/super-csv/super-csv-dozer/lib there are many .jar files that are needed for super-csv-dozer to work, so I added it as native library for super-csv-dozer entry in library tab of java build path in Eclipse.
When I try to compile the project, I receive a java.lang.ClassNotFoundException pointing a class that is contained in one of the jar files in the lib folder.
Everything works only if I manually add every jar in lib folder as an external jar.
Can someone explain me where I am doing wrong?
I'd recommend using Maven - it's a widely used tool for Java builds. To start using Super CSV, it would be as simple as adding the 2 dependencies (listed on the Super CSV website), and your Eclipse project would be ready to go.
There's a bit of a learning curve though, so if you want to just add the jars to Eclipse's build path manually, I'd recommend creating a lib directory at the root of your project and putting all of the jars there.
my-project
|-src
| |- (your source in here)
|
|-lib
|-commons-beanutils-1.8.3.jar
|-commons-lang-2.5.jar
|-commons-logging-1.1.1.jar
|-dozer-5.3.2.jar
|-slf4j-api-1.7.1.jar
|-super-csv-2.0.1.jar
|-super-csv-dozer-2.0.1.jar
You can then add them to the build path (here's a good guide).
Just a note: if you're not using the Dozer extension, then you'll only need super-csv-2.0.1.jar on the build path.
I am using a java jar dependency that requires a certain property file to be on the classpath. I can't for the life of me figure out how to add this folder/file to the classpath. I am using play 2.0.
I have added the config.properties file to both the /conf directory and have tried to add it to the root of my app source folder. The file does not seem to be recognized by the dependency.
BTW: play 2.0 uses sbt to compile and run the application so maybe something there could help?
Any ideas?
You should be fine if you put the property file where your class files are. When you use SBT you probably use either:
The project root directory as source directory. In this case just put your property file into the root directory.
Or the maven layout, so your normal classes are under src/main/scala In this case put your property file under src/main/resources
Although the answer of Jens Schauder should solve your issue, you may want to try to add the file to the lib folder.
Play 2.0 won't remove files manually added in there (at least it doesn't at the time I'm writting this!) and that folder should be included into the classpath automatically.