I have a RCP 4 app with many plugin projects. The app runs well in IDE but when I run it after exported, some exceptions was throw (ClassNotFoundException).
I investigated then see that it's because of some classes had not yet been exported to the jar files. I don't know why? The configurations in MANIFEST.MF, plugin.xml, build.properties are same but some can export the class to jar file, some not.
Can you help me? Thank you very much!
Update: build.properties file
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
item_editor.e4xmi,\
plugin.xml
Update: MANIFEST.MF file
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Item_editor
Bundle-SymbolicName: xxx;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: xxx
Require-Bundle: org.eclipse.e4.ui.model.workbench,
org.eclipse.osgi.services,
org.eclipse.jface,
org.eclipse.e4.core.services,
xxx,
xxx,
org.eclipse.nebula.widgets.nattable.core,
org.eclipse.e4.ui.workbench,
org.eclipse.e4.core.contexts,
org.eclipse.e4.core.di,
org.eclipse.core.runtime,
org.eclipse.e4.ui.di,
xxx;bundle-version="1.0.0",
org.eclipse.e4.core.di.extensions;bundle-version="0.15.0",
xxx,
xxx,
xxx
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: javax.inject;version="1.0.0"
Export-Package: xxx,
xxx,
xxx,
xxx,
xxx;x-internal:=true,
xxx
I was just facing this issue for couple of days! it was really annoying. here is what we did for our project to start copying the .class files into the package:
Our problem: None of the project classes (our classes) are copied inside the exported jar when it is exporting the project.
In the eclipse, we open the .project file we have for the build. It will open it in the editor section.
In the content menu, we click on our own Module entry (we named it XXX_BCC) and it opens it in a sperate editor.
Then we need to go to the build tab as you can see in the picture below.
Add our bin (it is the output folder specified for our .class files) to the . classpath!
Under Runtime Information, When we were opening it before the change, it was only src/, you can press Add Folder.. and add the bin/ there. It will add the content of the bin folder to the root of the classpath in the exported JAR file.
We did the export again and our class files were there and we did not receive that exception again.
Here is the build.properties file after the change:
-Below is the content of our JAR file after the change and export again. Please notice our packages like _bcc and YYYY in the JAR content. They are our classes that were missed before.
Related
I've spent the past week trying to figure this issue out...hopefully someone can help.
I created a Java project that uses MigLayout. I've added the jar file to the same directory where my main class is.
i.e.
java/
Main.java ...contains main() method
MigLayout/miglayout-4.0-swing.jar
It doesn't matter which editor I use, I can compile/run the file and it executes flawlessly.
The issue starts when I try to create a jar file, or compile with cmd. If, for example, in IntelliJ I build the artifact (build the Jar file), it builds it...but it won't run it when I double click on it.
If I use javac in cmd, it gives me this error:
/////////////////////////////////////////////////////////////////////
Main.java:8: error: package net.miginfocom.swing does not exist
import net.miginfocom.swing.MigLayout;
^
Main.java:74: error: cannot find symbol
menuPanel = new JPanel(new MigLayout());
^
symbol: class MigLayout
location: class Main
2 errors
//////////////////////////////////////////////////////////////////////
Any help would be great.
SOLVED
OK, so I got it working. This is what I did:
I created a new folder and moved all of the src files into the src folder there
I made sure to remove all other files that weren't java related, such as the Manifest file
I previously downloaded the MigLayout and json jars and placed them into the src folder as well (that's how I originally got the code to compile)
I opened up IntelliJ and clicked File -> New -> Project from existing source
I selected the folder that contained the src folder
I ran through the prompts. I noticed that it was finding everything: MigLayout and JSON jars
After it was complete, I made sure that it would compile in IntelliJ and it did.
Next, as I did before, I clicked File -> Project Structure -> Artifacts
I clicked the Plus button and selected JAR From Modules with dependencies. I selected the file containing the main method
I checked the Build on make option that's right below the Output directory
I clicked Apply and OK.
Next I clicked Build and Build Artifacts
I selected Jar and Build Jar
Went to the out folder and it was there
I double clicked on it and everything worked!
I have a problem regarding exporting my Java project into a jar file.
I have this file (application.properties) which contains some database information and located under the project root directory.
There is no problem when running this project on Eclipse. But after exporting into a jar(Runnable Jar file) file, application.properties will not be included in the packaging and that cause the error.
Any suggestion how to fix this problem?
Do you want to have the application.properties reside outside the jar (for writing), or is it read-only? When outside you can have an initial template file in the jar, and copy it to some location.
//String applicationWorkingDir = System.getProperty("user.dir"); // The current constellation.
String userHomeDir = System.getProperty("user.home");
File myApplicationDataDir = new File(userHomeDir + "/.MyApplication");
myApplicationDataDir.mkdir();
File propertiesFile = new File(myApplicationDataDir, "application.properties");
Also using the Preferences API instead of a properties would be a solution.
In the manifest file for an eclipse plugin its possible to add jar files and
folders to the classpath (on the Runtime tab).
In the root of my plugin I have a folder lib containing a-1.0.1.jar, b-1.0.0-SNAPSHOT.jar. But only when I select each jar separately:
Bundle-ClassPath: .,
lib/a-1.0.1.jar,
lib/b-1.0.0-SNAPSHOT.jar
...can they be used inside my project. Why is it not possible to add them to the classpath by adding the common root folder only:
Bundle-ClassPath: .,
lib/
?
No, you can't. Eclipse is based on OSGi, which is the platform providing MANIFEST.MF support to build plugins.
When you set values under Bundle-ClassPath, OSGi search into each one to find class files. So you can put folders containing Java packages and class files. When you put a jar file, it is uncompressed in memory and viewed by OSGi as a regular folder, still searching for class files.
Unfortunately, there is no way to load all jar from a folder. No wildcard mechanism or something like that is allowed here.
I need to import a flex project into FlashDevelop.
However I am unable to find the .actionScriptProperties file.
How would I be able to import the project?
It would be great if someone could help me out with it.
Usually Flex Builder project contains:
src/ directory - source files (.as and .mxml)
libs/ directory - .swc files (if exists)
Usually FlashDevelop project contains:
1) src/ directory - place here files from src directory of FB project
2) lib/ directory - place here .swc files (if exists) from libs directory of FB project
3) on each swc files (if exists) you need make right click and select "Add to Library".
4) Make right click on main class file and select "Document Class"
This is main. May be there are other files. But I can not say what you have because I not know what files you have.
actually i canĀ“t import a FB project to FD whit the options in the menus but i can fix it creating a new project in the folder of the FB project and putting files in folders identified by FD it works for me
I am using jar -uf to update my MANIFEST.MF file like this:
a. jar xf jarfile.jar META-INF\MANIFEST.MF
b. edit the file
c. jar uf jarfile.jar META-INF\MANIFEST.MF
But the 'uf' command is removing MANIFEST.MF from within my jar.
What is the right way to change a file inside a jar (windows 7, jdk 1.6)?
You can always use winrar (or any equivalent) to open the jar, and drag/drop the files. worked for me.
For updating the manifest file the jar command provides different option -
jar umf manifest jar-file
The m option indicates that you want to update the JAR file's manifest.
manifest is the manifest whose contents you want to merge into the manifest of the existing JAR file.
examples # http://java.sun.com/developer/Books/javaprogramming/JAR/basics/update.html
There is a special option (m) for the manifest file: http://download.oracle.com/javase/1.4.2/docs/tooldocs/windows/jar.html
Could you try with
jar um jarfile.jar META-INF/MANIFEST.MF