Adding self-written jar to Eclipse Plug.In - jar

So I am trying to use a method from another project in an Eclipse Plug-In. I have added said project as a jar to a "lib" folder in my Plug-In Project.
In the build.properties' Runtime tab I then used "Add..." in the classpath-menu to add said jar (the library "." is also added as second in the list).
In the build.properties' Build tab i then added the jar to the binary build. When I take a look at the Manifest the jar is also listed in the Bundle-ClassPath.
When I then proceed to implement the logic, autocompletion will provide me with the name of the class I wanted to use from the jar, but it won't show any methods. The only suggestions availabe are "this" and "class", but I need to use a static method (and of course the compiler is giving me a hard time).
My MANIFEST.MF looks like this:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: MyView
Bundle-SymbolicName: MyView;singleton:=true
Bundle-Version: 1.0.20170806
Bundle-Vendor: FHDW
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ui
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ClassPath: lib/TheDesiredJar.jar,
.
I am using Oxygen Release (4.7.0)
Any help would be really appreciated.

Related

Create external jar file and add to Netbeans 8.2

We have been trying to create JAR files from the LanguageTool (LT) Desktop version we downloaded that contains various JAR files. LT at this link made the statement that we needed all the files in these folders libs org and META-INF in our project. LT has repied they have no experience with Netbeans or JavaFX.
LT Directions
The app was built on Windows 7 with Netbeans 8.2 as a JavaFX 8 and Maven JDK 1.8
We tried following this tutorial the author was not much for proper code formatting and failed to mention that LT is not thread safe. We seldom work with threads but think our code is correct?
TUTORIAL
To install the Class AmericanEnglish.class which is in the LT Desktop zip file we extracted we used this process
cd C:\Users\Me\Documents\A A A A A LT UnZip\LanguageTool-4.7\LanguageTool-4.7
jar cf languagesLIBS.jar libs/*
jar cf languagesORG.jar org/*
jar cf languagesMETA.jar META-INF/*
Here is where it gets odd to our limited knowledge of adding Dependencies to Netbeans
1. Open the Projects tab.
2. Right-click on Dependencies.
3. Select Add dependency.
4. Set groupId to: language(can be anything)
5. Set artifactId to: en (can be anything)
6. Set version to: 4.7(can be anything)
7. Click Add to continue.
Dependency is added to pom.xml and appears under the Libraries node of Maven project. Continue:
1. Expand Dependencies.
2. Right-click on library (e.g., group.id).
3. Select Manually install artifact.
4. Set Artifact to install with the Java Archive (.jar) file path.
5. Click Install locally.
This process did place the AmericanEnglish.class in a JAR and it is found by Netbeans
import org.languagetool.JLanguageTool;
import org.languagetool.language.AmericanEnglish;
import org.languagetool.rules.RuleMatch;
Here is the error when we try to populate the JLanguageTool with AmericanEnglish
While the error NoClassDefFoundError would seem to indicate that the app can not find the
AmericanEnglish.class and that is the cause of the error ClassNotFoundException
Our question obviously is how do we fix this ?
And are we crating the external JAR files correctly?
Exception in thread "Thread-4" java.lang.NoClassDefFoundError: com/google/common/cache/CacheLoader
at com.mycompany.maventest.CheckSpellController.lambda$ini$0(CheckSpellController.java:43)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: com.google.common.cache.CacheLoader
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
We also see these warnings when we Clean and Build the project
The POM for languagetool:LIBS:jar:4.7 is missing, no dependency information available
The POM for languagetool:ORG:jar:4.7 is missing, no dependency information available
The POM for languagetool:META:jar:4.7 is missing, no dependency information available
exec-maven-plugin:1.2.1:exec (unpack-dependencies) # mavenTEST
When the Clean and Build is run we see the dependencies unpack
Here is the few lines of code that cause the error
static JLanguageTool langTool;
public void ini(){
new Thread(() -> {
langTool = new JLanguageTool(new AmericanEnglish());
}).start();
}
The ini() method is called from the initialize method
The necessary JAR files are in the Dependencies folder
The project imports these files
You need to use the actual JAR and the process where you thought it was a bit ODD
Is not the correct way to add JAR files. The extracted ZIP folder has all the gold or should we say JAR's. Here are a few screen shots and directions. That said we are still getting the NoClassDefFoundError so we will work on fixing that part of the question
Delete the three JAR's you added LIBS-4.7.jar META-4.7.jar and ORG-4.7.jar
We would also suggest opening the .m2 folder and under /repository/org/languagetool delete the languagetool folder. Do NOT worry everything will get recreated.
Right Click Dependencies folder and select Add Dependency
In the Query text field enter "org.languagetool"
Here is a comment we did not find languagetool 4.7 JAR's as central only local ? ?
You might like to try and use the central 4.6 JAR's
Expand the org.languagetool:languagetool-core folder and select the 4.7.jar
Once that JAR is in the Dependency folder Right Click ad select Copy Location
Now Right Click the same JAR once more and select Manually Install Artifact
In the Artifact To Install text box paste with a Ctrl + V
This will take you to the location of the JAR select it and presto magic the Artifact is added
Notice the language-en-4.7 we created this JAR file because we could not find AmericanEnglish.class in any of the downloaded files. See Last screen shot
Here are the screen shots in the order to match the above direction
I am not holding my breath that using the downloaded 4.7 JAR,s is the best idea
You might try reaching out to Maven and Language Tool and ask why LT 4.7 is not in the repository!
Best of Luck

How to add a 'non-built' file to a project with C-Make

I have been searching about this for a couple of hours but couldn't find a solution, so asking.
I have a solution of projects that includes about 10 projects. But I'm facing a dependency problem. One of my projects generates moc files (QT moc file that was generated by 'QT4_WRAP_CPP' macro of Cmake) and I would like to use this moc file in another project. For now, after running the cmake script and getting the solution, I build all projects and the project that need those moc files generated by previous project complain about linking errors(rightly because I didn't point any file to it in its c-make script in ADD_EXECUTABLE section).
My question is: is there any way to add a 'not built yet but will' file to a project in Cmake to point it meanwhile writing the cmake script?
Here is related section of the cmake script of the project:
//suppose that X projects (which is also in this solution and built before Y project) generates a moc file with the name 'moc_X.cxx'
SET(Y_WORK_STATION_UI_HEADER YWorkStation.h
YSignInWidget.h
YConfigurationWidget.h)
QT4_WRAP_CPP(MOCSrcs ${Y_WORK_STATION_UI_HEADER})
ADD_EXECUTABLE(${PROJECT_NAME}
main.cpp
.
.
.
${MOCSrcs}
%---------------->and here something like moc_X.cxx ?
}
Hope it is clear enough. Thanks in advance.
If the file is generated by something CMake understands (that is, by a custom command in the same CMakeList), you can just list it and CMake will pick up the dependency by itself. For other cases, there is a source file property GENERATED which you can set on the source file to indicate it will be generated during build:
add_executable(${PROJECT_NAME}
main.cpp
.
.
.
${MOCSrcs}
moc_X.cxx ?
)
set_property(SOURCE moc_X.cxx PROPERTY GENERATED TRUE)
You seem to be doing several wrong things.
To start:
What do you mean by 'another project'? Do you actually mean 'another target'?
Why is one project using the moc files of another project? Is it also using the source files of that project? Why?
Why don't you use a static (or other) library if that's your goal? If using the source files of the other project makes sense for some reason (I imagine creating a unit test), then you should probably re-moc the files instead of trying to grab them from another implementation-detail location.

Using external libraries in Eclipse plugin

Problem:
I'm making eclipse plugin and need to use external jars.
What I did:
I maked folder lib where I added all needed jar and added them to the build path, but it's probably not enought, I found that I have to added them somehow to the plugin project dependencies, but I couldn't find how to add them in Eclipse. I use Eclipse 4.3.1 Kepler.
So I need use in my plugin something like foo.jar in which is fooClass.class.
Open the plugin.xml editor and select the Runtime tab. Add the jars to the Classpath section (bottom right).
This will add the jars to the Bundle-ClassPath entry in the MANIFEST.MF and will update the build.properties file to ensure the jars are included in the plugin.

Jar inclusion Issue

How can i add external jars to my project before exporting the project so that the person about to use my code need not have to download those jars.He simply has to refer the jar i provided to run my project(Not using Maven).
Thanks
You might want to create a zip file containing
your_jar.jar
the libraries needed in a subdirectory lib
and add a manifest-classpath entry to point to those libraries
Manifest-Version: 1.0
Created-By: Hand
Main-Class: com.bitplan.gen.parser.m2java
Class-Path: lib/com.bitplan.smartgenerator-4.2.3.jar
After unzipping your code can be started with java -jar your_jar.jar

Creating a JAR file which contains other library files

I want to create one executable JAR file which contains other JAR libraries. But when I execute the JAR, it gives an error of class path problem.
How do I solve the class-path problem?
I think you can try it like this;
Here is a simple example for you question. First, we assume we have a project directory like D:\javademo. In this working directory we then create a main class HelloWorld.java and thtat contains our other JAR files, like commons-lang.jar. Now, we must archive our main classes HelloWorld and commons-lang.jar into test.jar file.
First we must edit our manifest file so that we can specify our class-path and main-class
like this:
Manifest-Version: 1.0
Created-By: tony example
Class-Path: test.jar commons-lang.jar
Main-Class: org.tony.java.HelloWorld
We named this file test.mf. Now we use the jar command to generate our JAR file like this:
jar -cvfm test.jar test.mf -C ./ .
Then it will generate the JAR file test.jar. You can use this command to run this main class using java command:
java -jar test.jar
That is my solution. I hope it give you something helpful...
You should use third-party libraries for it. For example, OneJar. You'll have to build the final JAR file using the OneJar tool (like Ant task) instead of standard JRE's tools.
On running such a JAR file, OneJar's service class is launched instead of yours. This class then loads JAR files packed inside, as well as your classes, and run your main class.
There are similar questions and answers already. For example: Stack Overflow question Easiest way to merge a release into one JAR file.

Resources