Add JLayer Library Eclipse - java

I have a problem with JLayer Library on Eclipse. With JDev it works fine but I have to work in Eclipse for a project and I can't install this Library.
I did Builds Path -> Add Library and import JLayer.zip
As you can see I can't import Javazoom. Thanks for your help

You need to unpack the JLayer zip file to extract the jar file contains the Java class files (jl1.0.1.jar). Use this jar file in the build path as an external jar instead of the zip file.
Also 'import' statements come before the class file definition:
import javazoom.jl.player.AudioDevice;
public class MyClass
{
....
}

Related

Export custom library to importable jar file java

I have created a custom package in Java. The directory structure is like this:-
wolpha
/Stream>Stream.java
/Word/Stream.java
/Pattern/Stream.java
/Stream/Stream.java
So I just made a non runnable jar file and tried to import the package but it gave a error that the package wolpha does not exist. Tried with a main class with imports included but gave the same error.
How can I add all these classes into a single .jar file such that all classes can be imported into any file. I expect some step-by-step instructions with some down-to-earth language.
If you are using eclipse, go to File > Export and follow the instructions as per the screenshots given below:

Compressing an Extracted Jar File

I have extracted a jar file and made some change on it. Now, how can i compress again it as an executable jar file?
Thanks.(Sorry for my bad english.)
Try :
jar cf jar-file input-file(s)
according to http://docs.oracle.com/javase/tutorial/deployment/jar/build.html
By Using Eclipse IDE You can Create your jar file
Below i have one link from which you can learn how to make jar file executable
https://www.cs.utexas.edu/~scottm/cs307/handouts/Eclipse%20Help/jarInEclipse.htm
But For that You have to make project in Eclipse.
You can use this very simple library to pack/unpack jar file programmaticaly
JarManager
Very simple
import java.io.File;
import java.util.List;
import fr.stevecohen.jarmanager.JarUnpacker;
class Test {
JarUnpacker jarUnpacker = new JarUnpacker();
File myfile = new File("./myfile.jar");
File unpackDir = new File("./mydir");
List<File> unpacked_files = jarUnpacker.unpack(myfile.getAbsolutePath(), unpackDir.getAbsolutePath());
}
You can also use maven dependency
<dependency>
<groupId>fr.stevecohen.jarmanager</groupId>
<artifactId>JarManager</artifactId>
<version>0.5.0</version>
</dependency>
Check the last version with the link bellow to use the last dependency
Please use my public issue tracker if you find some bugs
jar cvf filename.jar *
To compress all extracted file to single jar file you can use *
To add single file you also can use filename instead of *
https://docs.oracle.com/javase/tutorial/deployment/jar/appman.html

Java: silly newbie issue about path used in import statement

I'm working through the example here:
http://www.vogella.com/articles/JavaPDF/article.html
In my file, I've got:
package com.mycompanyname.mydirectory;
import com.mycompanyname.OneOfMyClasses;
import com.itextpdf.text.Document;
...
public class MyClass {
...
}
Everything is working fine. What I don't understand is that since I just copied the import statement directly from the link above for the iText portion -- why does com.itextpdf.text.Document work?
I mean, if I look in directory com.mycompanyname I can see OneOfMyClasses.java there.
But in the com directly, there is no itextpdf directory (although maybe my user doesn't have permission to see it(?)).
Hoping someone can help me understand what I'm missing here. Doesn't the import point to a specific directory that I should be able to see the class? Is there a different com directory somewhere that iText is using, and com.itextpdf.text points to there? (if so, where's the directory located)?
I installed the jar file for iText in the lib folder as per usual, and made sure it was included in the classpath.
Those classes are inside a JAR file that is added to the classpath:
Create a new Java project "de.vogella.itext.write" with the package "de.vogella.itext.write". Create a folder "lib" and put the iText library (jar file) into this folder. Add the jar to your classpath.
import statements will look inside whatever directory trees are in the classpath, which includes the current directory at compilation time (tipically the src/ directory in your project) as well as any directory specified through environment variable or JVM startup parameter. See this about the classpath.
EDIT
You do need the imports whenever you use classes across packages. Every public class/interface you define is in a package. If whatever you are referencing belongs to another package, you need to import it.
JARs are zip files that contain directories and files inside. It's the same as plain directories and files, only packed.
It comes from the iText dependency (jar) you added in an earlier step.
Not necessarily - you could also import from libraries, etc.
In fact, Java will try to search through the classpath. Here is some helpful documentation.
That class is most probably imported in a JAR library. Inside such JAR file, the class files are kept in exact package/folder structure as you use when importing them.

Error in Java program missing packages

I tried to run the java program but missing packages.
import org.activiti.engine.*;
public class RawDriver
{
public static void main(String[] args) {
ProcessEngine processEngine = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration().setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE).setJdbcUrl("jdbc:h2:mem:my-own-db;DB_CLOSE_DELAY=1000").setJobExecutorActivate(true).buildProcessEngine();
System.out.println("processEngine = " + processEngine);
}
}
How can i import external packages and run the program?
The external packages need to be in your classpath. This can be set as an environment variable or on the command line. You need to have the libraries associated with what you need which are usually shipped as jar files. More about the classpaths here: http://docs.oracle.com/javase/tutorial/essential/environment/paths.html
if the external packages are in another project, you can import that project, then in the project you are writing, choose Java build path -> project, add the project you just import. Then go to your java file and import the packages.
If you are using esclipse , if you have a jar file then you can add the jar file to you classpath using the project --->Properties-->java build path
add the jar in the project libraries , you will be able to access external packages like this .
if you using command line option or unix , set the class path using the command line option set CLASSPATH option.
Hope this helps
Abhi

Import library is not resolved

I have tried to compile a java program, shorten.java from mp4parser site. But my jar file is unable to resolve the required import shown below.
This program needs to import library from iso mp4parser as mentioned below. In short I need jar file for shorten.java file to resolve these import.
import com.coremedia.iso.IsoFile;
import com.coremedia.iso.boxes.TimeToSampleBox;
import com.googlecode.mp4parser.authoring.Movie;
import com.googlecode.mp4parser.authoring.Track;
import com.googlecode.mp4parser.authoring.builder.DefaultMp4Builder;
import com.googlecode.mp4parser.authoring.container.mp4.MovieCreator;
import com.googlecode.mp4parser.authoring.tracks.CroppedTrack;
I have downloaded the source code from the mp4parser site to create the jar file for these library.
In below image java->com->coremedia->iso and java->com->coremedia->iso->boxes having required java program
and java->com->googlecode->mp4parser->authoring etc. having other needed java program for these import
I have created the jar by following command-
cd java // moved in java folder
jar cfv mp4parser.jar *
now add these jar to my shorten.java program.
But I am getting error that import is not resolved.
****Do anybody can tell me where I am doing mistake ???****
Here is the directory where java codes for these imports are available.
I suggest you to this:
Create a quickstart java project with maven;
Add the dependencies that you want;
Put the java class in src/main/java
mvn clean install
If it don't work, try some IDE, like eclipse. Open the project and try to fix the imports... It's always possible that some lib has changed, and maybe they change the name of the package.

Categories

Resources