I have a project with standard maven layout:
src/main/java
src/main/webapp
I want to develop this project in Eclipse in such a way, that Eclipse would compile my classes into exploded war folder, smth like this:
build/webapp/WEB-INF/classes
And I do not use maven as a build tool, I use gradle. Is it a way to configure Eclipse, that my output folder of the project is of correct structure for exploded war?
task explodedWar(type: Copy) {
into "$buildDir/exploded"
with war
}
war.dependsOn explodedWar
With these lines of code in your web module build.gradle you can have your generated war exploded
You can change this by adding the following to your build.gradle file:
apply plugin: "eclipse"
eclipse {
classpath {
defaultOutputDir = file("${buildDir}/webapp/WEB-INF/classes")
}
}
This sets the output dir to the correct directory. Also take a look at the Gradle DSL reference
Related
I have a web application which depends on another standalone project. Simply the web project requires a standalone project jar to be in classpath. I have built the standalone project jar with gradle and included that in web application's WEB-INF/lib folder. The project is running as expected. Now i want to make it automatic by adding that project as dependency. This is also achieved using the following code.
settings.gralde
include 'job-invoker'
project(':job-invoker').projectDir = new File(settingsDir, '../job-invoker')
build.gradle
dependencies {
compile project(':job-invoker')
.
.
}
I'm able to build the war file from command line using gradle and run it in tomcat. But i'm getting errors in eclipse. I'm not able to run the project in eclipse due to the compilation errors. Can some one please help me. Thanks in advance.
Finally i found a solution for this by installing the other project in maven local repository and adding this as a regular dependency in project. Reference code is given below.
Other project Gradle file
apply plugin: 'maven'
group = 'com.xxx.job'
version = '1.0'
Run gradle install command on this project. Then add mavenLocal() to your repositories in another project and add the dependency
compile 'com.xxx.job:job-invoker:1.0'
I have a root project that builds WAR, and two child projects that build JARs. The root project references the child project in this way:
apply plugin: 'war'
jar.enabled = false
war {
dependencies {
runtime project(':application1')
runtime project(':application2')
}
}
application2 depends on application1:
dependencies {
compile '...:application1:1.+'
}
The WAR file includes two versions of application1.jar: one from repository, another just built.
EDIT: Application2 has to depend on application1 as a JAR because that simplifies debugging in Eclipse with embedded Jetty: Eclipse automatically adds application1.jar to classpath of Jetty server launch configuration.
You have specified dependency on application1 project differently for the root project and for the application2.
For your application2 it was made as dependency on a library within some repository, but your root project depends on it as on a subproject. Gradle can't determine, that some library in the repo is the same, as subproject's artifact.
If you don't want to get 2 versions of the same lib, you have to make it dependent from the same library: either as
compile '...:application1:1.+'
or as
runtime project(':application1')
Anyway, it seems to be prefferable, to make it depending on the same subproject in both cases, rather then on some project and on the library in repo.
I have created the Gradle web app which is running inside the NetBeans. Now I want to add some external jar files in it so how can I add the jar from NetBeans.
Modify your Gradle project to add your dependency and refresh it in NetBeans to pick up the changes. There is plenty of documentation how to do it. For example How to add local .jar file dependency to build.gradle file?
If you really need to take that .jar from a local directory,
Add next to your module gradle (Not the app gradle file):
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile name: 'gson-2.2.4'
}
ref:check here
I have a gradle project in eclipse (using STS plugin). I have a properties file I want on my classpath. This file is read during tests. In my project view, I put this file on
\src\test\resources\test.properties
When I run
gradle test
from the command line, this file is read.
But when I run eclipse it is not.
To reiterate what superEb said in his comment:
src/test/resources must be designated as a source folder for Eclipse to include your properties file on the classpath for tests.
You can in include Gradle's Eclipse plugin to handle this for you automatically with:
apply plugin: 'eclipse'
How do I create a package of a Maven project that contains the jar with my classes, plus a directory like "lib" with all the needed dependencies? I'm using netbeans ...
You can copy required libs into a folder using Maven dependency plugin copy-dependencies goal.
In addition to that you can use Maven assembly plugin to create an archive containing your jar and this lib folder.