Loading resources in a plug-in works in eclipse but not for maven - resources

I am trying to load resources with the platform URL approach in an e4 RCP application.
This works fine for my application plug-in. But I have got a second plug-in which extends the application via fragments. In this plug-in this approach
platform:/plugin/<name>/<path>
does not work. If I start the project from eclipse though, the resources can be loaded.
What could I be doing wrong?
The build.properties content of the plug-in is as follows:
source.. = src
bin.includes = META-INF/,\
.,\
plugin.xml,\
fragment.e4xmi,\
res/

The problem was:
The Maven build is case sensitive for file names, while eclipse is not.
new URL("platform:/plugin/name/res/myfile.txt")
new URL("platform:/plugin/name/res/myFile.txt")
In eclipse, both versions are working; from maven build, only the second version.
This seems quite strange to me. It would be great if anyone could explain this.

Related

I create a project and don't find the javax.servlet when I use eclipse

I generated a maven project and imported my entities. the aplicattion work perfect but if I close the IDE(eclipse) and I open again . it's said me this error.
I don't touch anythings on code. I don't understad why don't work.
https://ibb.co/NVgTb8Hn (the picture)
thanks
I think you should try with
with Maven IDE profile
If you are using Maven, you need to activate the IDE profile in Eclipse. This is used for applying IDE-specific tweaks, which currently only includes applying the MapStruct annotation processor.
Right click on Project -> Properties -> Maven
In “Active Maven Profiles”, type dev,IDE
With this configuration, you will be using both the JHipster dev and IDE profiles.

where is war exploded in Liferay 7 tomcat after getting copied in osgi folder

I deployed a portlet in liferay 7 and it got deployed successfully and was available for use. I want to replace the jsp file, in earlier version I could see my application in tomcat/webapps folder and replace it quickly.
Now I am unable to locate the exploded war in liferay 7. I can only see the war in osgi/war folder.
Can someone help me with that.
Thanks in advance.
While I mostly agree with what Olaf wrote, I do understand the need to be able to make changes in JSP files and try them quickly during development. I'm afraid I don't have the solution for that yet.
However, let me answer the question you asked:
where is war exploded in Liferay 7 tomcat after getting copied in osgi folder
It is NOT (at least not the way it was done by application servers)! When you deploy a WAR file in Liferay 7, it will automatically (on the fly) convert it into OSGi bundle and install it in OSGi runtime. This way now Liferay is fully in charge of deploying plugins and does not need to rely on various application servers.
PLEASE NOTE: Every bundle has it's own state folder. In Liferay those are in <LIFERAY_HOME>/osgi/state. If you know the bundle ID you can easily find it. It may be (I haven't checked) that you'll find some JSP files there. The reason I'm writing this is to warn you (in case you figured it yourself) to NEVER modify bundle's state folder manually. Doing so may brake the whole environment. In worse case scenario you may have to redeploy everything in clean environment.
You should not rely on behavior like this. In previous versions it was the task of the application server to compile changed JSPs at runtime. However, this is bad practice in production systems and totally screws up your maintainability. If you need to update some UI code frequently, I'm suggesting you change your implementation to utilize ADT (Application Display Templates), e.g. through Freemarker or Velocity. Those are meant to be updated at runtime, where the JSP updates were a side effect of Tomcat's default (development friendly, production hostile) configuration

How to get Eclipse EE to build classes in WEB-INF/classes (or better approach)

The default for Eclipse EE seems to be to build java code in build/classes not in WEB-INF/classes or WEB-INF/lib/my.jar. I can create a .war file which has the entire project, but then every time I build, I have to manually generate the war file. My current setup which has the WebContents directory symbolic linked to /var/lib/tomcat7/webapps/ROOT, in which case all the web pages are by definition in the right place, but the code is not there.
I'm willing to take a suggestion on how to get this to happen automatically, but I would like to know WHY there should be the need in the first place? Why would I want to have my build directory for a web application anywhere other than the directory where it should be executed? Is there any way to get eclipse to build the !%*#% class files in a sane place, or is there in fact a reason why an EE app would have code that does not go on the server? Is there something simple that I can add to trigger a rule in ant or mvn to move the code to the right place?
Compounding this problem, I am switching over to Ubuntu (Not that this works under windows at the moment either).
I was getting weird errors, and it turns out I didn't have jdk7 installed.
So I installed it, but how do I even know what java is being used to run tomcat and eclipse? How do I know it will use jdk7 and not the one that was used before? On windows, when I tried to run Eclipse, it gave a straightforward error when Java wasn't installed so this never happened.
I type javac -version and get the correct one, but this does not guarantee that some service like tomcat7 will use the same one.
The error (same on Windows)
An error occurred at line: 3 in the jsp file: /demos/post.jsp
ReadBody cannot be resolved to a type
1: <%# page import="org.adastraeducation.liquiz.servlet.*" %>
2: <%
3: ReadBody b;
4: %>
5: <html>
6: <body>
The current (ridiculous) way to stop this error is:
cd build/classes
jar -cf my.jar org
sudo mv my.jar /var/lib/tomcat7/webapps/ROOT/WEB-INF/lib
sudo service tomcat7 restart
Eclipse Web Tools can manage building and packaging a web-app (WAR) and automatically running it on a local server of your choice. This includes re-deployment when changes are made, debugging, etc. But you have to create or configure your project as a Dynamic Web project for Eclipse to know to do that for you.
For starters, you'll need to either download the Eclipse IDE for Java EE Developers package or use the Eclipse Installer to get it. Then you can peruse the Web Tools help (for example, start here).

