VAADIN cannot find themes when in productionMode - java

I have custom theme for my VAADIN application in src/main/webapp/VAADIN/themes/mytheme/ with files mytheme.scss and styles.scss.
Everything works fine when the vaadin productionMode deployment parameter is set to false in web.xml. When I set the parameter to true, suddenly Vaadin cannot find the resources for my theme and keeps complaining with:
Requested resource [/VAADIN/themes/mytheme/styles.css] not found from filesystem or through class loader. Add widgetset and/or theme JAR to your classpath or add files to WebContent/VAADIN folder
I dont have a /WebContent directory but /webapp instead, since its a maven web-app project.
I tried putting the VAADIN folder to:
src/main/resources
src/main/webapp
src/main/webapp/WEB-INF
but nothing works for the production mode. Any suggenstions?
Thank you in advance for help.

You need to add following goal to your pom.xml, which will compile the .scss files to .css files:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<classpathScope>compile</classpathScope>
<mainClass>com.vaadin.sass.SassCompiler</mainClass>
<arguments>
<argument>src/main/webapp/VAADIN/themes/heijunka/styles.scss</argument>
<argument>src/main/webapp/VAADIN/themes/heijunka/styles.css</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
Source: http://dev.vaadin.com/ticket/10291

#Develman already answered how to fix the problem but a bit more explanation.
When a Vaadin application is in development mode, it does the SCSS -> CSS compilation automatically when styles.css is requested and the file does not exist. In the production mode this does not happen. If styles.css exists, regardless of mode, the file is used and there is no SCSS -> CSS compilation.

I got this error even-though I've added maven goal to pom.xml
Finally got to know the reason, Its because of I've enabled production mode of Vaadin on web.xml
So when production mode on, its not generating styles.css file.
So you need to disable production mode in order to enable this SCSS - > CSS compilation.
<context-param>
<description>Vaadin production mode</description>
<param-name>productionMode</param-name>
<param-value>false</param-value>
</context-param>

Related

Spring boot : Add static web page (Angular) in a custom folder outside classpath folder (classes)

How would I place the static contents in a WAR Archive.
I have tried placing them inside the classes folder and works fine, but to make the cleaner I am asked to put it outside the WEB-INF, in a custom folder. I was able to do that and make it work by setting the welcome page in web.xml
<welcome-page>'./app/index.html'</welcome-page>
But the issue is that I don't want 'app' to appear in my URL, when the pages were kept inside classes/static the index.html appeared in root(localhost:8080), but putting the pages in custom folder URL changed to - localhost:8080/app
Is there any way to keep the pages in a custom folder and still get the index page and its dependencies from root URL.
Either you place your resources under "src/main/webapp", these will be copied to the root of your WAR. If you need more flexibility, maybe the maven-war-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<webResources>
<resource>
<directory>${project.basedir}/mycustomdir</directory>
<targetPath>somewhere</targetPath>
</resource>
</webResources>
</configuration>
</plugin>

Seperate spring.factories into multiple files

In Spring Boot, you can do the following:
src/main/resources/META-INF/spring.factories
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.autoconfigure.admin.AConfiguration,\
org.springframework.boot.autoconfigure.admin.BConfiguration,\
org.springframework.boot.autoconfigure.admin.CConfiguration,\
org.springframework.boot.autoconfigure.admin.DConfiguration,\
org.springframework.boot.autoconfigure.admin.EConfiguration,\
org.springframework.boot.autoconfigure.admin.FConfiguration,\
Which is very nice. However after a year of development the list of auto configuration is now > 15 lines, which makes it hard to manage.
Would like to know if it is possible to separate the spring.factories into multiple files? Preferably would like to keep the whole project in one JAR.
Or maybe there is another ways to help organize the EnableAutoConfiguration that I am not aware of?
Thanks in advance!
While using spring-boot we use multiple "starters", each with an auto-configuration and spring.factories file.
So, one way could be to split your project into modules - one for each auto-configuration, define a dedicated spring.factories file in the module, and import all the modules as a runtime dependency in the main application module.
You can use maven or gradle to manage the multi-module project and the dependencies among them:
Gradle: https://guides.gradle.org/creating-multi-project-builds/
Maven: https://www.baeldung.com/maven-multi-module
Example:
root
moduleA
src/main/resources/META-INF/spring.factories
moduleB
src/main/resources/META-INF/spring.factories
and so on...
I have found a solution for this question.
Note: This exact solution assume that you only used EnableAutoConfiguration in your spring.factiores, it would crash if you use more than one type of config inside spring.factories.
One can do:
src/main/resources/META-INF/spring.factories
src/main/resources/META-INF/spring-2.factories
src/main/resources/META-INF/spring-3.factories
src/main/resources/META-INF/spring-4.factories
and merge this into one file.
Note, I am using Maven Antrun but I suspect Gradle would also have a similar feature.
In your pom.xml, add the following:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>default-ci</id>
<goals>
<goal>run</goal>
</goals>
<phase>process-resources</phase>
<configuration>
<target>
<replace token='org.springframework.boot.autoconfigure.EnableAutoConfiguration=' value=','
dir="${project.build.directory}/classes/META-INF">
<include name="spring-*.factories"/>
</replace>
<concat destfile="${project.build.directory}/classes/META-INF/spring.factories" overwrite="yes" append="yes">
<fileset dir="${project.build.directory}/classes/META-INF" includes="spring-*.factories" />
</concat>
</target>
</configuration>
</execution>
</executions>
</plugin>
And in spring.factories is the normal config:
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.autoconfigure.admin.AConfiguration,\
org.springframework.boot.autoconfigure.admin.BConfiguration
But in spring-2.factories and others, you start with ,\ instead of the default statement:
spring-2.factories:
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.autoconfigure.admin.CConfiguration
spring-3.factories:
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.autoconfigure.admin.DConfiguration
After all that, the outcome spring.factories in your output class directories will be a very nice:
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.autoconfigure.admin.AConfiguration,\
org.springframework.boot.autoconfigure.admin.BConfiguration,\
org.springframework.boot.autoconfigure.admin.CConfiguration,\
org.springframework.boot.autoconfigure.admin.DConfiguration

