IntelliJ web application resources missing from classpath - spring

I'm using IntelliJ to build a standard java web application on top of Tomcat and Spring. I'm fairly new to IntellJ and feel like I'm missing something setup wise because I cannot seem to resolve resource files from the classpath.
Relevant Info -
IJ 2017.1.4
Tomcat 8.5.15
Java 8
Spring platform-bom:2.0.8.RELEASE
I should also mention I'm using a java only configuration, taking advantage of the Spring's annotations and the servlet 3.0+ spec.
Since I'm pretty sure this is an issue with my IJ configuration, here's a series of screenshots outlining my setup & the error. Appreciate any help on this one, it's had me stumped for a bit.
Modules
Facets
Artifacts
Project src
Exploded War ouptut
Code where I'm attempting to load in a file on the classpath
Error

Related

Spring Boot Maven plugin: What does it actually do?

Can someone give me an understanding of what the Spring Boot Maven plugin actually does? I have been Googling, but most of what I find doesn't give a clear picture.
The impression I have so far is that it can create a "fully executable" jar that does not need to be run via java -jar, and that it's also possible to make a more traditional jar that you would run via java -jar. I'm sure there are other variations of what it can produce as well.
I'm also under the impression that it can package up dependencies and resources. It's not at all clear to me how the resources are "accessed" by the application when it's run.
In either of the outcomes described above do I need just the jar and nothing else (i.e. no resource files, dependency jars, etc.)? In other words, is the jar self-contained? When I've opened the jar up, it does seem that everything it needs is there. Is that really the case?
Now, let's go a little further towards what I'm trying to do. I am writing a set of Spring services with REST APIs. Each service will be run in its own VM (or container - future). The services are packaged into a single jar and the service to be used is selected via Spring profile (i.e. spring.profiles.active=a-profile).
The way I've done things like this before has been to use the Maven assembly plugin to produce an archive (zip) for each separate service and inlcude all of the necessities (dependency jars, resource files, etc.). I'd place it where needed, unpack it, tweak some configuration and run it via an included script.
I'm getting the impression that's not "how it's done" when the Spring Boot Maven plugin is involved.
The Spring Boot Maven Plugin provides Spring Boot support in Maven, letting you package executable jar or war archives and run an application “in-place”.
It builds the uber jar which bundles in Tomcat along with your app. If you inspect the contents of the jar with jar -tf <file_name> you will see that the format is a bit different. The Spring Boot classes look normal, but then your project's files are inside a BOOT-INF folder.

Making a spring boot fat jar file with gradle WITHOUT a spring boot gradle plug-in (no access to bootJar)

I have a spring-boot application in which I loaded all the necessary (or so I believe) dependencies to run without using spring-boot initializer or the spring-boot gradle plug-in. These tools are not available for me at my work. I can run the application through intellij without issues, but when attempting to run a fat jar, I am met with
No auto configuration classes found in META-INF/spring.factories.
Now the spring.factory files ARE located inside the fat jar (there are multiples of them) and they are inside the meta-inf directory.
Spring boot has so much automated functionality, I am not sure where to begin. There are a lot of similar posts and everyone just tells people to use the spring-boot gradle plugin bootJar task but as I said these are not available to me. I need to get it running without those tools,
if anyone has insight into what the issue may be or how to resolve it, any help is appreciated. I will try to add more details later.
I am using spring-boot v. 2.1.1 and spring 5.1.4

Can Spring Boot + Gradle generate a war file compatible with Servlet 2.4?

I've been reading about using Spring Boot and Gradle to quickly build RESTful services: https://spring.io/guides/gs/rest-service/. I'd like to give it a try but I need to build a war that's compatible with servlet 2.4 (I know.. life in the 1970's).
The error I get when attempting to deploy the war generated by following the guide above to Sun App Server 8.1 is:
Unknown deployable object type specified: "Cannot determine the J2EE
component type"
The generated war has no web.xml and there may be other expected artifacts.
Configuring a spring-boot application using web.xml seems to suggest that a web.xml can be packaged with a Spring Boot application but doesn't explain how.
Is Spring Boot compatible with older servlet specs? How can Spring Boot and Gradle be used to generate a war that works on older web containers?
Thanks.
The answer to the question you linked to didn't actually go as far as saying that you could easily create a fully-leaded Boot application with Servlet 2.4. I consider that quite a hard, but probably achievable, target if you are prepared to do some legwork, and accept some compromises. You might find this stuff useful: https://github.com/scratches/spring-boot-legacy (I managed to use it to push an app to GAE). But there are some limits to what can be supported for such old technology, and we aren't officially supporting anything other than Servlet 3.0.1 right now.

IntelliJ + Tomcat + Spring-Loaded

I would like to try out Spring Source's "Spring Loaded" class reloading agent, with Tomcat run via IntelliJ.
https://github.com/SpringSource/spring-loaded
I've added the JVM arguments to my Tomcat run configuration, and my webapp starts up without errors and seems to behave normally.
I'm not really sure how to trigger the class reloading though. Do I just need to compile the classes that I modify? I've tried that and that didn't seem to work. Do I need to update Tomcat and deploy classes and resources? That doesn't seem to work either...?
Any specific configuration details would be greatly appreciated.
EDIT: More info, I think my problem may have to do with using two modules, one a core code library, and one the webapp. I use Maven for both, one configured as a jar project and the other as a war project. IntelliJ sets up the Artifact for the exploded war to use the jar module's jar file. I've tried switching the Artifact config to incorporate the jar module's compiled output into WEB-INF/classes instead. Now I see the .class files in target/webapp/WEB-INF/class/etc. But I'm not sure how to get IntelliJ to update a specific class file when I edit it.
If you added the following jvm parameters (as described at the springloaded page) to your tomcat
-javaagent:<pathTo>/springloaded-{VERSION}.jar -noverify SomeJavaClass
you should be fine. It may help to disable auto reloading in tomcat for the webapp you are testing. For exmaple in your server.xml:
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
<Context docBase="projekt" path="/projekt" reloadable="false" ...
This ensures that only the springloaded classloader loads changed classes.
spring loaded cannot hotswap jars.
Put web fragment output into webapp/WEB-INF/classes
Also spring loaded support only spring 4.1
https://github.com/spring-projects/spring-loaded/issues/139

Embed Jetty in Eclipse RCP

I am building a RCP application , where I need to monitor http traffic and show it to user. For that I require use of Embeded Jetty as transparent proxy.
I tried everything , followed this Tutorial But things just don't work. I get build exception.
I tried adding Jetty jar as external dependency , but still no use.
Would appreciate any help. Also please let me know if there are any other ways of achieving this without use of jetty. (I tried Socks but it conflicts with RCP UI thread)
Thank You.
In broad terms you need to look into making eclipse plugins and how to declare dependencies in eclipse plugin projects. What you are basically looking to do is write a bit of code based on our jetty embedded examples only in a plugin context, so when your plugin loads it would trigger the starting of the jetty server. You will load the jetty dependencies as osgi bundles. Note that in juno much of jetty 8.1.3 will be available by default.
Its not the best example in the world, but you can look at our crusty wtp plugin for some ideas, at least on how you could configure things using tycho and maybe some organizational bits.
http://git.eclipse.org/c/jetty/org.eclipse.jetty.wtp.git/

Resources