Where should the META-INF directory be in order for sbt to pick up custom configurations. I had this issue when trying to use the ServiceLoader and I was trying to create a custom services in META-INF/services
The META-INF folder will get automatically picked up by sbt if you put the folder in src/main/resources/
For Play application code the META-INF should be put inside the conf directory inside service/conf
I have verified this on my own application where I used it for putting META-INF/services/ file with the name of api.ImplementationClass in it and it worked with ServiceLoader.load
Related
What is the best practice for including template group files in a jar?
I would like to include my StringTemplateGroup file in my executable jar. I'm using Eclipse and have put the template group file in a folder called "template" under the project. In my java code, I create the files using:
STGroup File templates = new STGroupFile("template/file.stg");
This works fine in Eclipse, but when I export the jar and run it, I get the following error:
Exception in thread "main" java.lang.IllegalArgumentException: No such group file: template\HasbroServiceHelper.stg
How do I get the name of the file in the jar file itself, so I can prefix with "jar:file" or is there a better way to package the template file in the jar?
I have not tested it, but something like this should work.
String fullPath = getClass().getClassLoader().getResource("/template/file.stg").getFile();
STGroup File templates = new STGroupFile(fullPath);
There are two approaches to do this
In my case I have package the "templates" Folder along with the jar file.
Why: so the benefit of doing this if I need to change the template then in that case we don't need to regenerate or redeploy the jar
When we run the above code from the eclipse then eclipse knows that you are running from the project directory. That's the reason its running fine from the eclipse
myapp
|-- myapp.jar
|---Templates folder
If you run the jar from the "myapp" folder then you will not get the above exception.
Second Possible way to do this you have to keep your template files in your classpath means move them into resources folder and call it by the ResourceLoader
But in this case if you have some changes in the templates then you have re-build your entire project
#Autowired
ResourceLoader resourceLoader;
resourceLoader.getResource("classpath:template/mytemplate.stg");
Hope that Helps :)
Is it possible set custom "lib_managed" path in build.sbt? I would want that command update the puts jar files to the my web folder web/WEB-INF/lib. If sbt does not allows setup custom folder(google finds nothing), what i must add to the build.sbt to copy files from lib_managet folder to my web/.../lib folder?
lib_managed is only a build-local cache and it contains jars for all configurations, such as Test and Compile. It is not appropriate to list its contents and use it as a classpath. There may be duplicates or libraries that shouldn't be on the classpath of interest.
I am developing a application in Netbeans7.1. I am facing one problem to add new jar file from the app after building the app.
As i know, when we build the project in Netbeans that will create a "jar" file and "lib" directory (which has all the libraries those are being used in the application) into the "dist" directory.
The problem is, I have to add new jar from my application into /lib/ directory after building the project. So that jar will be used in the application.
How should i do this?
If you have a successful build then it means the jar you wants to add is required at runtime not at compile time otherwise it wouldn't have compiled.
And if above is the case adding jar is straightforward.
Add the jar file to lib folder.
Now open you applications jar with some rar software like winrar.
Goto the META-INF folder open the MANIFEST.MF file and append the class path with lib/new_jar_file.jar.
Bingo..You are done.
Here is a screenshot of MAINIFEST.MF file and red box shows where to add the above mentioned lines.
I have the log4j.properties and another .properties file under src and it works deployed in gwt dev mode. To build the war to launch to tomcat I use an ant script that compiles the .java classes and puts them in a JAR file. The JAR file gets copied into the WEB-INF folder in the war file.
The app runs fine when I don't use log4j but it can't find the properties file when I attempt to use log4j. All of the answers I see say WEB-INF/classes, but my project doesn't have a WEB-INF/classes directory, instead the JAR file that was copied to WEB-INF contains my projects classes.
You have to put log4j.properties (or log4j.xml) file into directory or JAR that is considered by your servlet-container as resource in Classpath.
So, simply create WEB-INF/classes directory and put it there, or pack it into your JAR.
See also Where should I put the log4j.properties file? - it could be useful.
I am using a java jar dependency that requires a certain property file to be on the classpath. I can't for the life of me figure out how to add this folder/file to the classpath. I am using play 2.0.
I have added the config.properties file to both the /conf directory and have tried to add it to the root of my app source folder. The file does not seem to be recognized by the dependency.
BTW: play 2.0 uses sbt to compile and run the application so maybe something there could help?
Any ideas?
You should be fine if you put the property file where your class files are. When you use SBT you probably use either:
The project root directory as source directory. In this case just put your property file into the root directory.
Or the maven layout, so your normal classes are under src/main/scala In this case put your property file under src/main/resources
Although the answer of Jens Schauder should solve your issue, you may want to try to add the file to the lib folder.
Play 2.0 won't remove files manually added in there (at least it doesn't at the time I'm writting this!) and that folder should be included into the classpath automatically.