Package mysql-connector jar along with my project - executable-jar

I have a simple JDBC project that fetches data from a database. I have used mysql-connector-java-5.1.12.jar for jdbc connection.
Now I want to create an executable jar of my project from command line (not from eclipse).
I tried using :
jar cfe myJar.jar com/demo/MySqlJDBC com/demo/MySqlJDBC.class
The jar was created, but it doesn't contain mysql-connector jar and so when I run the jar as:
java -jar myJar.jar
I get error like:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
So, my question is how can I pack the mysql-cnnector-jar while creating jar of my project without using maven and eclipse (just from command line)

Related

leiningen uberjar - add external jar at runtime

I am trying to see how I can add a directory and an external jar to the classpath when making a leiningen uberjar.
The reason is that I need to distribute a jar but some dependencies (jdbc driver for example) cannot be compiled into the uberjar due to licencing restrictions.
I would also like to provide certain external resources such as properties for logging and configuration external to the jar.
Normally in java or spring boot I would use the appropriate command line option to change the classpath. However -cp does not find the jar etc
Is there a way to do this or an appropriate plugin?
Thanks in advance
You can add the jar as a resource in the :dev profile. Then it is added to the classpath. The dev profile is for the local development and not packaged into the uberjar.
:profiles {
:uberjar {:aot :all}
:dev {:resource-paths ["no-redist/commercial-jdbc-driver.jar"]}}
At 'production' time with the uberjar you need set the classpath then manually:
java -cp no-redist/commercial-jdbc-driver.jar;your-app-uber-jar.jar main.namespace
Afaik when using the -jar flag, it uses the dependencies in the jar file, whatever is linked and referred to in there. Combining -cp and -jar might not work.
Another way is to refer to the no-distributable jar file in the jar manifest (META-INF/MANIFEST.MF):
Class-Path: no-redist/commercial-jdbc-driver.jar
The the java -jar your-app-uber-jar.jar would look for the jar in the folder no-redist/commercial-jdbc-driver.jar in the local directory. Add this in leinigen like:
:manifest {"Class-Path" "no-redist/commercial-jdbc-driver.jar"}

lein uberjar doesn't pack the jar file under resource into the final jar

I defined :resource-paths in profile.clj to include some special jar (vertica jdbc) file. and then I run lein uberjar: trying to pack that jar file into the standalone jar file, but after I run it, and uncompressed it, I can't find that vertica jdbc file.
Leiningen can create jar files, but the only place it picks them up from is your maven repository (under an .m2 directory on your machine). Once your special jar is in maven you need to refer to it as a dependency in your project.clj file.
If your jar file was in clojars this would be quite easy - just put in a dependency - lein will fetch it into your maven repository. On the other hand if it was your own source code you would first need to lein install from the directory of that source code project.
However I'm guessing your file is just a jar file you have, which is not an artifact in clojars. In this case you can install it into your maven repository using this maven command (here assuming my-deps.jar is your file):
mvn install:install-file -Dfile=./my-deps.jar -DgroupId=my-deps -DartifactId=my-deps -Dversion=1.0.0 -Dpackaging=jar
You can then refer to it as a dependency in the uberjar project, and then lein uberjar.
Edit - if you don't want to use raw maven commands then consider using this leiningen library that abstracts them away for you: https://github.com/kumarshantanu/lein-localrepo.
An alternative is to add to project.clj:
:repositories {"local" "file:lib"}
Create a lib directory in your project and add the jar there.
Add the lib reference in the :dependencies tag in project.clj.
This lib directory has the same structure as .m2/repository but is inside your project and local to your project

WSO2 Carbon Identity Server - Build and run

I've modified a .jsp file in the org.wso2.carbon.identity.entitlement.ui package, in order to customize the server for my purposes.
The problem is that when I build the project with Eclipse, the build is successful, but I don't understand how I can actually run the compiled code. How can I do it?
Once you build the project with maven, in the target directory you will find the jar (OSGi bundle). In your IS Server under /repository/component/patches, create a new directory something similar to "patch0100". Copy the jar inside this "patch0100" directory and restart the IS server.
The number in the patch directory (0100 in this case) is important. If you put the same jar to a patch directory with a higher number, say pactch0200, that particular jar with override the earlier one. That's how patching works in WSO2 Carobon Server, which is the platform on which the products are built.

Jetty runner is not executing the war file

I have a project named as test using spring,hibernate and struts.It is running when am using eclipse.But when i export this project as war and execute it using jetty runner in command prompt it just extracted the project and listed the contents in the browser.But i want the project to be executed.I have tried with some other simple web application war using the same procedure and it works fine.But in my project its not working with jetty.
here is my code for jetty
D:\>java -jar jetty-runner-7.0.0.v20091005.jar test.war
i just listing some console output of jetty
INFO::RUNNER
NO tx manager found
deploying file:D:/test.war #/[webAppContext#86f241#86f241/,null,file:D:/test.war
can any one tell me a solution for my problem
1) use a newer version of runner, 7.6.3.v20120416
2) what context are you trying to navigate to, you might want to experiment with some of the other cli options on the runner to set the context and whatnot from the command line and experiment with that. This site has some good information on using this artifact as well.

deploying scalatra onto Jetty

How does one deploy scala or scalatra onto Jetty servlet container? Does anyone have experience or can point me to some resources online?
If you're using sbt, run the package command from within the sbt shell. This will create you a war file in the target dir. You can drop that into jetty's webapps directory and configure a context xml file in its contexts directory.
If you're using maven, I believe the command you want is mvn package.
Are you using Simple Build Tool (SBT) for your project? If you do, it's as easy as running "sbt jetty"
Check it out: http://code.google.com/p/simple-build-tool/