How to Access API end point from executable jar in another maven project
I have one scenario where I have backend API which is build in springboot. I need to build API project as executable jar and want to use that in another project. which is basic maven project where I am using frontend code. I want to include my executable jar in frontend project and then want to access the API end point directly from the jar. Without giving any reference in frontend code. What configuration I need to do for this in POM? I have tried multiple online solution but none of them working. I am getting 404 always if I try to access the API end point from frontend project. Note: Final deployment should happen on Tomcat server with Frontend code and API jar both in same War file and deployed in tomcat. So I should be able to access the Backend API directly from jar.
If anyone can help on this it would be great help. Thanks in advance.
do you know?
how many words do you know
See also questions close to this topic
-
Read each name in Array list to create seperate object for
I have a file that has student names, age, and an id number. I have a student class that holds the everything above for each student object. I stored all the names, id numbers. and age separately in an array list. Now im trying to assign the info to create a student object.
public class Student { private String lName; private int idNumber; private int age; public Student() { lName = ""; idNumber = 0; age = 0; } public Student(String l, int i, int a) { lName = l; idNumber = i; age = a; } public void setName(String last) { lName = last; } public String getName() { return lName; } public void setIdNum(int num) { idNumber = num; } public int getIdNum() { return idNumber; } public void setAge(int a) { age = a; } public int getAge() { return age; } }
My Text File looks something like this: This info is stored in parallel array lists. I don't quite get how to implement this into an object to pass it into my second contractor method.
Josh 2134 19 Smith 5256 21 Rogers 9248 19 Andrew 7742 20
Here's what I've tried;
public static void main(String[] args) { String file = "studentData.txt"; Scanner reader = new Scanner(file); ArrayList<String> lastNames = lNames(file); ArrayList<Integer> idNumbers = idNum(file); ArrayList<Integer> ageList = ages(file); Scanner input = new Scanner(System.in); Student s1 = new Student(); // confused about how to implement this constructor with the textile info for (int i = 0; i<idNumbers.size(); i++) { Student user = new Student(lastNames.get(i), idNumbers.get(i), ageList.get(i)); } //user enters idNumber to display age System.out.println("Enter ID Number"); //exception handling to be added int idNum = input.nextInt(); for (int i = 0; i<idNumbers.size(); i++) { if (idNum == idNumbers.get(i)) { s1.setAge(ageList.get(i)); System.out.println(s1.getAge()); } } }
-
Using EdittextPreference for Goto search
sorry for my poor English. I want to use EditTextPreference in my bottom nav like the pic below, ![screenshot][1]
I have recycleview xml in my project with in many sub cardview layouts(which is scrollable) and I want to create item in the bottom nav which is called "Goto". When the "Goto" item is clicked i want it to pop-up like the screenshot. And when user enters a number(according to the cardviews i.e if the number of cardview is 40 user must enter 1-40) I want to search the cardview by its ID. Thank you and I hope u got it, If u have any questions let me know [1]: https://i.stack.imgur.com/grK8P.jpg
My xml format look like this. As you see in the blow since the cardviews are huge in number it is not cool to scroll all the way down that is why i need Goto item in the bottom nav to search it by its ID when the user click number in the EditTextPreference as u see in the screenshot. i.e The screenshot is not from my app
<LinearLayout> <LinearLayout> <androidx.cardview.widget.CardView> <RealtiveLayout> <Textview/> <RealtiveLayout> </androidx.cardview.widget.CardView> </LinearLayout> <LinearLayout> <androidx.cardview.widget.CardView> <RealtiveLayout> <Textview/> <RealtiveLayout> </androidx.cardview.widget.CardView> </LinearLayout> <LinearLayout> <androidx.cardview.widget.CardView> <RealtiveLayout> <Textview/> <RealtiveLayout> </androidx.cardview.widget.CardView> </LinearLayout> <LinearLayout> <androidx.cardview.widget.CardView> <RealtiveLayout> <Textview/> <RealtiveLayout> </androidx.cardview.widget.CardView> </LinearLayout> .. .. .. .. many more..
-
How to get remaining time of the day in java?
I would like to calculate the time remaining for next day 00:00:00 from the current date time.
For e.g. time difference between 2
022-05-07T05:49:41.883807900Z
and2022-05-08T00:00:00Z
Expected answer:
18:10:19
or 65419 (in seconds).How can I achieve this with efficiently using java 8?
-
best way to add a spring boot web application with JSPs to a docker container?
so i have a spring boot web application, it uses JSPs, and im supposed to put it in a container .
my question is what is the best way ? ive tried to copy the project and then run it there using a wmvn like so : dockerfile:FROM openjdk:8-jdk-alpine ADD . /input-webapp WORKDIR /input-webapp EXPOSE 8080:8080 ENTRYPOINT ./mvnw spring-boot:run
which works, but it takes a long time getting the dependencies and feels messy .
and ive tried to package it into a jar, and then copy the jar only, and run it : dockerfile:
FROM openjdk:8-jdk-alpine ADD target/input-webapp-0.0.1-SNAPSHOT.jar input-webapp-0.0.1-SNAPSHOT.jar EXPOSE 8080:8080 ENTRYPOINT ["java","-jar","input-webapp-0.0.1-SNAPSHOT.jar"]
but this way it cant see the JSPs, or at least i think this is the problem, as i get a 404.
so is there a better way ? can i copy the jsps plus the jar to make it work? thanks
-
build spring boot (mvnw) with docker can not use cache
Spring Boot Docker Experimental Features Docker 18.06 comes with some “experimental” features, including a way to cache build dependencies. To switch them on, you need a flag in the daemon (dockerd) and an environment variable when you run the client. With the experimental features, you get different output on the console, but you can see that a Maven build now only takes a few seconds instead of minutes, provided the cache is warm.
my dockerfile can not use cache.
dockerfile
# syntax=docker/dockerfile:experimental FROM openjdk:8-jdk-alpine as build WORKDIR /workspace/app COPY mvnw . COPY .mvn .mvn COPY pom.xml . COPY src src RUN --mount=type=cache,target=/root/.m2 ./mvnw install -DskipTests -s .mvn/wrapper/settings.xml RUN mkdir -p target/extracted && java -Djarmode=layertools -jar target/*.jar extract --destination target/extracted FROM openjdk:8-jre-alpine ENV TZ Asia/Shanghai RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone RUN addgroup -S spring && adduser -S spring -G spring USER spring:spring ARG EXTRACTED=/workspace/app/target/extracted ARG JAVA_OPTS="-Xmx100m -Xms100m" COPY --from=build ${EXTRACTED}/dependencies/ ./ COPY --from=build ${EXTRACTED}/spring-boot-loader/ ./ COPY --from=build ${EXTRACTED}/snapshot-dependencies/ ./ COPY --from=build ${EXTRACTED}/application/ ./ ENTRYPOINT ["sh", "-c","java ${JAVA_OPTS} org.springframework.boot.loader.JarLauncher"]
run shell
DOCKER_BUILDKIT=1 docker build -t org/spring-boot .
every time use many minutes
-
How can I delete a row by its SKU instead of its ID?
I try to delete the row using the sku of the product. I'm using spring boot and angular. I got an error when I added the sku on my button like this one
(click)="onDeleteProductBySku(deleteClick?.sku)"
it said that theProperty 'sku' does not exist on type '(product: Product) => void'.
. On my command prompt, I got this error. How can I solve this problem?Error: product/product.component.html:50:109 - error TS2339: Property 'sku' does not exist on type '(product: Product) => void'. 50 <button class="btn btn-outline-danger btn-sm me-2" (click)="onDeleteProductBySku(deleteClick?.sku)">Delete</button> product/product.component.ts:12:16 12 templateUrl: './product.component.html', ~~~~~~~~~~~~~~~~~~~~~~~~~~ Error occurs in the template of component ProductComponent.
ProductsController.java --> This is working on the postman.
//Delete a product record using sku //http://localhost:8080/products/deletebysku?sku=12345678 @DeleteMapping("/products/deletebysku") @ResponseBody private void deleteProductBySku(@RequestParam String sku){ productsService.deleteProductBySku(sku); }
product.component.ts
public deleteProduct!: Product; public onDeleteProductBySku(sku: string): void { this.productServive.deleteProductBySku(sku).subscribe( (response: void) => { this.messageShow(); console.log(response); this.getAllProduct(); }, (error: HttpErrorResponse) => { this.errorMessage(error.message); } ); } public deleteClick(product: Product) { this.deleteProduct = product; console.log("delete by sku"); }
product.service.ts
public deleteProductBySku(sku: string): Observable<void> { return this.http.delete<void>(`${this.apiServerUrl}/products/deletebysku?sku=${sku}`); }
product.component.html
<button class="btn btn-outline-danger btn-sm me-2" (click)="onDeleteProductBySku(deleteClick?.sku)">Delete</button>
-
"no main manifest attribute" in .jar Netbeans 13
I recently just started toying around with Maven in java. Time comes to test my project, it works fine in the NetBeans window, running the main class found in App.java (com.MyCompany.App), but when I try to run it from a command line I get an error:
"no main manifest attribute"
I'm using Apache Netbeans 13 with Maven to build the project
Any help will be apreciated Thanks in advance
-
Spring Boot - nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type '' available
I'm trying to add the following statement to a Spring Boot service:
@Autowired private ApELDatabasePublisherService eventPublisher;
The dependency for eventPublisher is contained in maven, in this jar file:
.m2\repository\com\xxxx\bip\bip-event-logging\1.5.3.7-RELEASE.jar
It compiles, builds and updates the local maven repository, but when I launch the application, it terminates with an error message.
Initially, the error message was this:
No qualifying bean of type 'com.xxxx.bip.components.el.services.ApELDatabasePublisherService' available
However, that disappeared when I added
com.xxxx.bip.components.el.services
to the component scan.The next message was this:
No qualifying bean of type 'com.xxxx.bip.components.el.dao.services.IApElTypeNameLookupService' available:
So I added
com.xxxx.bip.components.el.dao.services
to the component scan, and that error went away.But now I have a third message which is not going away, as follows:
No qualifying bean of type 'com.xxxx.bip.components.el.repository.IApELEventTypeRepository' available
This message stays even when I add the following to component scan:
com.xxxx.bip.components.el.repository
So my current scan looks like this:
@EnableRetry @EnableScheduling @SpringBootApplication(exclude = { HibernateJpaAutoConfiguration.class }) @ComponentScan(basePackages = { "com.xxxx.bip.components.el.services", "com.xxxx.bip.components.el.dao.services", "com.xxxx.bip.components.el.repository",
I've verified that the class in question,
IApELEventTypeRepository
is included in the jar file and is annotated as "@Repository"Why would it not find it when it finds the previous two packages?
-
Tomcat static content path security with Spring
I'm trying to setup static content serving on my Tomcat 9 server So I specified it inside server.xml
<Host name="${serverhost}" appBase="webapps" unpackWARs="true" autoDeploy="false" deployOnStartup="false"> .... <Context path="/staticfiles" docBase="${staticfiles.folder}" reloadable="false"/> .... <Context path="" docBase="application" reloadable="false"> ....
On top of that I set up spring sercurity filter for /staticfiles path::
<security:http use-expressions="true" entry-point-ref="authenticationEntryPoint" access-decision-manager-ref="accessDecisionManager" disable-url-rewriting="true" pattern="/staticfiles/**" create-session="never" security-context-repository-ref="oAuth2EapiCompositeSecurityContextRepository"> <security:csrf disabled="true"/> <security:headers disabled="true"/> <security:http-basic/> <security:form-login authentication-failure-handler-ref="authFailureHandler" authentication-success-handler-ref="authSuccessHandler" username-parameter="j_username" password-parameter="j_password" login-processing-url="/j_spring_security_check"/> <security:anonymous enabled="false"/> <security:intercept-url pattern="/staticfiles/**" access="permitAll"/> <security:intercept-url pattern="/**" access="denyAll"/> <security:custom-filter ref="fileTransferResourceServerFilter" before="PRE_AUTH_FILTER"/> </security:http>
web.xml mapping
<filter-name>springSecurityFilterChain</filter-name> <url-pattern>/staticfiles/*</url-pattern>
It allows to access all the static files without any authentication still
GET apphost.com/statifiles/333/test.jpg doesn't ask for authentication, so seems like Spring Security filter chain doesnt match this path somehow, but all the other application endpoints are secured (with corresponding security patterns)
So seems like Tomcat somehow use it's own filter to serve static content, I tried to put
<Context path="/staticfiles" docBase="${staticfiles.folder}" reloadable="false"/>
inside
<Context path="" docBase="application" reloadable="false">
which actually makes it work so Spring protecting this path with basic auth but after sucessfull login it responds with 404 all the time, seems like Spring doesn't fallback to Tomcat static content servlet after Spring Security filters
-
Springboot 202 with Apache Tomcat (TomEE)/8.5.6 (7.0.2)
I am trying to deploy Springboot 202 application on Apache Tomcat (TomEE)/8.5.6 (7.0.2).
During deployment of generated war file(customotmmportal.war), I dont see any error when tomee starts but tomee hangs after printing these lines.
Error:
localhost-startStop-1 2022-05-06T13:40:09,322 | INFO | session=402906812 | user=customuser | com.server.scheduler.task.UpdateScheduledJobTask | Updated scheduled job with name:Asset Expire Events localhost-startStop-1 2022-05-06T13:40:09,343 | INFO | session=402906812 | user=customuser | com.server.security.session.task.LogoutTask | User customuser (session 402906812) has logged out localhost-startStop-1 2022-05-06T13:40:09,435 | INFO | session= | user= | OpenEJB.tomcat | ------------------------- localhost -> /customotmmportal localhost-startStop-1 2022-05-06T13:40:09,915 | INFO | session= | user= | org.apache.jasper.servlet.TldScanner | At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
localhost-startStop-1 2022-05-06T13:40:09,942 | INFO | session= | user= | org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/customotmmportal] | 1 Spring WebApplicationInitializers detected on classpath
**Code1:** @RestController @EnableAutoConfiguration public class MessageController { @GetMapping("/hello") public String hello() { return "Hello World"; } } **code 2:** @SpringBootApplication public class SpringBootApp extends SpringBootServletInitializer{ @Override protected SpringApplicationBuilder configure( SpringApplicationBuilder builder) { return builder.sources(SpringBootApp.class); } public static void main(String[] args) { SpringApplication sa = new SpringApplication( SpringBootApp.class); sa.run(args); } } **pom.xml:** <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.2.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <artifactId>spring-boot-starter-tomcat</artifactId> <groupId>org.springframework.boot</groupId> </exclusion> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-hateoas</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> </dependency> </dependencies> <build> <finalName>customotmmportal</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> <configuration> <skip>true</skip> </configuration> </execution> </executions> </plugin> </plugins> </build>
-
IM getting "HTTP Status 500 - Servlet.init() for servlet dispatcher threw exception" error,new to spring-mvc and java
I'm new to java ,self-learning through video's and stackoverflow , I cannot find where I committed error in this code.
this is my web.xml :
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>Spring-mvc</display-name> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
this is my dispatcher-servlet page:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:component-scan base-package="com.controller"/> <bean class="org.springframework.web.servlet.view.InternalResourceViewResoulver"> <property name="prefix" value="/WEB-INF/JSP/"></property> <property name="suffix" value=".jsp" ></property> </bean> </beans>
this is my controller java class:
package com.controller; import javax.servlet.http.HttpServletRequest; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; @Controller @RequestMapping("/display") public class Control { //@RequestMapping("/display") public ModelAndView reqandres(HttpServletRequest req) { String nme=req.getParameter("name"); return new ModelAndView("display","message",nme); } }
this is my login-page:index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <form action ="display" method="get"><br><br> <input type="text" name="Name" placeholder="enter username" ><br><br> <input type= "password" name="passWord" placeholder="enter password"><br><br> <input type="submit" value="submit"> </form> </body> </html>
this is my view page (display.jsp):
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <form action ="display" method="get"><br><br> <input type="text" name="Name" placeholder="enter username" ><br><br> <input type= "password" name="passWord" placeholder="enter password"><br><br> <input type="submit" value="submit"> </form> </body> </html>
this is error I'm getting:
HTTP Status 500 - Servlet.init() for servlet dispatcher threw exception type Exception report message Servlet.init() for servlet dispatcher threw exception description The server encountered an internal error that prevented it from fulfilling this request. exception javax.servlet.ServletException: Servlet.init() for servlet dispatcher threw exception org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476) java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Unknown Source) root cause org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.web.servlet.view.InternalResourceViewResoulver] for bean with name 'org.springframework.web.servlet.view.InternalResourceViewResoulver#0' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.web.servlet.view.InternalResourceViewResoulver org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1380) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:670) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:637) org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1489) org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1007) org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:741) org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868) org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:676) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:642) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:690) org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:558) org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:499) org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:172) javax.servlet.GenericServlet.init(GenericServlet.java:158) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476) java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Unknown Source) root cause java.lang.ClassNotFoundException: org.springframework.web.servlet.view.InternalResourceViewResoulver org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1332) org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1166) org.springframework.util.ClassUtils.forName(ClassUtils.java:255) org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:437) org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1428) org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1372) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:670) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:637) org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1489) org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1007) org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:741) org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868) org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:676) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:642) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:690) org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:558) org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:499) org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:172) javax.servlet.GenericServlet.init(GenericServlet.java:158) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476) java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Unknown Source) note The full stack trace of the root cause is available in the Apache Tomcat/8.0.36 logs. Apache Tomcat/8.0.36
this is what I'm getting in console:
-
Spring Boot not embedding custom script
I am trying to make a executable jar with spring boot. It will be run on FreeBSD so I need to add a custom embeddedLaunchScript, but have not been able to do so.
In the projects pom.xml file I have added the executable and embeddedLaunchScript tags but when I open the jar I generate after doing run as maven install, I cannot find the script and when I try to run the application on my server it give the following error:
./MyApplication-0.0.1-SNAPSHOT.jar -bash: ./MyApplication-0.0.1-SNAPSHOT.jar: /bin/bash^M: bad interpreter: No such file or directory
Any insight into what I am missing would be most appreciated.
Below is the relevant portion of my pom.xml:
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>com.company.project.MyApplication</mainClass> <executable>true</executable> <embeddedLaunchScript>myApp-launch-script.sh</embeddedLaunchScript> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
-
In Java, deal with NoClassFoundError
My project is built using Apache Maven JAR Plugin, I'm using ini4j inside my project managed by maven, on the IDE, everythin works fine. But when i try to launch the JAR in the cmd as follow : java -jar javaProgram-1.0-SNAPSHOT.jar
I get this error :
Exception in thread "main" java.lang.NoClassDefFoundError: org/ini4j/Ini at org.example.Main.main(Main.java:14) Caused by: java.lang.ClassNotFoundException: org.ini4j.Ini at java.net.URLClassLoader.findClass(URLClassLoader.java:387) at java.lang.ClassLoader.loadClass(ClassLoader.java:418) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ... 1 more
Here is the manifest.mf inside the .jar:
Manifest-Version: 1.0 Class-Path: lib/ini4j-0.5.4.jar lib/maven-jar-plugin-3.2.2.jar lib/mav en-plugin-api-3.1.0.jar lib/maven-model-3.1.0.jar lib/org.eclipse.sis u.plexus-0.0.0.M2a.jar lib/cdi-api-1.0.jar lib/jsr250-api-1.0.jar lib /javax.inject-1.jar lib/guava-10.0.1.jar lib/jsr305-1.3.9.jar lib/sis u-guice-3.1.0-no_aop.jar lib/aopalliance-1.0.jar lib/org.eclipse.sisu .inject-0.0.0.M2a.jar lib/asm-3.3.1.jar lib/maven-core-3.1.0.jar lib/ maven-settings-3.1.0.jar lib/maven-settings-builder-3.1.0.jar lib/mav en-repository-metadata-3.1.0.jar lib/maven-model-builder-3.1.0.jar li b/maven-aether-provider-3.1.0.jar lib/aether-spi-0.9.0.M2.jar lib/aet her-impl-0.9.0.M2.jar lib/aether-api-0.9.0.M2.jar lib/aether-util-0.9 .0.M2.jar lib/plexus-interpolation-1.16.jar lib/plexus-classworlds-2. 4.2.jar lib/plexus-component-annotations-1.5.5.jar lib/plexus-sec-dis patcher-1.3.jar lib/plexus-cipher-1.4.jar lib/maven-artifact-3.1.0.ja r lib/file-management-3.0.0.jar lib/maven-shared-io-3.0.0.jar lib/mav en-compat-3.0.jar lib/sisu-inject-plexus-1.4.2.jar lib/sisu-inject-be an-1.4.2.jar lib/sisu-guice-2.1.7-noaop.jar lib/wagon-provider-api-2. 10.jar lib/maven-archiver-3.5.2.jar lib/commons-io-2.6.jar lib/common s-compress-1.20.jar lib/plexus-archiver-4.2.7.jar lib/plexus-io-3.2.0 .jar lib/snappy-0.4.jar lib/xz-1.9.jar lib/maven-shared-utils-3.3.4.j ar lib/plexus-utils-3.3.1.jar Build-Jdk-Spec: 1.8 Created-By: Maven JAR Plugin 3.2.2 Main-Class: org.example.Main
Any idea how i could provide everything while keeping maven? The goal would be to build the .jar and to launch it in the cmd instead of runnig it in the IDE
EDIT : This problem has been solved using the Apache Maven Shade Plugin allowing you to fix the problem by running the shaded jar.