Is it possible to have Liferay SDK in different location than the source codes?

I'd like to ask you for best practices with developing with Liferay SDK.
I have the SDK downloaded, I have Eclipse ready, it works, I can create new portlets and run local Liferay instance to test it.
Here is my situation - all the source code I have is in the Eclipse workspace, currently it is only portlets what I'm working on.
Liferay SDK I have in completely different location than workspace. Let's say ~/dev/liferay_sdk.
Eclipse workspace is located in ~/workspace.
At the beggining, it was not working like that. Eclipse from some reason can't find or use Liferay SDK. When I changed "Project validation" in Eclipse/Liferay configuration to "Ignore" the "Liferay Plugin SDK is not valid", it started to work without problems.
Next problem happend when it comes to need to build a WAR for example.
In the portlet directory in the workspace is present "build.xml" file. But inside it refers to another xml file, which should be located one directory up, and this one refers to more thing in relatively location and so on.
In short, it assumes that you have the portlets etc, inside the Liferay SDK.
Like "~/dev/liferay_sdk/portlets".
My question is, Am I wrong completely, or could you suggest me the best practices with this?
I don't want to mix SDK and the code, it sounds wrong to me.
Thanks for help!
I think, the best practice is still when your portlet projects are located inside the Liferay Plugins SDK directory. That way you can take all the advantages of the Liferay IDE plugin for Eclipse, for example. Because as far as I understand Liferay IDE will not allowed you to have portlet projects in another location. It's pretty easy to import projects to Eclipse from inside the Liferay SDK directory, and that's not problem.
But I also faced the same sort of problem when tried to save portlet project to the Git repository. Possible solutions with symbolic links didn't work correctly on every system. Thus I slightly modified the build.xml file to be able to run ant tasks from any directory. For portlets it was something like that:
<project name="your-portlet" basedir="." default="deploy">
<property file="build.properties" />
<property name="project.dir" value="${liferay.sdk.home}" />
<import file="${project.dir}/build-common-plugin.xml" />
</project>
Notice that you should define property "liferay.sdk.home" in build.properties and it should be path to the Liferay Plugins SDK.
As for other types of Liferay plugins (themes, hooks, etc.) you should import another build file for building that type of plugin. For example, for themes it will be:
<import file="${project.dir}/themes/build-common-theme.xml" />
Hope you'll get the idea. :) But think twice before doing something like that.
Liferay plugins are developed inside the Liferay Plugins SDK, its called SDK for a very good reason.
I don't find anything wrong with the plugins-SDK and the code tied togather, below are few reasons why:
If you see the liferay repository of plugins on github, you would find all the sample portlets and other plugins are stored in their respective folders inside plugins-SDK.
So if you want to develop liferay plugins (with or without IDE), the best practice (the only efficient way I think) is to have the projects created inside the respective folders of plugins SDK like portlet projects inside portlets folder, hook project inside hooks folder etc.
If you have used Liferay IDE when you create a plugin project (Liferay project) in this IDE you specify the SDK and the server runtime and what it does is it creates the project inside your Plugins SDK and copies the .settings, .classpath & .project file inside the project created. It does not create the project inside your workspace as eclipse normally does for other projects.
Hope I have managed explain it clearly and this was what you wanted.
I'm already quite happy with the other answers, this could have been distributed through comments at those, but a separate answer gives some more structuring options:
As Prakash says, it's not really bad to do that. In addition to his answer, you do not need to have your code in the workspace directory. Eclipse is happy to put it anywhere in the filesystem - thus while you work with Eclipse you don't even care where exactly your code is (and as you check it into version control - right? - you actually never need to care.
If you want to use Liferay's OOTB ant scripts: They are geared towards exactly the setup you describe: Work in the SDK directory. It's actually not bad, but if you don't like it, you just have to accept that you can't work with build.xml without changing it (like Artem suggests).
Another option is to use maven - this also bypasses the sdk (and the Liferay IDE integration), so you're again free to put your sourcecode whereever you like and let maven do the rest.
I can imagine some rather esoteric and rare issues with Artem's suggestion (like referring to custom parent themes when you imply some relative position) but I consider that as extremely minor, so if that works for you: Go ahead. Just keep in mind that you don't fulfill the basic assumptions that the SDK makes, so you might have to change things that violate the assumptions. I can't imagine this being too hard if you keep this in mind.
Of course, what you miss with that solution is the neat handling of including build.${username}.properties - you'll have to have your own build.properties that define ${liferay.sdk.home}. If you're not working in a team, that's ok. Otherwise you'll have to invent this yourself (and code it) or rely on global parameters to be configured with every team member.

Groovy class files not included in deployment

I have two java projects, A and B, A depends on B. In project B I've added a groovy class (Foo.groovy) and a java class (Bar.java) that uses the groovy class. In MyEclipse, Foo.class is in bin-groovy, and I can run things from MyEclipse just fine. However, when MyEclipse deploys project A to tomcat, it does not include the Foo.class file so Bar.java can't run. If I manually copy Foo.class to tomcat, it works just fine. Is this just a MyEclipse issue? It's driving me crazy because all that needs to happen is to have the .class files from the groovy classes get included on a deploy, it seems like that should be an easy configuration, but I have not found a solution for this yet.
Where are the missing files in the source structure? Are they in grails-app or src/groovy?
When you deploy via CL what happens (i.e. grails war or similar command)

Resources