I got source code from Hermes (hermes2_src_20100121). When I extracted it has about 10 folders which is separate projects.
/myd1/Exetel/Hermes_SRC/ebxml-pkg
/myd1/Exetel/Hermes_SRC/CorvusEbMS
/myd1/Exetel/Hermes_SRC/Commons
Etc….
Each project has its own build script
/myd1/Exetel/Hermes_SRC/ebxml-pkg/ant/build.xml
/myd1/Exetel/Hermes_SRC/CorvusEbMS/ant/build.xml
/myd1/Exetel/Hermes_SRC/Commons/ant/build.xml
Etc….
I need to build this 10 projects using the given ant scripts
when I run it the script fails and it gives compilation error
/myd1/Exetel/Hermes_SRC/ebxml-pkg/src/hk/hku/cecid/ebms/pkg/PKISignatureImpl.java:98: error: package org.apache.log4j does not exist
etc.....
Issue in this, log4j can’t be found(similary dom4J, Mail, etc….)
So I created folder in path “/myd1/exete/libs/” and added the required jar file there and set the CLASSPATH to this folder
CLASSPATH=/myd1/exete/libs/*
but still it gives the same error as the classpath is not working
I tried add CLASSPATH to ~/.bashhrc
CLASSPATH=/myd1/exete/libs/*
Export CLASSPATH
Add CLASSPATH to gedit /etc/environment
Env | grep CLASSPATH prints the correct path
The issue is when I run build script it still gives the same error as the classpath is not working
You should either set classpath in ANT script:
<path id="common.classpath">
<fileset dir="/myd1/exete/libs">
<include name="*.jar"/>
</fileset>
</path>
or
Set CLASSPATH according to http://docs.oracle.com/javase/6/docs/technotes/tools/solaris/classpath.html:
classpath1:classpath2 Class paths to the .jar, .zip or .class files.
Each classpath should end with a filename or directory depending on
what you are setting the class path to: For a .jar or .zip file that
contains .class files, the class path ends with the name of the .zip
or .jar file. For .class files in an unnamed package, the class path
ends with the directory that contains the .class files. For .class
files in a named package, the class path ends with the directory that
contains the "root" package (the first package in the full package
name). Multiple path entries are separated by colons.
The default class path is the current directory. Setting the CLASSPATH
variable or using the -classpath command-line option overrides that
default, so if you want to include the current directory in the search
path, you must include "." in the new settings.
Classpath entries that are neither directories nor archives (.zip or
.jar files) nor * are ignored.
So you should try either:
CLASSPATH=/myd1/exete/libs/*
or
CLASSPATH=/myd1/exete/libs
Set your classpath as CLASSPATH=/myd1/exete/libs/myjar.jar
i.e. name your jar in the CLASSPATH!
Related
After converting my java program to executable jar file using commands in command prompt in windows 10,while executing jar file I am getting error:
Could find or load main class Combine.class" caused
by:java.lang.ClassNotFoundException:Combine.class
My jdk-11.0.1 has javamail api and excelapi.While executing I have set my classpath as:
classpath=%classpath%;C:\Program Files\Java\jdk-11.0.1\javamail_api\javax.mail-1.6.2.jar;C:\Program Files\Java\jdk-11.0.1\javamail_api\activation.jar;C:\Program Files\Java\jdk-11.0.1\jexcelapi\jxl.jar;.;
It was compiling and executing properly but after converting to executable jar file it is not running and giving above error.
Any help would be appreciated.
Thank you
The clue is in the exception message. It is trying to load a class with the name Combine.class. But the classes real name is Combine.
You have created the JAR file incorrectly.
echo Main-Class: Combine.class > manifest.txt
jar cmf manifest.txt FinalExecutable.jar Combine.class
If Combine is in the default package (i.e. it doesn't have a package statement) then the above should be:
echo Main-Class: Combine > manifest.txt
jar cmf manifest.txt FinalExecutable.jar Combine.class
If Combine is declared in package foo.bar, then the above should be.
echo Main-Class: foo.bar.Combine > manifest.txt
jar cmf manifest.txt FinalExecutable.jar foo/bar/Combine.class
and you need to be in the directory above the foo directory.
NB: the "Main-Class" attribute in the manifest must be a Java fully qualified class name, NOT a filename or file pathname.
It also should be noted that the CLASSPATH environment variable and the -cp argument will be ignored when you run a JAR using java -jar .... If your executable JAR depends on other JAR files, you should either combine them (to create a shaded JAR) or you should add a "Class-Path" attribute to the manifest; see https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html
Finally, my advice would be to use a build tool (e.g. Maven) to compile your code, create the executable JAR file, etc rather than doing it by hand.
I made a code that connects to my sqlite driver which is in the CLASSPATH and reads some database file. I want to create an executable which can be used on computers that don't have the sqlite driver.
If I do:
jar cvfe exec.jar main_class
I will get "class not found: org.sqlite.JDBC" when running with
java -jar exec.jar
What should I do to make the executable work?
Edit:
I don't know if it makes any difference, but this is the JDBC driver I use:
https://bitbucket.org/xerial/sqlite-jdbc
You need to include the library inside the JAR. Maybe you don't know this, but JAR files are just ZIP files, so you can change their contents easily. Here are some quick instructions on how to do it. Assuming your JAR file is named exec.jar, and the JAR of the library you want to include (the JAR you downloaded) is driver.jar
Change your file name from exec.jar to exec.zip.
Extract all the contents of exec.zip into folder exec/
Change your library file name from driver.jar to driver.zip
Extract all the contents of driver.zip into folder driver/
Copy the contents of driver/ into exec/, but do not copy the META-INF folder. If a pop-up asks if it's ok to merge the folders, click yes.
Compress all files in exec/ into exec.zip
Rename exec.zip to exec.jar (replace the original).
You can include any java library inside a JAR using this method.
Here is the doc:
C:\Windows\System32>jar /?
Illegal option: /
Usage: jar {ctxui}[vfmn0Me] [jar-file] [manifest-file] [entry-point] [-C dir] files ...
And so I think the command you need is:
jar cvfe exec.jar main_class main_class
I am getting this strange error while excuting following commands..
cobertura-merge.bat --auxClasspath ./cobertura-2.0.3.jar --datafile cobertura.ser cobertura1.ser cobertura2.ser
cobertura-merge.bat --auxClasspath . --datafile cobertura.ser cobertura1.ser cobertura2.ser
Error -
Error: Could not find or load main class net.sourceforge.cobertura.merge.Main
PS -
I have JAVE HOME set.
Java bin dir is added to PATH.
CLASSPATH is defined with - %CLASSPATH%;.;.
I have added cobertura-2.0.3.jar in jdk lib and jre lib directory.
I ran in to the same problem. To fix this, you will need to edit the cobertura-merge.bat in a text editor. The last line looks something like this:
java -cp "%COBERTURA_HOME%cobertura.jar;%COBERTURA_HOME%lib\asm-3.3.1.jar;.....
The jar file names in this command most likely do not match the jar file names in your cobertura_home\lib.
Example:
In the command above, from the batch file, it references 'cobertura.jar'
If you look in the lib folder, the actual name of the file is 'cobertura-2.0.3.jar
The same goes for the other jar files. So you will have to change the bat file, or the file names, to make them match.
I am trying to run program from command prompt
Here is my director structure
In the classes directory i have this structure
In the email folder i have two properties file general-mail-settings.properties and customer-mail-settings.properties
Now when i run the command
D:\vintnes\lasses>java -cp ".;..\dependency-jars\*" com/softech/ls360/integration/BatchImport vintners
Then i get the error that
java.lang.Exception: Email Properties File not found: src\main\resources\email\general-mail-settings.properties (The system cannot find the path specified)
at
...
I tried this to specify path
java -cp ".;..\dependency-jars\*;.\email\*.*" com/softech/ls360/integration/BatchImport customer
But still i am getting the error. I tried ;email\* and \email\*, but still i am getting the error. How can i specify path so program get run?
Thanks
You put a path to src/main/resources in your code somewhere. This is a directory used by Maven builds to hold "resource" files (files that aren't code but that should be copied into the finished artifact, like configuration files or media). The contents of src/main/resources are copied directly into the root of the artifact as-is, so in this case, the email directory is copied straight into your classes directory. Remove the src/main/resources part of the path from your properties lookup.
HI guys,
There is an abc.jar under /tomcat_lib. I need use this in my def.java
I tired
javac -classpath /tomcat_lib/ -d
../classes def.java
but it doesn't work
But if it works if I use
javac -classpath /tomcat_lib/abc.jar
-d ....
Can anyone help explain it?
To add a jar to your classpath, you need to specify the path up to and including the .jar file.
Quoting the official Java SE 6 documentation at Oracle.com:
Each [item in your classpath] should
end with a filename or directory
depending on what you are setting the
class path to:
For a .jar or .zip file
that contains .class files, the class
path ends with the name of the .zip or
.jar file.
For .class files in an
unnamed package, the class path ends
with the directory that contains the
.class files.
For .class files in a
named package, the class path ends
with the directory that contains the
"root" package (the first package in
the full package name).
...and from the "Folders and Archive Files" section of the same documentation:
When classes are stored in a directory
(folder), like
c:\java\MyClasses\utility\myapp, then
the class path entry points to the
directory that contains the first
element of the package name. (in this
case, C:\java\MyClasses, since the
package name is utility.myapp.)
But when classes are stored in an
archive file (a .zip or .jar file) the
class path entry is the path to and
including the .zip or .jar file.