Intellij IDEA: Server Configuration cannot be run cause file does not yet exist. Use maven goal result as artifact? - intellij-idea

until now I deployed to a Glassfish server with the default IntelliJ artifact "Web Application: Archive". Now my built process got a bit more complicated with maven modifying several files.
In the glassfish configuration under Deployment, I substituted the Artifact to deploy with the direct war file and put the maven goal in "Before Launch: Another Configuration"
However, if mvn clean was run the war does not exist and I cannot run the configuration (because the external file doesn't exist).
Can I avoid having to run mvn package once manually? E.g. by making the output of a maven goal an Artifact?
Thanks!

Related

IntelliJ Jetty plugin does not extract war

I'm using IJ Ultimate 2020.3 and trying to set up a Jetty Server run configuration.
AFAIK, in order to start Jetty with a war artifact it is needed to be located in $JETTY_HOME/webapps directory.
But, it looks like the Jetty plugin of my IJ refuses to copy the war (exploded, or any other) artifact to that directory, which lead the Jetty server to fail.
I was able to start the Jetty server (from IJ) only after manually copying the war file into the webapps directory, so looks like the only problem is the 'copy' step.
Any ideas?
IntelliJ IDEA doesn't copy the artifact into webapps, instead it instructs Jetty to load the artifact directly from the location that you have configured as the artifact output directory.
Artifact used for deployment:
Artifact output directory:
Startup logs showing that artifact is loaded directory from its output directory and not from webapps:
Thanks #CrazyCoder, this is a progress for me.
problem is that my output console suggests that it does not search for the artifact in the location it is set:

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.

Building war with Gradle, Debugging with IntelliJ IDEA

I have JavaEE webapp project(named ProjectA) developed in IntelliJ IDEA.It has build.gradle file that applies war plugin :
apply plugin: 'war'
I want to debug(or run) gradle generated war file instead of debugging auto generated intellij artifact.
It's very important for me that I can update classes changed during debugging without need to restart server.
How can I do it?
Note that :
1) When click refresh button in gradle plugin tab () Intellij updates all project configurations(for example module dependencies) and generate artifacts.I called it auto generated intellij artifact.
For run it,I should only create new local Tomcat Server configuration and add artifact to deployment tab.
2) In addition,there is some gradle tasks(clean,build,war and etc).I can execute build task or war task to generate war file.I called it gradle generated war file.
Instead of deploying the IntelliJ build artifact, you can deploy an "External source" by clicking the "+" button in your final screenshot. You can then navigate to the artifact built by Gradle (in this case, the .war file in build/libs).
Second, you can instruct IntelliJ to run a Gradle task before running the configuration. Again, in your final screenshot, I would remove the second step labeled "Build 'Gradle ...' artifact" and add a step to run the Gradle war task.

Dynamically loading dependency in maven

Can we dynamically load dependencies using maven.
For example, lets say we have a web project which needs a specific jar A to run on Glassfish server, while the same project needs additional jar B to run on weblogic in its WEB-INF/lib folder.
Do I need to have the separate pom.xml file for glassfish and weblogic and then run the appropriate pom.xml depending on the server being used?
Or Can I have a single pom.xml with both dependencies i.e. both jar A and jar B specified in it and depending on the parameters passed to pom.xml while running it (like mvn clean package -Dserver=glassfish), it will load the jar A only?
Is this possible?
What is the most appropriate way of doing this?
Please help.
You can exploit the concept of profiles in maven. You can create a whole profile of your execution environment and launch maven with that profile. For more info, see http://maven.apache.org/guides/introduction/introduction-to-profiles.html
These profiles can be defined within pom or can be defined in an external file and refer it to in pom. You can activate a profile by launching it with -P option, mvn -P

How does Intellij deploy to JBoss?

I finally have my application in IntelliJ and deploying to JBoss. I'd like to get hot deploy working but it looks like I need to understand how IntelliJ and JBoss interact.
When I build my project in IntelliJ and then start JBoss, the ear file does not appear in the deploy directory so I assume that there is some magic that IntelliJ does so that JBoss reads from a different folder. What is happening during this step?
Thanks :)
I know this is an old and apparently answered question, but unfortunately the links provided in the accepted answer didn't give me the simple details I was looking for. For anyone also trying to understand how IntelliJ IDEA deploys your exploded war to JBoss without copying files to the deployments folder, here's what I've found while deploying locally from IDEA 14 (EAP) to JBoss 7.1.1.Final:
After you've created an "exploded war" artifact for your project (or it has automatically been created for you), IDEA will build your provided sources and place the output in the directory set in the artifact options (you can change this setting to place the output inside the deployments folder inside your jboss installation).
IDEA will update your JBoss configuration file (/standalone/configuration/standalone.xml) and add a "deployment" node inside the deployments section. This entry simply defines a name, a runtime name and the exploded war root folder for your project, which will point to the output directory of your artifact set in IDEA.
When JBoss is started (either manually or from your run/debug configuration in IDEA), it will automatically deploy your artifact. Be warned that if your files are in the output directory of your project and you clean it, JBoss will still try to find the directory, thus encountering errors in your next attempt to start it: org.jboss.as.server.deployment.DeploymentUnitProcessingException: Failed to mount deployment content, Failed to process phase STRUCTURE of deployment and java.io.FileNotFoundException to name a few.
Please refer to the documentation.
Basically, you need an exploded Artifact configuration with the directory name ending with .ear.
Build | Make performs hot deployment as well as Update action (which is configurable and can update only resources, resources and classes, optionally redeploy or restart the server).
Instead of copying your application to JBoss, IDEA runs it with appropriate parameters so that it uses Artifact directory instead. Configuration is very flexible and you can just change the artifact directory location to reside under JBoss directory.