1

I'm finishing one project in JSF, but now I have to recreate all links (like localhost:8080/project/recoverpassword to the www.project.com/recoverpassword for instance and many others. So I wonder if there's any other way to do that in a easier way ?

Other thing is that I'm using Windows 7 to development plataform and this project is gonna be deployed in Linux (probably CentOS 6) and the paths are totally different, for links, for image, for video, etc, referring to the local content of course (I think would be expensive host these files outside where the application is running), 'cause the file system is different, this 'cause problems even with database in names of tables that are referred in entities in JPA. So the lesson here is that I HAVE to develop my project where it's gonna be deployed ? Or am I wrong ? There's another way to work around this issue ?

Thanks.

Valter Silva
  • 16,446
  • 52
  • 137
  • 218

3 Answers3

1

You should always have the same environment for developing, testing and for production.

Otherwise, tracking faults becomes a nightmare as you might not now if they are caused by the environment or your own software.

One thing you could do is e.g. setting up virtual machines replicating the target environment.

DotNetDeveloper
  • 493
  • 1
  • 6
  • 16
1

I gather that /project is the context path. The context path is indeed a dynamic value, completely beyond the control of your web application project.

You should not have the need to recreate all links if you have from the beginning on properly used:

The mentioned tags automatically prepend the current context path when necessary. In other words, you should never have had the need to hardcode the string /project representing the context path anywhere in the code.

Pick together yourself, bite the bullet, take a full day to fix them all in the current project and profit of the lesson learnt for future projects.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • BalusC, what did you recommend to upload of photos, videos ? Where did you store them and make proper link using `` or `` ? I would like to store them locally then upload to some image/video server, for better privacy policy in my project. – Valter Silva Apr 18 '13 at 12:50
  • For save, make the save folder configurable as system property, environment variable or propreties file setting. E.g. http://stackoverflow.com/questions/14915887/path-inside-an-web-app-not-a-direct-link/14917577#14917577 For streaming, let the server admin make a virtual host on that folder and set its root URL as another system property, environment variable or properties file setting, so that you can use it in your code. – BalusC Apr 18 '13 at 12:55
0

I faced your problem some times ago. The solution I had for myself was to create a Constants file where I put all the system-dependent variable inside. For example,

public class Constants {
    // Local development
    private static final String PHOTO_FOLDER = "C:\path\to\photos\Windows";
    private static final String APP_PATH     = "localhost:8080/project/";

    // Online server
    private static final String PHOTO_FOLDER = "/path/to/photos/Linux";
    private static final String APP_PATH     = "www.project.com/";
}

Any constants in the above class can be accessed in any @ManagedBean using Constants.PROPERTY. In case, you want to access your constants inside your .xhtml pages, you can create a .properties file with similar content:

// Local development
PHOTO_FOLDER = C:\path\to\photos\Windows
APP_PATH     = localhost:8080/project/

// Online server
PHOTO_FOLDER = /path/to/photos/Linux
APP_PATH     = www.project.com/

Then declare this .properties file in your faces-config.xml as a ResourceBundle:

<faces-config version="2.0"
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
    <application>

        <resource-bundle>
            <base-name>your_package.constants</base-name>
            <var>constants</var>
        </resource-bundle>

    </application>
</faces-config>

At this point, you can access your constants in .xhtml pages using #{constants.PROPERTY}.

Depend on where you're deploying the app, just comment out the unnecessary lines :).

Besides, when you're dealing with file names, just use File.separator to separate the folders and you should be fine :P.

What I'm doing is definitely NOT the best practices, but it's a pretty easy way to achieve what you want :P. BalusC's answer should be the best practices at the moment while dealing with those components. So perhaps a hybrid should be cool? :)

Mr.J4mes
  • 9,168
  • 9
  • 48
  • 90