2 Attachment(s)
Problem building first JSF application sample on "Core JSF 3th"
Greetings EveryOne ;D
I'm making my first steps toward learning JSF. I found this interesting book called "Core JavaServer Faces Third Edition".
At page 10, the book gives you instructions to build your first JSF application. Here quoting those instructions:
Quote:
Here are the build instructions for the sample JSF application.
1. Launch a command shell.
2. Change to the corejsf-examples directory—that is, the directory that contains
the sample code for this book.
3. If you use GlassFish or another Java EE 6 compliant application server,
change to the javaee subdirectory. If you use Tomcat, change to the tomcat
subdirectory.
4. Change to the source directory and make the directory for holding the
class files:
cd ch01/login/src/java
mkdir ../../web/WEB-INF/classes
On Windows, use backslashes as file separators.
5. If you use GlassFish, run
javac -d ../../web/WEB-INF/classes -classpath .:glassfish/modules/\*
com/corejsf/UserBean.java
On Windows, use a semicolon in the classpath, and don’t escape the *
wildcard:
javac -d ..\..\web\WEB-INF\classes -classpath .;glassfish\modules\*
com\corejsf\UserBean.java
If you use Tomcat, use the following command to compile your code:
javac -d ../../web/WEB-INF/classes -classpath .:jsf-ref-impl/lib/jsf-api.jar
com/corejsf/UserBean.java
6. If you use Tomcat, you need to include the JSF libraries:
mkdir ../../web/WEB-INF/lib
cp jsf-ref-impl/lib/*.jar ../../web/WEB-INF/lib
Skip this step if you use a Java EE 6 compliant application server.
7. Run the following commands (and note the period at the end of the jar
command, indicating the current directory):
cd ../..
jar cvf login.war .
At this moment i'm working on windows, when i implement the 5th instruction, this is a snap of my cmd:
Attachment 4072
Can you tell me why javac complaining about "no source file"?
Thank You In Advance ;D
P.S: - I had created a directory called "class" not "classes", just to tell you that my path is correct.
- Please ignore the snap bellow, i can't remove it.
Re: Problem building first JSF application sample on "Core JSF 3th"
Any Advice? Any Suggestion? Please I Need Help with this.
Re: Problem building first JSF application sample on "Core JSF 3th"
Greetings EveryOne ;D
I found an answer to my problem and i want to share it with whom it may concern, you can find the answer here:
java - package javax.inject does not exist - Stack Overflow
After successfully compiling the source code, creating the WAR file (web archive), deploying it with glassfish i was getting this error, when submitting the user name and hitting the login button:
Code:
/index.xhtml @15,55 value="#{user.name}": Target Unreachable, identifier 'user' resolved to null
This is the UserBean.java:
Code:
package com.corejsf;
import java.io.Serializable;
import javax.inject.Named;
// or import javax.faces.bean.ManagedBean;
import javax.enterprise.context.SessionScoped;
// or import javax.faces.bean.SessionScoped;
@Named("user") // or @ManagedBean(name="user")
@SessionScoped
public class UserBean implements Serializable {
private String name;
private String password;
public String getName() { return name; }
public void setName(String newValue) { name = newValue; }
public String getPassword() { return password; }
public void setPassword(String newValue) { password = newValue; }
}
After a lot of thoughts, I found out my problem was in the directory structure of the WAR file:
The wrong structure:
Code:
login.war
|
|--- index.xhtml
|--- welcome.xhtml
|
|--- WEB-INF
|
|--- beans.xml
|--- web.xml
|--- classes
|
|--- UserBean.class
In an enlightenment moment i said maybe the problem was in not respecting the package structure of the source code, and i was right it worked perfectly.
This is the right directory structure of the WAR file:
Code:
login.war
|
|--- index.xhtml
|--- welcome.xhtml
|
|--- WEB-INF
|
|--- beans.xml
|--- web.xml
|--- classes
|--- com
|--- corejsf
|--- UserBean.class
I hope this would make it easier for someone else.