Gradle dist folder on IntelliJ classpath - intellij-idea

We have a project which we build with gradle. We use IntelliJ as our development environment.
We have some resources we want to keep outside the JAR and so we have put them in the src/dist-folder. This works fine when running the application from the command line, but not so good when we want to debug from IntelliJ.
We could put a runtime-dependency to src/dist, but then we end up with files inside our lib-folder in the generated ZIP file and that's not what we would like to have.
Bottom line: how can we keep some resources outside the JAR (in src/dist) and also on the classpath of IntelliJ (as generated by Gradle; I don't want to have to add things manually to the IntelliJ classpath). The directory structure in the resulting zip should be something like:
root
|
|- config/*
|- css/*
|- lib/*
It seems that this question describes a similar problem, but the solution in addition #4 still mentions that no solution was found to correctly get the resources on the classpath of IntelliJ:
Gradle build file with conf folder with properties not in jar but on classpath

The solution I've used in a similar situation is to:
Use the Idea plugin in gradle rather than relying on the IntelliJ support.
Once that is working you can tweak the source path that IntelliJ uses in the gradle file itself

Related

IntelliJ Spring Boot: How to create an executable jar

I'm trying to create an executable jar from IntelliJ.
First I got the Java Security Exception and I changed sqljdbc4-4.0 to unsigned. First problem solved.
Then I got Manifest not found. Added META-INF dir to output. Second problem solved.
Next I got the BeanCreationException (unsolved):
Caused by: org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.
In IntelliJ it is working.
I think the resources are not in the output. (application.properties, ...)
In which way do I add the resources or where are they stored in the jar.
I'm using gradle and on the spring boot homepage are only instructions for maven.
You should use spring-boot-maven-plugin or spring-boot-gradle-plugin, depending on your preferred build system.
EDIT:
Just run ./gradlew build
I suggest to dive into this getting started guide. It clarifies a lot of stuff for beginners.
A typical Spring boot project is a Maven project or a Gradle-Project (I only know how to do it with Maven, for Gradle see [luboskrnacs answer][1]). So you just need to run the maven targetpackageand pick the jar form the (created)target` folder
use a shell, go to the project root directory (where the pom.xml file is) and type
mvn clean package
cd target
the there is the xxx.jar file.

Using Gradle to Build an IntelliJ Module From Command Line

I understand the basic functionality of gradle, but I don't understand how to use a build.gradle file other than the one in the project's root. I have a project which contains a gradle wrapper in it's root, and a module which has it's own build.gradle file. How do I specify for gradlew to use the module's build.gradle file instead of the one in the root directory?
Specifically, I have an IntelliJ project I have uploaded to my CI server, and I am trying to setup a script to run the builds automatically.
Cheers
It looks like you have a multi-module build which only has a single module... correct?
You could include a settings.gradle which points to the module
You could declare a GradleBuild task in the root module to invoke the sub module.
A good place to look for inspiration is the java samples and the organizing build logic page in the documentation. An impressive feature of gradle is that all of the code snippets which appear in the documentation is sourced from the samples directory which is run as part of their CI build.
Happy Gradling!

What is a working directory in Intellij IDEA

I created a Maven project and imported it in Intellij IDEA.
In a run configuration, there is a field "working directory", which points to the root of Maven project.
If I change this folder, it doesn't seem to affect anything. So what is it?
This is the directory that is set as the Java user.dir system property. If you have any code that creates relative files or directories, it will be relative to this directory. So for a well designed application (i.e. resolves resources from the classpath and is configurable for output directories) this will not be a factor. There is also some importance to this value in maven projects, especially multi-module maven projects. This directory specifies the directory IDEA will read the POM from.
If you are unflamilar with what the Java user.dir is, there is some discussion available here and in the class level Javadoc for the File class.
In addition to answer given by #Javaru if you want to update or view your working directory in IntelliJ IDEA go to:
Run | Edit Configurations | Configuration Tab | Working Directory
From the IntellJ help Run/Debug Configuration: Maven
Working directory Specify the path to the Maven project file pom.xml.

logback.xml and running application from JetBrains IDEA IDE

When I develop application in IDEA, where should I place logback.xml for it to have an effect on the application?
It seems when you run/debug IDEA doesn't make any jars and doesn't invoke Maven to build something. Does it execute main() directly from compiled *.class file? If so, where can I put logback.xml so that it would have effect?
logback.xml should be available in the root directory of your CLASSPATH. When you run your application, the full CLASSPATH is printed at the very beginning. When I put logback.xml in /src/main/resources (Maven project) it works without any problem. Also putting it in /src/test/resources with logback-test.xml name has presence.
Simply run:
getClass().getClassLoader().getResource("/logback.xml");
And see whether it returns something or null.
If you are not working with Maven project, open Project structure (Ctrl + Alt + Shift + S) and add in Modules section select folder containing logback.xml and mark it as Sources (blue icon).
For me: I simply needed to re-build the project (not just re-run or re-compile the project). Changing the src\main\resources\logback.xml did not affect logback because the class loader is picking up the logback.xml that is in the target/ folder, not the /src folder. This makes sense since target is the run environment. Therefore, a build is required to transfer the new xml file over to target.

intelliJ 9 cannot find class I specify in web.xml

I am trying to get logdigger to work in my java app that uses google app engine. I have tried putting my jar files in the src/ directory, lib/ directory, and no matter what I do, it can't find the class. The only thing that it finds is the com.google.appengine stuff. I have tried messing with my dependencies and it's not working. Has anyone done this before and gotten it to work? I am not sure how to modify the classpath through intelliJ (however in the project settings I have the jars linked as a dependency under the modules section).
You probably need to look at the artifacts for your project. IntelliJ separates runtime assembly of WARs into the artifacts section. Look and see that your WAR file is assembled properly. I'm guessing that you don't put the contents of the /lib directory into the WEB-INF/lib of your WAR. The compiled output ought to go into WEB-INF/classes. All other output belongs in the root of the deployment.