使用不同的操作系统将项目从开发部署到生产的良好实践?

时间:2022-05-29 20:04:17

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 ?

我正在JSF完成一个项目,但现在我必须重新创建所有链接(例如localhost:8080 / project / recoverpassword到www.project.com/recoverpassword等等。所以我想知道是否有其他方法可以以更简单的方式做到这一点?

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 ?

另一件事是我正在使用Windows 7开发平台,这个项目将部署在Linux(可能是CentOS 6)中,路径完全不同,用于链接,图像,视频等,指的是本地内容当然(我认为在运行应用程序的地方以外会很昂贵地托管这些文件),'因为文件系统不同,这会导致问题,即使在JPA中的实体中引用的表的名称中使用数据库也是如此。所以这里的教训是,我必须开发我的项目,它将被部署?或者我错了?还有另一种方法可以解决这个问题吗?

Thanks.

谢谢。

3 个解决方案

#1


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.

我认为/ project是上下文路径。上下文路径确实是一个动态值,完全超出了Web应用程序项目的控制范围。

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:

#2


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.

你可以做的一件事是,例如设置复制目标环境的虚拟机。

#3


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,

我不久前遇到了你的问题。我自己的解决方案是创建一个Constants文件,我将所有依赖于系统的变量放在其中。例如,

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:

可以使用Constants.PROPERTY在任何@ManagedBean中访问上述类中的任何常量。如果您想访问.xhtml页面中的常量,可以创建具有类似内容的.properties文件:

// 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.xml中将此.properties文件声明为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}.

此时,您可以使用#{constants.PROPERTY}访问.xhtml页面中的常量。

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.

此外,当你处理文件名时,只需使用File.separator来分隔文件夹,你应该没问题: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? :)

我正在做的绝对不是最好的做法,但它是一种很容易实现你想要的方法:P。 BalusC的答案应该是处理这些组件时的最佳实践。那么也许混合动力应该很酷? :)

#1


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.

我认为/ project是上下文路径。上下文路径确实是一个动态值,完全超出了Web应用程序项目的控制范围。

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:

#2


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.

你可以做的一件事是,例如设置复制目标环境的虚拟机。

#3


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,

我不久前遇到了你的问题。我自己的解决方案是创建一个Constants文件,我将所有依赖于系统的变量放在其中。例如,

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:

可以使用Constants.PROPERTY在任何@ManagedBean中访问上述类中的任何常量。如果您想访问.xhtml页面中的常量,可以创建具有类似内容的.properties文件:

// 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.xml中将此.properties文件声明为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}.

此时,您可以使用#{constants.PROPERTY}访问.xhtml页面中的常量。

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.

此外,当你处理文件名时,只需使用File.separator来分隔文件夹,你应该没问题: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? :)

我正在做的绝对不是最好的做法,但它是一种很容易实现你想要的方法:P。 BalusC的答案应该是处理这些组件时的最佳实践。那么也许混合动力应该很酷? :)