I'm using an open source project that produces a war. I want to deploy this to a Jetty server. I want to create an sbt project with a Main class where it fires up a jetty server, and then deploy above war to it.
The problem I'm facing is how to tell jetty to deploy the war. Even if I made the war as a dependency, still I would not have the war physically in my project.
One thing I tried was add
retrieveManaged := true
in build.sbt, where it copied all the dependencies to the managed_lib folder, but that looks ugly.
I cannot move the war project in to SBT
Any good ways to do this?
The steps you need to take are basically the following:
Create an sbt task that gives you access to the war file
Communicate the location of the war file to your code
Tell Jetty the location of the file
Note that the code is untested, but it should give you something to go on
1.
val warFile = taskKey[File]("A reference to the war file")
warFile := {
val filter = artifactFilter(name = "name of warfile")
val updateReport = update.value
updateReport.filter(filter).toSeq.headOption.map {
case (config, module, artifact, file) => file
}.getOrElse(sys.error("Could not find a warfile"))
}
2.
In project/buildinfo.sbt add addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.3.2")
buildInfoPackage := "your.package",
buildInfoObject := "BuildInfo",
buildInfoKeys := Seq[BuildInfoKey](
warFile
),
sourceGenerators in Compile <+= buildInfo
3.
val warFile = new File(BuildInfo.warFile)
// pass to Jetty
Related
I have a following project structure
bin
start.sh
db
liquibase_scripts
...
schema.json
main
java
...
test
resources
liquibase_scripts
...
schema.json
So than I build my project, folder db with liquibase scripts added to distributive.
In unit tests I use H2 database and want to load schema from db/liquibase. I create bean
#Bean
public SpringLiquibase springLiquibase() {
SpringLiquibase springLiquibase = new SpringLiquibase();
springLiquibase.setDataSource(dataSource());
springLiquibase.setChangeLog("classpath:/liquibase/sam.json");
return springLiquibase;
}
The problem is that method setChangeLog look at resource folder in test folder.
So to solve the problem I copied all liquibase scripts to the test/resources directory.
But this is not ok becouse now I have 2 copies of scripts in different folders.
Is there a way to force springLiquibase.setChangeLog find scripts in any folder not only in test/resources?
In Maven build configuration you can define testResources, which may be directories and files. It looks like this:
<build>
<testResources>
<testResource>
<directory>${project.basedir}/db/liquibase_scripts</directory>
</testResource>
</testResources>
</build>
With such configuration Maven copies the files into the target/test-classes directory. Thanks to that those files can be used as test resources in the code, but there's no duplication in the project files.
Im using such configuration (Liquibase + testResources) in one of my projects. To better reproduce your problem, I've created a separate branch, where you can find the configuration described above - see: this commit diff. All test pass after the change.
I have a LibGDX project with some tests. The structure is as follow:
core/src -> for my java sources code
core/test -> for my tests source code
core/assets -> for all my assets
When I run the tests from eclipse, they all go green but whenever I try to run them from the gradle command line (./gradlew test) I get an error with the assets folder. I believe this is because the tests are not launched from the assets folder as it is from eclipse.
How can I solve this problem ? Is there a way to tell gradle to use core/assets as the workspace directory when running the tests ?
Here is the error I get:
com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load dependencies of asset: myasset.png
I found a way to achieve what I wanted. I post my solution here for anyone that might need it. There is a property named workingDir for the test task in gradle. So I just needed to set it to the right folder. Inside the build.gradle file of your project (the root folder) just add the following section:
project(":core") {
apply plugin: "java"
// Add the following test section
test{
workingDir= new File("/assets")
}
// Rest of the file
}
That's it! My tests are running green from the command line now.
I am trying to write a Dropwizard application and its doc tells me that I need to ship everything as an uber jar.
However, in my application I need to support multiple databases and this requires multiple database JDBC driver jars in my classpath, all of which are not expected to be shipped together with my application. Users are expected to place the corresponding JDBC jar like mysql-connector-java-5.1.39.jar in a particular folder by their own.
After reading Dropwizard's documentation I am not sure if this kind of usage is supported. Does anyone have experience making it to work this way?
Since java 6, you can wildcard classpaths.
Using the application plugin, the generated bin folder will have a start script that contains the classpath. What we want to do, is to instead of listing every possible jar in the bin folder, we simply include all of them.
Note: You can also do the same thing with different folders if you want the classpath in a different location.
This can be achieved (in a workaround manner since there are problems with this plugin in my version) in the easiest way as follows. In build.gradle you do:
startScripts {
doLast {
def windowsScriptFile = file getWindowsScript()
def unixScriptFile = file getUnixScript()
windowsScriptFile.text = windowsScriptFile.text.replaceAll('CLASSPATH=.*', 'CLASSPATH=\\$APP_HOME/lib/*')
unixScriptFile.text = unixScriptFile.text.replaceAll('CLASSPATH=.*', 'CLASSPATH=\\$APP_HOME/lib/*')
}
}
This will wildcard your lib folder in the start scripts. When starting up, your classpath will simply be
lib/*
When you drop jars into that folder, they will automatically be picked up (on startup, not on runtime).
I hope this helps,
Artur
I am having a issue when I run jetty in embedded mode after creating my jar file. It works from the same location where jar is created because it can locate src/main/webapp folder but when I copy my jar it's not running. And when I open my jar it doesn't have src/main/webapp everything is at root level.
First of all why is it creating everything at root level any specific reason?
Can I run my jar from Java command line if there is no src/main/webapp, if yes then in that case what shud be my webcontext resource look like in my main class
try this:
String webappDir = this.getClass().getClassLoader().getResource("applicationContext.xml").toExternalForm();
webappDir = webappDir.substring(0, webappDir.lastIndexOf('/') + 1);
String webXmlPath = webappDir + "WEB_INF/web.xml";
WebAppContext context = new WebAppContext(webappDir, contextPath);
context.setDescriptor(webXmlPath);
context.setResourceBase(webappDir);
context.setClassLoader(new WebAppClassLoader(this.getClass().getClassLoader(), context));
Run from IDE or Jar both works.
A WebJob running on Azure does not seem to drop the <Content> files (Copy if Newer) into the correct directory.
I get the following error:
System.IO.DirectoryNotFoundException: Could not find a part of the path 'D:\local\Temp\jobs\continuous\LongTasks\lprysn1r.tsv\Content\File.cshtml
And I try to access that file as such:
File.ReadAllText("Content/File.cshtml");
When running locally, it works just fine.
Is there a way to get this static file dropped appropriately?
After doing some tests, the convention is they do a shallow copy of the /bin/Release folder to App_Data/jobs/continuous/LongTasks/
Which means, if there are any folders, they are not being copied.
Moving the "File.cshtml" to the root directory fixes this problem.
I know this is not fully related to the Azure WebJobs SDK, but this is happening on 6/22/2015 with version 1.0.0.
You should use WEBJOBS_PATH environment variable for currently running webjob.
var webjobPath = Environment.GetEnvironmentVariable("WEBJOBS_PATH");
if (string.IsNullOrWhiteSpace(webjobPath))
{
// Handle dev environment
webjobPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
}
This will return some path like D:\local\Temp\jobs\triggered\\xxeeeexxx.qzx\, which contains your content files and folders.