1

When I do this it doesn't compile when I run build.xml and deploy,

I want to do this as it looks much nicer than a huge method call with JournalArticleLocalServiceUtil.addArticle.

JournalArticle journalArticle = new JournalArticleImpl();
journalArticle.setDescription(description);

Does anyone know if it is possible in Liferay 6?

Edit: This is the output I get:

Buildfile: C:\opt\liferay-six1-dev\code\portlets\migration-portlet\build.xml
compile:
merge:
compile-java:
    [javac] Compiling 1 source file to C:\opt\liferay-six1-dev\code\portlets\migration-portlet\docroot\WEB-INF\classes
    [javac] C:\opt\liferay-six1-dev\code\portlets\migration-portlet\docroot\WEB-INF\src\com\liferay\migration\importdata\JournalArticleImport.java:138: cannot find symbol
    [javac] symbol  : class JournalArticle
    [javac] location: class com.liferay.migration.importdata.JournalArticleImport
    [javac]     private JournalArticle createJournalArticle(ExportedJournalArticle article) {
    [javac]             ^
    [javac] C:\opt\liferay-six1-dev\code\portlets\migration-portlet\docroot\WEB-INF\src\com\liferay\migration\importdata\JournalArticleImport.java:142: cannot find symbol
    [javac] symbol  : class JournalArticle
    [javac] location: class com.liferay.migration.importdata.JournalArticleImport
    [javac]         JournalArticle journalArticle = new JournalArticleImpl();
    [javac]         ^
    [javac] C:\opt\liferay-six1-dev\code\portlets\migration-portlet\docroot\WEB-INF\src\com\liferay\migration\importdata\JournalArticleImport.java:142: cannot find symbol
    [javac] symbol  : class JournalArticleImpl
    [javac] location: class com.liferay.migration.importdata.JournalArticleImport
    [javac]         JournalArticle journalArticle = new JournalArticleImpl();
    [javac]                                             ^
    [javac] 3 errors

BUILD FAILED
C:\opt\liferay-six1-dev\code\build-common-plugin.xml:403: The following error occurred while executing this line:
C:\opt\liferay-six1-dev\code\build-common.xml:94: Compile failed; see the compiler error output for details.

Total time: 1 second
Elizabeth Hamlet
  • 170
  • 3
  • 10
  • 1
    You claim it doesn't compile, but it looks to me like it should. What happens when you try? – Jon Skeet Jan 25 '12 at 09:40
  • edited question, when I run build.xml and deploy – Elizabeth Hamlet Jan 25 '12 at 09:42
  • You still haven't said what *does* happen... or whether you're able to compile in other ways. Please read http://tinyurl.com/so-hints - if you can avoid us having to guess what's going on, you're bound to get to an answer more quickly... – Jon Skeet Jan 25 '12 at 09:49
  • The class its states is missing is not missing – Elizabeth Hamlet Jan 25 '12 at 10:04
  • 1
    Well, so you say... what does your build.xml look like? Where are you telling it about the liferay libraries? – Jon Skeet Jan 25 '12 at 10:05
  • Generally with Liferay (if you're using the Plugins-SDK) then the build.xml of a portlet inherits properties from a file on the root of the SDK. This properties file contains the path to the Liferay Classpath which the JAR containing this class will be on. – Jonny Jan 25 '12 at 10:11

2 Answers2

2

As Jon mentions the library/jar for the implementation classes are not copied if you're using the Plugins SDK. Unfortunately you are not allowed to create the JournalArticle object directly from a plugin and you must use the JournalArticleLocalServiceUtil to have the object created.

rp.
  • 3,435
  • 1
  • 21
  • 29
1

Okay, now that we've got the compiler failure, it looks like you just haven't got the right libraries on the classpath.

Also, it looks like you're creating your own classes under the com.liferay package - you shouldn't be doing that unless you're building code for Liferay. If you're only building code which uses Liferay, you should be building it under your own organizational package.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • the thing is they are correct, as I am using them elsewhere! I can create the object using a constructor, just not this way. Doesn't make sense – Elizabeth Hamlet Jan 25 '12 at 10:04
  • @ElizabethHamlet: What do you mean by "elsewhere"? Elsewhere in the same build? Note that you're *already* using a constructor, so it's not clear what you mean. It would really help if you could give us more information - ideally a short but *complete* sample of code which works, and a similar short but complete sample of code which doesn't work. (The whole class, including imports. It doesn't need to do anything useful.) – Jon Skeet Jan 25 '12 at 10:06
  • Yes in the same build. By constructor it works if I call JournalArticleLocalServiceUtil.addArticle(userId, groupId, articleId, autoArticleId, version, title, description, content, type, structureId, templateId, displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, expirationDateMonth, expirationDateDay, expirationDateYear, expirationDateHour, expirationDateMinute, neverExpire, reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour, reviewDateMinute, neverReview, indexable, smallImage, smallImageURL, smallFile, images, articleURL, serviceContext); – Elizabeth Hamlet Jan 25 '12 at 10:11
  • I am using my own organisation path, but I removed it when posting online – Elizabeth Hamlet Jan 25 '12 at 10:18
  • 2
    @ElizabethHamlet: Please edit your *question* rather than putting code in comments. Note that the code in your comment *isn't* calling a constructor - it's calling an `addArticle` *method*. The code in your question *is* calling a constructor. Also, it's fine to use some dummy package name for a short but complete example - but making it start with `com.liferay` is just adding to the confusion. – Jon Skeet Jan 25 '12 at 10:20
  • its just a short sample.. and yes technically it is a method not a constructor, I was thinking in terms of creating a JournalArticle object, as that is what it is doing, my mistake, but that's just a technicality. The point is I wanted to do it a neater way, by creating an Empty Journal Article object (empty constructor) and setting each part), and ok I didn't add a dummy name.. – Elizabeth Hamlet Jan 25 '12 at 10:31
  • @ElizabethHamlet: It's not "just a technicality" - it completely goes against what you'd been asking for. You'd been asking for a way of doing it without calling a constructor, giving sample code which *does* call a constructor - and showing existing *working* code which *doesn't* call a constructor. That's incredibly confusing. Again, please edit your *question* with short but complete sample classes: one which works, and one which doesn't. You should include all the imports you use, and the complete error messages. – Jon Skeet Jan 25 '12 at 10:37