掲示板

Where I place constants with Service Builder?

thumbnail
11年前 に Mariano Ruiz によって更新されました。

Where I place constants with Service Builder?

New Member 投稿: 10 参加年月日: 10/11/05 最新の投稿
I make a portlet with customs models and services, and I used the service builder to make the project.

I make a constant like this in a *ServiceBaseImpl class:

public static final String CLIENTDOCUMENT_NEW_CODE = "CDN";

But, when I compile the project, I obtain a nice *-portlet.jar with a ServiceUtil class with the same method to access to the logic into the *ServiceBaseImpl class, and that allow to me publish the service in other portlets as you know.

The problem is, how I publish my constant PROCESSDOCUMENT_NEW_CODE with the service builder without boxing in a function?, just the constant, like this class in the kernel classes of liferay: com.liferay.portal.kernel.util.Constants

I want access to that constant directly. Maybe I need put the constant in other class, some like MyConstants.java, but, where put that to be published with the service builder in the *portlet.jar?
thumbnail
11年前 に Jan Geißler によって更新されました。

RE: Where I place constants with Service Builder?

Liferay Master 投稿: 735 参加年月日: 11/07/05 最新の投稿
I usually place my Constant Files in docroot/WEB-INF/service/my.packackge.path.service.constants

this way the Constant classes get exported in the service.jar file.
thumbnail
11年前 に Mariano Ruiz によって更新されました。

RE: Where I place constants with Service Builder?

New Member 投稿: 10 参加年月日: 10/11/05 最新の投稿
Jan Geißler:
I usually place my Constant Files in docroot/WEB-INF/service/my.packackge.path.service.constants

this way the Constant classes get exported in the service.jar file.



Yea works, but, I thought that the docroot/WEB-INF/service folder only contains auto generated classes by the service builder, and is not good practise put custom source code there.
thumbnail
11年前 に Jan Geißler によって更新されました。

RE: Where I place constants with Service Builder?

Liferay Master 投稿: 735 参加年月日: 11/07/05 最新の投稿
But if you want to expose your classes via the generated library you have no other choice. Even the Portal-Core does it this way, so it can't suuuuch a bad practise I guess. ;)
thumbnail
11年前 に David H Nebinger によって更新されました。

RE: Where I place constants with Service Builder?

Liferay Legend 投稿: 14916 参加年月日: 06/09/02 最新の投稿
It's not good practice to modify any of the generated code or move things around, etc., because future versions of Liferay may end up somehow interfering w/ your code...

I'd avoid putting a java file anywhere in the package path that Liferay is creating, but it's okay to include other sources in there... So if SB is writing code to com.example.service package, it should be okay in the long haul to put code into a com.example.constants package.

One thing to be aware of - "ant clean". I believe that the whole WEB-INF/service folder may get deleted on "ant clean". That would mean your code, the code you put into com.example.constants, would also get deleted.

Just saying, you need to be mindful of what code you put in there and have some way to recover it should "ant clean" throw it away...
thumbnail
11年前 に Jan Geißler によって更新されました。

RE: Where I place constants with Service Builder?

Liferay Master 投稿: 735 参加年月日: 11/07/05 最新の投稿
But putting constants in there should not be a problem. Execept you run an ant-clean, right? I mean, you don't mess around with generated code, you just add something in there, right?
thumbnail
11年前 に David H Nebinger によって更新されました。

RE: Where I place constants with Service Builder?

Liferay Legend 投稿: 14916 参加年月日: 06/09/02 最新の投稿
Well, all of the packages and sub packages are generated by SB, which means it is up to SB as to what packages to generate. I don't know, but what if the next version (or the one after that) all of a sudden starts creating a my.package.path.service.Constants class... You wouldn't necessarily know about it (until compiling your other code failed), and then you'd be faced with some rework...

It's not something that I know will happen, but as it is something that could conceivably happen, I keep code outside of the SB area. Just as a precaution, more or less.