How to import javax.faces library in Eclipse using JDK8? - eclipse

Based on the advice to use JSF, the following sample would like to be run in order to learn more about JSF and to implement this technique into the servlet. However, a number of libraries is unable to be imported:
package tobedefinedservlet;
import javax.faces.bean.ManagedBean;
#ManagedBean
public class Hello {
final String world = "Hello World!";
public String getworld() {
return world;
}
}
javax.faces
The import javax.faces cannot be resolved
ManagedBean
ManagedBean cannot be resolved to a type

You have to include a JSF library like for example Mojarra in the classpath of your application.
First of all have a look at the Primefaces user guide (especially chapter 2.2). You can download e.g. Mojarra here and include the JAR or add the dependency to your POM.xml if you are using Maven. Hope that helps.

If you're using maven for build automation, add the latest jsf-api dependency to your pom.xml:
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1</version>
</dependency>
Or the latest javax.faces-api implementation:
<dependency>
<groupId>javax.faces</groupId>
<artifactId>javax.faces-api</artifactId>
<version>2.3</version>
</dependency>
However, note that JSF is integrated into most Java EE application servers, such as JBoss.
See also this answer.

in my case ...I went to project properties and in the search engine I wrote facets ... I went to the right of the window and selected the runtime tab and select wildfly ... then apply and apply and close and solve ...

If you're not using maven you have to manually install the jar. You can download it at this link:
javax.faces
If you're using eclipse you can right click your Web App project and click properties at the bottom. Then under the java build path make sure the libraries panel at the top is selected then select the Web App library and on the right click Add External JARS. You can go to your downloads folder and select the jsf-api-2.1.jar and refresh the project and you can now import that annotation.

Related

Cannot download sources from jar in intellij with maven

I want to debug my maven project. I add a dependency Test that I have developped like this:
<dependencies>
<dependency>
<groupId>com.company.group</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
when I debug my program and I enter into Test dependent method I see /* compiled code */. If I click on attach source It does nothing and if I click on download source, I get a pop up message saying:
Cannot download sources,
Sources not found for:
com.mycompany.group:test:0.0.1-SNAPSHOT
I also tried to execute :
mvn dependency:sources
But when I try to enter my dependent method I just see /* compiled code */
Do you have any idea?
It's not uncommon for sources to be unavailable for custom jars, since developers would have to explicitly create a source jar using the Maven Source
Plugin and install this jar in a remote repository. There's a Maven cookbook page for this as well.
If you have no way of adding sources for your dependencies, then I think your best bet would be to use a decompiler.

Importing a maven dependency using Struts 2 in Eclipse

I'm using eclipse with maven and I would like to include two struts tags :
<%# taglib prefix="s" uri="/struts-tags" %>
<%# taglib prefix="sj" uri="/struts-jquery-tags" %>
<%# taglib prefix="sb" uri="/struts-bootstrap-tags" %>
The problem is that the compiler says :
Can not find the tag library descriptor for "/struts-jquery-tags"
The library is correctly downloaded by maven through this declaration:
<dependencies>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.5.8</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<version>2.5.8</version>
</dependency>
<dependency>
<groupId>com.jgeppert.struts2.bootstrap</groupId>
<artifactId>struts2-bootstrap-plugin</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>com.jgeppert.struts2.jquery</groupId>
<artifactId>struts2-jquery-plugin</artifactId>
<version>4.0.1</version>
</dependency>
</dependencies>
The maven dependencies are in the project's build path.
Why the struts-jquery-tags is not imported ?
PS : when I add the struts-jquery-tags's jar manually, I have no errors.
(There is another post dealing with the same problem but the answers are not relevant in my case).
Make sure that your project is maven enabled. Right click on your project select configure and then convert to maven project.
Then make sure you have maven dependencies set correctly.
In the eclipse right click on your project and select Build Path > Configure build path ... The select Libraries tabs. Make sure you have the Maven Dependencies in the list of your libraries. If the it is not there select Add Liberary and then Maven Managed Dependencies
I hope this will be a Eclipse issue.
I guess you've created a Dynamic Web Project and then converted it to a Maven project. When a struts project created in this way there are chances of getting errors which you mentioned.
As long as your project is running smoothly in the deployed server you need not to pay attention towards these.
I suggest to create struts2 project from maven repository. If project created in this way these kind of errors can be avoided.
The jar file is available here. You have the problem of downloading/packaging jar file. struts-jquery-tags is not imported because the plugin is not available on classpath.
If you need additional info you can check docs Building with Maven.

