留言板

How do you make OSGI copy JARs into the Project and External dependencies?

Zak Thompson,修改在7 年前。

How do you make OSGI copy JARs into the Project and External dependencies?

Junior Member 帖子: 70 加入日期: 16-6-13 最近的帖子
I've been looking at this blog trying to resolve some OSGI issues I'm having and I haven't been able to figure it out. Basically what I'm trying to do is include the apache commons fileuploader and declare it as an external dependency so I can use functionality from its JAR. There is a commons-fileupload.jar in the root of tomcat in the WEB-INF lib, so I think that method two or three from the blog link provided would be my best bet.

Here is my build.gradle:
dependencies {
	compile group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.0.0"
	compile group: "com.liferay.portal", name: "com.liferay.util.taglib", version: "2.0.0"
	compile group: "javax.portlet", name: "portlet-api", version: "2.0"
	compile group: "javax.servlet", name: "servlet-api", version: "2.5"
	compile group: "jstl", name: "jstl", version: "1.2"
	compile group: "org.osgi", name: "org.osgi.compendium", version: "5.0.0"
	compile group: "commons-fileupload", name: "commons-fileupload", version: "1.2.1"
}


Here is the bnd.bnd
Bundle-SymbolicName: audit.uploader
Bundle-Version: 1.0.0
Web-ContextPath: /auditupload


When I build or deploy my portlet from the gradle tasks, everything compiles fine and the portlet is deployed correctly, so since I receive no errors I'm assuming that it is correctly using commons-fileupload as a dependency. However, the commons-fileupload JAR is never put into the Project and External Dependencies folder so I'm unable to use its functionality.

I'm guessing there is something I have to add to my build.gradle or bnd.bnd to make it copy the JAR, but I'm unsure of what that step is.
thumbnail
David H Nebinger,修改在7 年前。

RE: How do you make OSGI copy JARs into the Project and External dependenci

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
Zak Thompson:
Basically what I'm trying to do is include the apache commons fileuploader and declare it as an external dependency so I can use functionality from its JAR.


Zak, you're in luck. Liferay already includes commons-fileupload version 1.3.1 as a global dependency; you don't have to worry about including it yourself. Just make sure to use the "provided" keyword instead of "compile" in build.gradle dependencies.







Come meet me at the LSNA!
Zak Thompson,修改在7 年前。

RE: How do you make OSGI copy JARs into the Project and External dependenci

Junior Member 帖子: 70 加入日期: 16-6-13 最近的帖子
I changed my build.gradle to be the following:

build.gradle
dependencies {
	compile group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.0.0"
	compile group: "com.liferay.portal", name: "com.liferay.util.taglib", version: "2.0.0"
	compile group: "javax.portlet", name: "portlet-api", version: "2.0"
	compile group: "javax.servlet", name: "servlet-api", version: "2.5"
	compile group: "jstl", name: "jstl", version: "1.2"
	compile group: "org.osgi", name: "org.osgi.compendium", version: "5.0.0"
	provided group: "commons-fileupload", name: "commons-fileupload", version: "1.3.1"
}


Now I'm getting the following error while attempting to build:

FAILURE: Build failed with an exception.

* Where:
Build file 'X:\Liferay7\Workspace\liferay\modules\audit-uploader\build.gradle' line: 8

* What went wrong:
A problem occurred evaluating project ':modules:audit-uploader'.
> Could not find method provided() for arguments [{group=commons-fileupload, name=commons-fileupload, version=1.3.1}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED


Is there some configuration I need to do to make the global dependencies available? My current project is based on the Liferay IDE and I've only used it to do my tasks, I've done no manual BLADE configuration, its all what's been generated by the IDE.
thumbnail
David H Nebinger,修改在7 年前。

RE: How do you make OSGI copy JARs into the Project and External dependenci

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
Sorry, I keep forgetting, I use the nebula.provider-base plugin for the "provided" scope.

Add the following to your build.gradle file:

plugins {
  id "nebula.provided-base" version "3.1.0"
}


As long as you have a recent version of gradle it should pull it in. Otherwise you might check out the plugin page: https://plugins.gradle.org/plugin/nebula.provided-base






Come meet me at the LSNA!
Zak Thompson,修改在7 年前。

RE: How do you make OSGI copy JARs into the Project and External dependenci

Junior Member 帖子: 70 加入日期: 16-6-13 最近的帖子
I was able to get commons-fileupload into the module bundle and upon opening the module jar with 7zip, the commons-fileupload jar was included inside. I was able to import and create Objects from the JAR in my java file, and everything works when the module is deployed. However, Eclipse is putting red lines under everything from commons-fileupload because it is not in the Project and External Dependencies folder in Eclipse. Is there any way to get the JAR added to there for code completion, or should I just manually add the JAR to the build path during development for code completion, and then remove it from the buildpath once development is complete.
thumbnail
David H Nebinger,修改在7 年前。

RE: How do you make OSGI copy JARs into the Project and External dependenci

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
After changing build.gradle, you usually have to select the project, right click and choose Gradle -> Refresh Gradle Project. This should build the Eclipse project back in sync with the stated dependencies.





Come meet me at the LSNA!
Zak Thompson,修改在7 年前。

RE: How do you make OSGI copy JARs into the Project and External dependenci

Junior Member 帖子: 70 加入日期: 16-6-13 最近的帖子
Awesome, that did the trick. Thanks for all your help!