Changing the classpath order in play framework - java

Some time back, I had written a library in java-play.
I wanted to re-use this library, so I added in my sbt dependencies.
But the problem is, I had to modify a couple of files and I don't have source files (only jar).
So I have created classes with same class name and package name and added it to my new project.
But when I run my project, it still picks up my old file.
If it was Java world, I would have modified my classpath file and everything would have been fine, but this is play framework.
When I looked more into this issue, I landed at this.
A play application classpath is built as follows (in this order):
The /conf directory for the application The
$PLAY_PATH/framework/play.jar All jar files found in your application
/lib directory All jar files found in the $PLAY_PATH/framework/lib
directory
Is there a way to change the classpath, so that it picks my file first and then the libraries?

Related

How to modify a file contained in a JAR that is a dependency in IntelliJ

I am working with Scala in Intellij-Idea, and have run into a problem. I have included the Java tag in case someone with Java experience can also answer my question.
In my .ivy2/cache folder for a certain dependency I am working with, there are two jar files. One contains .class files and one contains .scala source files. I want to be able to modify one of the jars, drop it in my lib folder, then run my program with the jar that includes my changes.
I have an issue though. I can modify the file in the source folder with jar uvf, but when I drop it in lib, and run it, the changes don't show up. I have tried commenting out the dependency in my build.sbt file, but it appears to still be using my old dependency even after I run sbt update.
My question can be divided into several parts:
1) Can I just drop a jar file containing only .scala files in the lib folder and expect it to run?
2) To remove the dependency, is commenting out the line in my build.sbt file and then running sbt update enough?
3) Let us say that the only way to run the jar file as a dependency is to use a jar file containing .class files. How do I rebuild the jar with .class files using the .scala files if I don't have any of the other project files, like the build.sbt file? I have the source files, but I am not sure how to use it to recreate the jar without all the other information that usually comes packaged in a Scala project.
I use Intellij only to edit my files, and use sbt to run the code.
1) Can I just drop a jar file containing only .scala files in the lib folder and expect it to run?
That's not possible because the jar file is expected to contain class files, scala files will be handled as resources instead of source files.
2) To remove the dependency, is commenting out the line in my build.sbt file and then running sbt update enough?
I would run sbt clean instead, I haven't tried but sbt "show unmanagedBase" is supposed to list you the library if it was actually picked.
3) Let us say that the only way to run the jar file as a dependency is to use a jar file containing .class files. How do I rebuild the jar with .class files using the .scala files if I don't have any of the other project files, like the build.sbt file? I have the source files, but I am not sure how to use it to recreate the jar without all the other information that usually comes packaged in a Scala project.
The ideal way would be to find the complete repository for that source, update the source and run sbt publishLocal, if that's not possible, another way would be to reconstruct the build.sbt and keep adding libraries until the library compiles properly, hopefully, it will have no dependencies, or a few only.

How to package java libraries that will automatically work when jar file is distributed to another computer?

I've created an application which has a few external libraries, i am trying to distribute to another machine. I want the application to work from just the .jar file.
I know its something to do with the 'Resolve Project Problems', is there a way to prevent this when distributing to another machine
I have already tried adding a library to the distribution folder, it carries over but doesn't do anything with it
Run the application on a new machine without having to 'Resolve project problems' through net beans
You will need to Create a FAT jar
Two Useful links which helped me where
How to include jars in lib into project jar file in Netbeans?
https://dzone.com/articles/java-chronicle-bytes-kicking-the-tires
This didn't entirely fix the issue, i was using a dynamic file string with in my program
I copied the data folder from my application and pasted it in the store folder and rebuilt and also repackaged the fat jar. This made it work

exporting java app as jar which contains other libraries

I have exported my simple java application as normal jar file which contains all the source file and the dependent libraries ie jar files.
Here all the jars I have kept inside the lib folder of my application.
so these things I am able to do but when I am accessing my application as a jar file in other application then I am getting ClassNotFoundException because whatever libraries I have added inside the First application (which I have exported as jar contains all the dependent libraries) are not visible in runtime.
I think I need to give this information about the dependent libraries in MANIFEST.MF file of first application.
but I don't know whether I am thinking right or wrong.
I don't know how to write the MANIFEST.MF file and what would be the directory structure of the of my application if I want to keep the MANIFEST.MF file in my application.
Here for example I have created one jdbc application to create Connection object for that I had to add the ojdbc14.jar in the classpath of my application so for that I have created one lib folder inside the project root directory and I kept that ojdbc14.jar inside that lib folder and then I build the path.
then I exported this application as simple jar which contains that ojdbc14.jar also then I added this jar in my other application but while running my second application I am getting ClassNotFoundException.
Please Help Me On It.

How to create Jar file with external folders and Jars

I made a simple standard-lone java Application using Spring,Apache Camel,Activemq for processing messages.
Note: My Application don't have any GUI.
My project structure is in the following way.
SACLib folder have nearly 70 external jars(all Spring,Camel and Activemq corresponding jars).
It's working fine in Eclipse. SO Now We want to deploy into Jar file.I tried in Eclipse,But I didn't seen Rod1,Rod2,Copy1 and SACLib folders in my Jarfile.
after Deploying Jar, If I run FirstConsumer.java it runs Rod1-->ThMapInfratab1-2.exe file. For this I mention Real paths of .exe file.
How can I make Jar file with including all my folders.
Thanks
Well, this is a kind of work that is typically done with build automation tools like Apache Ant, Maven or Gradle, so you can investigate there if you want to make this happen automatically next time.
But, if you want to do it manually...
First, you project needs a META-INF folder where you will place a file called a MANIFEST.
That manifest contains a Main-Class entry pointing to you main class. You can read about this in the Java Tutorial: Setting Application's Entry Point.
But it can also contain a Class-Path entry, pointing to all other jars required by your application and that should be loaded by the executable jar.
You can read about it the Java Tutorial: Adding Classes to your Jar Class Path.
If you are building your executable jar with Eclipse, it will let you choose the MANIFEST file that you want to use during the creation process.
Now, if you want to use build automation tools, there are other answers here that explain how to do it:
Creating a bundle jar with ant
How to create executable jar with dependencies with Maven
How to export an executable jar in Gradle
simply using ant download it , and then make a build.xml file and put it
Here's an simple example of an ant target that will create a jar (named test.jar) that includes all jar files under the lib directory. Maybe this will solve your problem?
for using apache ant, see this
http://ant.apache.org/manual/using.html

Adding additional java files to playframework classpath

I have a project that shares models with my android project. I have a separate eclipse project just for models and other shared code. I add this to my play project as a dependency in eclipse.
In eclipse, play compiles and starts without problem. However, I went to deploy to GAE and found that the compilation stage of play's packaging fails because it can't find the models.
I suspect I could hack the ant build files, but that seems brittle.
Is there a standard way to add extra directories to the play compilation source tree or the classpath?
Make a jar-file with your classes and put it in /lib. That's where I put my libraries.
Files in the application /lib folder is automatically added to the class path by Play Framework. See Classpath settings
From Anatomy: "The app directory contains all executable artifacts: Java and Scala source code, templates and compiled assets’ sources" ... and further: "You can of course add your own packages, for example an app/utils package"
You can copy java source files to make a hierarchy of packages under /app, e.g.:
/app/sharedcode/project2/models/domain1 and import that in WhateverController.scala as:
import sharedcode.project2.models.domain1._

Categories