I'm using Spark as framework to build a Java web server and rely on Bootstrap and jQuery for frontend. I'm using Webjars to bring dependencies in my pom.xml.
The problem omes with importing static files. While importing Bootstrap's CSS and JS files works well, it doesn't for jQuery JS file. I import the static files using staticFileLocation("/META-INF/resources"); and HTML header contains:
<link rel="stylesheet" href="webjars/bootstrap/3.3.6/css/bootstrap.min.css">
<script type="text/javascript" src="webjars/jquery/2.2.1/jquery.min.js"></script>
<script type="text/javascript" src="webjars/bootstrap/3.3.6/js/bootstrap.min.js"></script>
webjars/bootstrap/3.3.6/css/bootstrap.min.css and webjars/bootstrap/3.3.6/js/bootstrap.min.js routes work well but webjars/jquery/2.2.1/jquery.min.js answers 404.
Somehow, it looks like jQuery JS file isn't present in classpath. Any clue what I'm missing ?
Edit:
The pom.xml dependencies are the following:
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.6</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>2.2.1</version>
</dependency>
Edit 2:
I also call staticFileLocation() two times in my controller:
staticFileLocation("/static");
staticFileLocation("/META-INF/resources");
The two calls seem to conflict with each other.
The jquery version 2.2.1 dependency is probably being overridden via a transitive dependency on jquery in bootstrap. You can either set an exclusion in the bootstrap dependency:
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.6</version>
<exclusions>
<exclusion>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
</exclusion>
</exclusions>
</dependency>
Or you can remove the explicit dependency on jquery and use the transitive one which is 1.11.1 per the bootstrap pom.xml.
I've found that if you run Spark from an IDE which is used mvn exec:exec to run project then you get only bootstrap in /META-INF/resources/webjars.
But if you make a jar-with-dependencies first and then run it with java -jar <your-project-name-and-version>-jar-with-dependencies.jar you'll get whole set of resources (both bootstrap and jquery in your case).
Actually you can easily check available resources with this code:
get("/list", (req, res) -> {
Resource resource = Resource.newClassPathResource("/META-INF/resources");
return resource.getListHTML("/", true);
});
Accessing /list you will get whole list of available resources.
Diving into Spark's source code, I found that one can refer to only one static folder location. Hence, only one webjar can be used at the same time and it will make Spark to ignore any CSS or JS file in any other location.
Related
I am doing a camel project with Jetty server using Springboot, I must expose the apis swagger-ui. I have already generated the swager in json format and it can be consulted at localhost:8080/swagger. Using swagger-ui webjars I am trying to see the graphic interface of swagger but this is not generated.
Im using this maven dependencies:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-swagger-java-starter</artifactId>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>swagger-ui</artifactId>
<version>3.1.4</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator</artifactId>
<version>0.36</version>
</dependency>
it is suppose that when using webjars the swagger-ui can be consulted in the path /webjars/swagger-ui/index.html, but i get:
Problem accessing /webjars/swagger-ui/index.html. Reason:Not Found
I tried to define a camel route like this: but doesnt work.
rest("/swagger")
.produces("text/html")
.get("/index.html")
.responseMessage().code(200).message("Swagger UI").endResponseMessage()
.to("direct://get/swagger/ui/path");
from("direct://get/swagger/ui/path")
.routeId("SwaggerUI")
.setBody().simple("resource:classpath:META-INF/resources/webjars/swagger-ui/3.1.4/index.html");
I was using this example:
https://medium.com/#bszeti/swagger-with-spring-boot-and-camel-ac59cca9556e
but I use Jetty as rest component
restConfiguration().component("jettty").port(8080).bindingMode(RestBindingMode.json)
.skipBindingOnErrorCode(false)
How can I expose the swagger Ui Interface?
I hope someone can help me, thank you very much
I made a program that parses turtle files with Jena library. These are the dependencies i use:
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-iri</artifactId>
<version>3.10.0</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-core</artifactId>
<version>3.10.0</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-arq</artifactId>
<version>3.10.0</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-tdb</artifactId>
<version>3.10.0</version>
</dependency>
So the parsing is working well on my java program but when i create my jar and try to run it, i have these kind of errors :
ERROR JenaService:146 - org.apache.jena.n3.turtle.TurtleParseException: Line 28015, column 79: org.apache.jena.iri.impl.IRIImplException:
<http://www.reussir.fr,> Code: 28/NOT_DNS_NAME in HOST: The host component did not meet the restrictions on DNS names.
Any ideas ?
EDIT
I have a warning for the invalid IRI problem by running my program with the IDE, but still giving me errors with the generated jar.
<http://www.reussir.fr,>
There is a comma in the URI in a place where commas are not allowed.
It is better to find and fix the data problem because it can lead to other problems later if not fixed.
I found the problem, the only dependency i really needed was jena-arq, so i removed others dependencies (especially jena-iri which was throwing the TurtleParseException) and the bad-iri errors became warnings like in the IDE execution logs.
Has anyone used Spring JDBC with Clickhouse? What is the driver class name?
spring.datasource.driver-class-name=<what is it?>
I guess it could be it, even though it doesn't look like any other driver class names that I have seen.
spring.datasource.driver-class-name=ru.yandex.clickhouse.ClickHouseDriver
There is also lighter and faster alternative to the official driver version - clickhouse4j. (fork of the official driver with some improvements)
You can use it like this:
spring.datasource.driver-class-name=cc.blynk.clickhouse.ClickHouseDriver
Driver was renamed due to moving vom yandex to clickhouse.com.
Clickhouse Driver
spring.datasource.driver-class-name=com.clickhouse.jdbc.ClickHouseDriver
See https://github.com/ClickHouse/clickhouse-jdbc
Also note Java Client and JDBC Driver MVN dependencies changed as well:
Maven Clickhouse Java Client
<dependency>
<groupId>com.clickhouse</groupId>
<!-- or clickhouse-grpc-client if you prefer gRPC -->
<artifactId>clickhouse-http-client</artifactId>
<version>0.3.2-patch11</version>
</dependency>
Maven Clickhouse JDBC Driver
<dependency>
<!-- please stop using ru.yandex.clickhouse as it's been deprecated -->
<groupId>com.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>0.3.2-patch11</version>
<!-- use uber jar with all dependencies included, change classifier to http for smaller jar -->
<classifier>all</classifier>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
Starting 4.0.0 yandex packages will be removed and be non functional!
im trying to do some 'integration' tests using MockMvc class
I use:
this.mockMvc.perform(
get("/admin"))
.andExpect(status().isOk())
.andDo(print());
but freemarker which is responsible for generating page is using security taglib
<#assign security=JspTaglibs["http://www.springframework.org/security/tags"] />
maven dependency:
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
which seems to be not available while testing.. exception:
The following has evaluated to null or missing:
==> security [in template "lib/abc.ftl" at line 170, column 19]
application itself is working, but I have to use mvn tomcat:run-war instead mvn tomcat:run to get taglib in place.
I had to copy
~/.m2/repository/org/springframework/security/spring-security-taglibs/3.2.0.RELEASE/spring-security-taglibs-3.2.0.RELEASE.jar
to my WEB-INF/lib folder. Then I get another issue about missiong 'Tag' class so I had to add
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
</dependency>
copy paste that jar file seems to be dirty workaround.. please let me know if there is any better solution.
edit
there is a way to run it using mvn tomcat7:run instead run-war, so taglibs are loaded and template files refreshed without server restart. Just add
<jarScanAllDirectoriescontextReloadable>true</jarScanAllDirectoriescontextReloadable>
<contextReloadable>true</contextReloadable>
to your tomcat7-maven-plugin in pom.xml
I have a Spring 3 MVC app that I am setting up some ajax actions for.
My controller action looks like this:
#RequestMapping(value="add", method=RequestMethod.POST)
#Secured("ROLE_USER")
#ResponseStatus(HttpStatus.CREATED)
public #ResponseBody Plan addPlan(#RequestBody Plan plan, Principal principal) {
//Save the plan
}
When I post the Plan data from my browser the app throws a ClassNotFound exception:
java.lang.ClassNotFoundException: org.joda.time.ReadableInstant not found by jackson-mapper-asl [176]
at org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:787)
at org.apache.felix.framework.ModuleImpl.access$400(ModuleImpl.java:71)
at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1768)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
The Plan object itself does not contain any joda-date types. Though it contains a collection of objects that do. Originally I was pulling in the joda-date jar via my DOA jar but the error persists even if I add a direct dependency to my web project's pom.xml. I'm using the joda classes elsewhere in this project without any issue.
Additional information
Here are the relevant dependencies from my web pom.xml:
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.3</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.3</version>
</dependency>
I somehow came across this question: Apache FTP server is not seeing a logging jar package that exists in the class path
Their solution of setting <class-loader delegate="false"> in glassfish-web.xml seems to have fixed my issues.
I've reported this on Glassfish JIRA https://java.net/jira/browse/GLASSFISH-20808