Consume .jar in java web project

1

I created a .jar (script.jar) file that contains the "print ()" method only returns a string and I would like that when I click a button in my Java Web application (JavaEE) this "print executed.

Script.jar file method

package jardeteste.metodos;

public class Test{
     public static String imprimir(){
          return "Teste de Impressão";
     }
}

Bean method that receives and manipulates the click (checkBoxView.java)

package projetojavaweb.bean;

import jardeteste.metodos;

@ManagedBean
public class CheckboxView {

        public static void executar(ActionEvent event) {
                String recebedor = Teste.imprimir();
                System.out.println(recebedor);
        }

}

View if needed: (testList.xhtml)

 <p:commandButton value="Printar" actionListener="#{checkboxView.executar}" icon="ui-icon-check"/>

Error generating log:

WARNING: /pages/testList.xhtml @20,124 actionListener="#{checkboxView.listarTestes}": java.lang.NoClassDefFoundError: jardeteste.metodos
    javax.el.ELException: /pages/testList.xhtml @20,124 actionListener="#{checkboxView.listarTestes}": java.lang.NoClassDefFoundError: jardeteste/metodos
        at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:111)
        at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:147)
        at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
        at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:813)
        at javax.faces.component.UICommand.broadcast(UICommand.java:300)
        at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
        at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
        at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
        at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:475)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:498)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:796)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1368)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Unknown Source)
    
asked by anonymous 12.04.2017 / 18:06

1 answer

0

You must define a class or import the entire package in import:

import jardeteste.metodos.*;

or

import jardeteste.metodos.Teste;

You can also directly import the static components of the Test class:

import static jardeteste.metodos.Teste.*;

This way you do not need to put the class during the method call:

String recebedor = imprimir();
    
12.04.2017 / 23:50