How to create JARs for inclusion in Play's /lib directory
[Noob question]
I downloaded jBCrypt which contains two files, BCrypt.java and a test file.
I am new to packaging Java, and I know that the /lib directory needs .jar files. I know how to create a class file (javac "java file") and I know how to create a jar (jar cvf "class file").
I don't know if that's the right way, however. How do I correctly package a java file into a jar so Play will know how a开发者_JAVA百科nd where to find the package?
P.S. My workaround is to make a package /playapp/app/bcrypt/BCrypt.java.
The problem with the approaches above is that you will not be able to run play with dependency sync from other repos. I found a solution somewhere on the internet and thought it might be useful to you. The suggestion is also working if you run e.g play run --deps
The following is my suggestion:
1: create a folder to store your local repository e.g jar in the root folder of your play app
2: add the following to your dependencies.yml file:
repositories:
- provided:
type: local
descriptor: "${application.path}/../[module]/conf/dependencies.yml"
artifact: "${application.path}/jar/[module]-[revision].jar"
contains:
- provided -> *
3: Then in the require section add this to the list
require:
- provided -> yourjarfilename 1.0
The above example requires you to name your file like: yourjarfilename-1.0.jar
Play will load automatically any Jars found in the lib folder. You just need to make sure that the folder structure in the Jar matches the package name.
Ie if your class is called com.mycompany.myproject.MyClass
then you should have the following folder structure inside your Jar:
com/mycompany/myproject/MyClass.class
So you will need to get your jar
command to Jar com and all subfolders.
To create a Jar file, follow the Oracle tutorial. An easy way is to create a Java Jar project in your IDE, add the files you want, and let the IDE generate the Jar.
Given that you just want to add 1 or 2 Java files to your project, it can ve acceptable (in this scenario) to just add them to the source of your project.
If you create the Jar I would recommend to add the Jar to some local repository (see here) so you can manage it automatically via Play deps.
精彩评论