How to add lib with jars to shared folder? - scala.js

I have a cross building scala-js project with a client, server and shared folder. If I add a lib folder with some jars in the server project folder I can reference the classes in the jars in my server code. But if add the lib folder in the shared project folder I can't reference the classes in my shared code. Can I add some command in my sbt build file to get my jars visible in my shared project or what should I do?

.jars should never be shared, since it is not the same .jar for Scala/JVM and Scala.js, even if they have the same source code.
If you have the two .jars for JVM and JS, you can put them in shared/jvm/lib/ and shared/js/lib/, respectively.
(if you use .crossType(CrossType.Pure), use .jvm/.js instead of jvm/js)

Related

java reference libraries while copying and importing projects

A java project is created and external libraries are added to it while the location of those external jars are within the same project inside a folder which i created.
So when i copy the project to pendrive and import it to another system(say my friends pc's eclipse) the JRE system libraries and reference libraries are not copied along with it and I have to add them manually.
is there a way that those libraries also can be copied, so next time i just copy the project to pendrive and import to another device and start using it rightaway without adding them again?
Don't add them as External JARs, just add them as JARs. Then, set the project's JRE system library using one of the "Execution Environment" values. This will act as a small abstraction and make the reference portable across machines.

How to access external libraries using Play Framework?

I'm trying to use an external library contained in a .jar file with the Play Framework.
I've added the .jar file to the lib/ directory, to no avail.
I know I could add the dependency to my project/Build.scala file, but I have no idea what the group ID, artifact ID, or version numbers are. Are those found in the .jar file?
You can go to Project Structure
Under Project Setting -> Modules ->
Go to tab Dependencies , under sbt-unmanaged-jars you can edit and add your lib manually.
groupID, artifactID and version are “Maven Coordinates”. These three identifies are needed to find exact jar file in the Maven Repository. When provided, the build system (and Play! uses SBT) can automatically find, download and include the library you want to use (assuming that that library exists in the repository).
As that is a global repository, groupID should uniquely identify the project. groupID is usually the same as the main project's package, e.g. org.apache.commons. artifactID is supposed to identify a particular jar in the project, e.g. commons-io. version, quite obviously, points to the exact version of the jar.
How to use IntelliJ with Play Framework and Scala
see this short tutorial.
but you have to add all necessary jars to lib folder before call create module command idea with-sources=yes
So, again
Create a new application
Create lib folder and copy all jars
Create the IDE module
This is only one way how I can deploy it successfully

Eclipse build path: library with native library folder

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.

Can I add predefined jars to WEB-INF/lib in Eclipse project?

When I am designing normal Java project in Eclipse, I can add predefined libraries to it's Build Path. Can I do the same way when putting jars into WEB-INF/lib folder of Web project? I.e. can I ask Eclipse to put some predefined library jars there?
Just copy / import a Jar there; it will be added to the build path automatically. You will find it in the package explorer within the Web App Libraries (or in the build path in the project properties). The project has to have the Dynamic Web App nature.
This is what I did. I copied the jar files into my WEB-INF/lib folder. Then, I added these jars into my build path using: Properties -> Java Build Path -> Add Jars -> Select the jars from the WEB-INF/lib folder.

Using java library in eclipse

I'm a bit new to eclipse and want to use the following libraries so that I can use their implemented objects (HttpClient and Java csv). How do I import these libraries so that I can write some java with them?
http://hc.apache.org/downloads.cgi
http://sourceforge.net/projects/javacsv/
What you're looking to do is add the libraries to your project's build path (the class path that will be used while compiling). In Eclipse, you can do this by right-clicking your project and choosing Properties (or hitting [Alt]+[Enter] when the project is selected in Project Explorer, Navigator or Package Explorer views) and then Java Build Path from the sidebar and the Libraries tab where you can add JARs.
Note the difference between Add JARs and External JARs is that External JARs will add an external dependency in your project since the absolute path to the JAR on your filesystem will be put into your project's configuration. With Add JARs you can select JARs from within your workspace.
I find it to be a good practice to create a lib folder (at the same level as my src folder) and put all my JARs in there and then add them to the build path with the Add JARs option. This makes the project portable since there are only relative paths referring to resources within the project rather than absolute paths or resources from other workspace projects.
You add the .jar files you want to use in your projects build path. You access this windows by right-clicking your project. Choosing "Build path" -> "Configure build path".