Maven: zip resources and save into specific folder

For a project I need to zip a number of resource files and put this archive inside the project source (src/main/resources). The idea is that this archive then ends up in the EAR and goes to the deployment server, where it is picked up by a script for further processing. Convoluted, I know, but those are the constraints we are working with.
I've created an Assembly plugin configuration file that creates the zip, but this zip is placed by default in a target/ folder.
The assembly plugin has an outputDirectory option, but this only changes the filestructure of the contents of the zip, not the location where the zip is saved.
Is there a way to specify where the assembly plugin saves the created zip? Or is there a better way altogether to zip resources?
there are two outputDirectory configuration, one represents the file path inside your assembled package,
another one represents directory where your assembled package would be output
you are looking for second one
Please add the following code in pom.xml , provide the path in outputDirectory tag :
<execution>
<id>assembly-execution</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>zipFileName</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>${project.basedir}/zip.xml</descriptor>
</descriptors>
<outputDirectory>${project.basedir}/src/main/resources</outputDirectory>
</configuration>
</execution>

Java webapp : How to map/direct webapp to your BASE URL/IP?

Typically when you create a webapp you will access your webapp when you hit the url
<your_IP>/<Project_name>/
Example:
127.0.0.1/MyWebapp/
Question: How do you configure your webapp to run from base URL
Example
127.0.0.1/
Moreover, when the browser navigates to your IP (and not your IP + name of your webapp) you can hit your webpage
Question: Is this a configuration file that needs to be edited in your Application web server?
It depends on your container, but generally you will name your file ROOT.war or specify the context explicitly.
For example, since you've tagged this question with jetty, here is the plugin in my pom.xml for embedded testing using mvn jetty:run. Notice the contextPath element.
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.25</version>
<configuration>
<contextPath>/</contextPath>
<scanIntervalSeconds>5</scanIntervalSeconds>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>8081</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
</configuration>
</plugin>
When I deploy to Tomcat, I simply name my file ROOT.war and drop it into the webapps folder. Note that you'll need to move or remove the existing ROOT content from webapps first.
Doing this will allow you to access your application at http[s]://<host>[:<port>]/ with no extra context needed.
Assuming you're using maven to build your application, you can avoid manually re-naming your WAR by specifying the finalName in your pom.xml.
<build>
<finalName>ROOT</finalName>
[...]
</build>

Composite components in an external JAR are not recognized in Netbeans

I have packaged a number of composite components in a JAR. However, when using them in another project (using Maven), Netbeans editor puts red error lines under lines which use the composite component, even though the project compiles and runs as expected.
The folder structure for the composite component JAR look like:
compositeComponent.jar
META-INF
faces-config.xml
highcharts-taglib.xml
MANIFEST.MF
web.xml
maven
// maven stuff.
resources
highcharts
Chart.xhtml
Series.xhtml
Tooltip.xml
nz
co
kevindoran
highcharts
example
NZPopulationTrend.class
The highcharts.taglib.xml looks like:
<facelet-taglib version="2.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd">
<namespace>http://nz.co.kevindoran/highcharts-jsf</namespace>
<composite-library-name>highcharts</composite-library-name>
</facelet-taglib>
[Side note: The faces-config.xml and web.xml are present to allow the 'JAR' to be deployed as a WAR by changing the file extension to WAR (this is to done to run the examples).]
In my current project, I have specify a Maven dependency on the above project like so:
<dependency>
<groupId>nz.co.kevindoran</groupId>
<artifactId>jsf-menu</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
In a JSF page, I use on of the composite components like so:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:hc="http://nz.co.kevindoran/highcharts-jsf">
....
<hc:TimeChart title="Price Over Time" xLabel="Date" yLabel="Sold Price (NZD)">
<hc:TimeSeries name="Sold" series="#{cc.attrs.model.priceVsTimeChart.soldSeries}"/>
</hc:TimeChart>
....
</html>
Red error lines appear under all lines above, with message: "No library found for namespace http://nz.co.kevindoran/highcharts-jsf"
How do I get these error lines to be removed? I have seen many Netbeans bug reports for similar issues, but all seem resolved.
This error occurs on Netbeans 7.1, 7.2 and 7.3 (including 7.3.1).
I have absolutely the same problem. In my case it depends on the /src/main/java folder. If it's exist (only in the project and not even in the jar) the project which includes this library shows the "No library found for namespace... "
When i remove the "java" folder it works. But then my backing bean class is missed in the jar...
Tried with Netbeans 7.2 and 7.3, maven 2
Solution:
Generate a second project which contains the Java source files. (called: jsf-lib-java)
In jsf-lib project (your composite component project with xhtml) delete the "java" folder and all *.java sources.
add in the jsf-lib pom.xml following configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.mycompany.project</groupId>
<artifactId>jsf-lib-java</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>src/main/</outputDirectory>
<includes>**/*.class</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
That's it. This will generate a "good" jar file with the required *.class files. So it's possible to "trick" Netbeans.
Now i work with this solution. It's a hack but didn't found a better solution.

Categories

Resources