Use javascript in Scala.js compiled jars - scala

I have a Scala.js jar, foo_sjs0.6_2.11-0.1-SNAPSHOT.jar, which contains javascript for my web server, and a separated Play project for controlers/views/etc.
Is there any way to compile and load .js files at runtime when I run the Play project, given it has foo_sjs0.6_2.11-0.1-SNAPSHOT.jar as a dependency?
P/S: I'm well aware of Play-Scala.js multi-project settings https://github.com/vmunier/play-with-scalajs-example, and I don't want that.

It's possible. You just have to use the Scala.js Tools API programmatically to link the .sjsir files in the jars into a .js file. Look at how the CLI linker does it for inspiration.

Related

outside lib in GitHub

I just recently used Github, and when I was trying to upload my java project I realized that I was using some external libraries like apahce poi in this project, and these files have to be stored in libs for my application to function, do I need to upload these files because I realize that might violate some issues(maybe ?).
If yes, then what is the correct way to upload or maybe just post a link to those dependency
Use a tool that provides a dependency management system such as Maven or Gradle (these are both common choices in the Java ecosystem). Your project will then include a configuration file that Maven or Gradle will use to download dependencies so you don't need to distribute them with your project.

how to keep jar dependancy while checking in code

I have a scala project built with dependancy on a locally built jar file (java code). Once I need to check in my scala code into a different environment for building and deployment, what's the best way to keep my jar file in the dependancy?
I know that if I use the sbt dependancy from online modules, I don't need to worry, it will download the version and build, but what if I want to use my own jar file for this purpose?
This is in OSX, and code will be checked into linux machines, I am using intellij and sbt to manage my scala project. I also used intellij to build my external java lib into jar file and added dependancy of this specific path.
I hope there should be some generic solution, but I am new in JAVA and SBT
I got it figured out. Add the jar files under the lib directory right under the project will solve the problem. SBT will pick it up automatically and you can certainly check in the jar files like source code.

Generate a JAR from one Scala source file

I have no Scala experience, but I need to create a JAR to include on a project's classpath from a single Scala source file.
I'm thinking there is a relatively straightforward way to do this, but I can't seem to figure it out.
The Scala file is here: http://pastebin.com/MYqjNkac
The JAR doesn't need to be executable, it just needs to be able to be referenced from another program.
The most convenient way is to use some build tool like Sbt or Maven. For maven there is the maven-scala-plugin plugin, and for Sbt here is a tutorial.
If you don't want to use any build tool, you may want to compile the code with scalac and then create the jar file manually by using zip on the resulting class files and renaming it to jar. But you have to preserve the directory structure. In your pastebin you use the package org.apache.spark.examples.pythonconverters, so make sure the directories match.
Btw, if you want to just integrate this piece of code with your java project, and using maven, you can have the scala code in your 1 project as well (in src/main/scala). Just use the maven-scala-plugin plugin and hook it to the compile phase, or some sooner phase if your Java code depends on it. However, I don't recommend mixing multiple languages in one project, I would split it into two separate ones.

scala generating jar file from scala-io to include in eclipse

I am trying to use the library scala-io in my Eclipse environment, does anyone know how do I generate a jar file, or which folder to include in my eclipse so that I can have access to the scala-io library from my project ?
EDIT:
Q: How to incorporate an external library into scala IDE?
A: Two possibilities:
Leverage SBT to build your project; that is generating jar files and maintaining dependency
Including the generted jar files directory in the IDE, project -> Properties -> Java build paths.
hth.
EDIT #2:
I found this great plugin to generate all of your dependencies in one jar file sbt-assembly
http://jesseeichar.github.io/scala-io-doc/0.4.2/index.html#!/getting-started
shows how to start with sbt or maven or with prebuild jars provided by links.
You should try to get familiar with a build system like sbt. Its cumbersome to always manually add dependencies to eclipse, especially if you have dependency chains: scala-io needs scala-io-core and arm and file etc...

How to create a java project as a jar for GWT

I'm wanting to use some java code as a reusable component jar in my GWT 2.4 application.
I need access to that code on the client side, so I've read that the steps involved are to
add an entry in the main projects gwt.xml file pointing to this project,
include a gwt.xml file in the jar
and put the java code under a client folder.
I assume that this has to be a gwt project itself, otherwise there would be no need to add the inherits entry or is it not possible to use a regular java project client-side?
Is there anything else I need to do for this (other than ensure the libraries in the jar fall under the JRE Emulation Reference list)?
We don't use the plugin functionality in Eclipse, but to use another project in your GWT project all you need to do is define a .gwt.xml module file in your project that you want to use in your GWT project and reference that module file with <inherits.../> in your main GWT project. You will also obviously need to add that project as a reference in the build path in Eclipse, so you don't get compilation errors. And all of that is besides the fact that your referenced project has to comply to the JRE emulation reference so it can be fully GWT compilable.