Why does addition of MigLayout still give an error inspite of adding the MigLayout jar file in the libraries in netbeans 8.0?

Though I have configured the classpath and added the jar file in the library of the project , it still gives me an error as "package net.miginfocom.swing. does not exist".
What can I do to avoid this error?
You can use maven to automatically download MigLayout. Just click new project, select and maven from categories, then Java Application. Once created go into the "pom.xml" (within Project Files) and paste this under the properties section:
<dependencies>
<dependency>
<groupId>com.miglayout</groupId>
<artifactId>miglayout</artifactId>
<version>3.7.4</version>
</dependency>
</dependencies>
Then just build the project and maven will download and install MigLayout. Hope this helps.

NetBeans adding external library Vaadin Framework

How can I add external library to Vaadin framework using NetBeans?
I can't find libraries folder there. Additionally I want use pi4j library.
I haven't seen it there like in normal Java Application Libraries folder.
Looks like you are using Maven. In that case you have to edit your pom.xml file (you can find it in the Project Files folder in NetBeans).
Google for the Maven coordinates for the library you want to include and add the corresponding dependency section in the dependencies section. For example, to add Log4j, you must add the following in your pom.xml:
...
<dependencies>
...
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.5</version>
</dependency>
...
</dependencies>
...
Alternatively, you can right click the Dependencies folder in NetBeans, select Add Dependency..., and add the corresponding Maven coordinates or search for the dependency (keep in mind the Maven Index may be updated the first time you search for a dependency, process that might take some seconds/minutes).

The import org.apache.commons cannot be resolved in eclipse juno

I am having a problem while compiling my project in Eclipse. It is showing the error The import org.apache.commons cannot be resolved.
Please tell me what does this error means and how to solve it.
The mentioned package/classes are not present in the compiletime classpath. Basically, Java has no idea what you're talking about when you say to import this and that. It can't find them in the classpath.
It's part of Apache Commons FileUpload. Just download the JAR and drop it in /WEB-INF/lib folder of the webapp project and this error should disappear. Don't forget to do the same for Apache Commons IO, that's where FileUpload depends on, otherwise you will get the same problem during runtime.
Unrelated to the concrete problem, I see that you're using Tomcat 7, which is a Servlet 3.0 compatible container. Do you know that you can just use the new request.getPart() method to obtain the uploaded file without the need for the whole Commons FileUpload stuff? Just add #MultipartConfig annotation to the servlet class so that you can use it. See also How to upload files to server using JSP/Servlet?
If you got a Apache Maven project, it's easy to use this package in your project. Just specify it in your pom.xml:
<project>
...
<properties>
<version.commons-io>2.4</version.commons-io>
</properties>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${version.commons-io}</version>
</dependency>
</dependencies>
...
</project>
expand "Java Resources" and then 'Libraries' (in eclipse project).
make sure that "Apache Tomcat" present.
if not follow-
right click on project -> "Build Path" -> "Java Build Path" -> "Add Library" -> select "Server Runtime" -> next -> select "Apache Tomcat -> click finish
You could just add one needed external jar file to the project.
Go to your project-->java build path-->libraries, add external JARS.Then add your downloaded file from the formal website. My default name is commons-codec-1.10.jar
Look for "poi-3.17.jar"!!!
Download from "https://poi.apache.org/download.html".
Click the one Binary Distribution -> poi-bin-3.17-20170915.tar.gz
Unzip the file download and look for this "poi-3.17.jar".
Problem solved and errors disappeared.
You could also add the external jar file to the project.
Go to your project-->properties-->java build path-->libraries, add external JARS. Then add your downloaded jar file.
In my little experience, I have solved the issue about org.apache.commons.cli, on my Eclipse Version: 2019-12 (4.14.0):
In Provar(2.8.0), Issue got resolved after adding the jar file(commons-io-2.11.0.jar) to the project.
Steps:
1.Download the latest JAR file from https://commons.apache.org/proper/commons-io/download_io.cgi
Added jar file under lib folder in project.
2.Project--> Properties --> Java build path --> Libraries--Add Jars from lib folder.