when I try to build my .jar (as described here) I get a MANIFEST.MF and a xml file inside the artifacts folder that's in the .idea folder. However I have no artifact folder with a .jar file inside the out folder. That's where the .jar file should be. This build process had worked earlier and I have no idea what I messed up.
I really need to build a jar and I used the IntelliJ GUI creator so I can't simply build a jar with an other program because it uses some compiled classes from a IntelliJ library, can I?
The xml file inside the artifacts folder:
<component name="ArtifactManager">
<artifact type="jar" name="Zimmerbelegung_BwInf36:jar">
<output-path>$PROJECT_DIR$/out/artifacts/Zimmerbelegung_BwInf36_jar</output-path>
<root id="archive" name="Zimmerbelegung_BwInf36.jar">
<element id="directory" name="META-INF">
<element id="file-copy" path="$PROJECT_DIR$/META-INF/MANIFEST.MF" />
</element>
<element id="module-output" name="Zimmerbelegung_BwInf36" />
</root>
</artifact>
</component>
My project structure looks like this:
IntelliJ didn't automatically build the artifact.
So I had to build it manually: (Build > Build Artifacts...)
Related
I am currently trying to write a build.xml which will convert a normal java project say com.example.normal to com.example.plugin.jar.
I have the code for a basic build.xml which creates a jar of the source project. But normally creating a jar file is not the same as creating a plugin jar file. For this reason I need to create a plugin jar file using ant and not just a normal jar file which cannot act as a plugin.
This is the example code snippet for creating the jar file.
<jar destfile="generatedPlugins/com.example.normal.jar">
<fileset dir="JavaSource/com.example.normal"/>
</jar>
Manually, I can create a plugin with the following steps:
Right Click on project > Export > Plugin Development > Deployable
plug-ins and fragments.
In other words, I just need to automate this process using Ant. Any idea how to proceed?
Thanks!
This can't really be done with Ant alone. You should use Tycho or PDE Build to build bundle (plug-in) JARs. Take note that Tycho is the modern, preferred option; I'm not sure that PDE Build is even actively maintained or used any more.
You could try manually editing the build.xml, adding something like
<!-- This builds a .jar file, Assuming you have a set of .class files
created by some "compile" target. -->
<target name="build" depends="compile">
<!-- We need to set up class path for any required libraries so that we
can add it to the manifest file later. -->
<path id="build.classpath">
<pathelement location="${lib.location}"/>
</path>
<!-- Now we convert the class path we just set up to a manifest class
path - we'll call it manifest.cp. We also need to tell it where our
.jar file will be output. -->
<manifestclasspath property="manifest.cp" jarfile="${jar.output.dir}/filename.jar">
<!-- We just give it the classpath we set up previously. -->
<classpath refid="build.classpath"/>
</manifestclasspath>
<!-- Now we can make the .jar. It needs to know the base directory of
our compiled .class files. -->
<jar destfile="${jar.target}/filename.jar" basedir="${class.target}">
<!-- Set up the manifest file with the name of the main class and
the manifest class path we set up earlier. -->
<manifest>
<attribute name="Main-Class" value="name of main class"/>
<attribute name="Class-Path" value="${manifest.cp}"/>
</manifest>
</jar>
</target>
You can generate Ant scripts from the PDE tools by right-clicking on a relevant manifest file (e.g. plugin.xml) in the project and selecting PDE Tools --> Create Ant Build File.
This link from the Eclipse Mars documentation explains in detail.
While running junit test in eclipse I am getting this Exception:
java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
I've added junit.jar library file.
I've tried different versions of junit.jar: 4.4, 4.8, etc.
How do I fix this Exception?
Add hamcrest-all-X.X.jar to your classpath.
Latest version as of Feb 2015 is 1.3:
http://code.google.com/p/hamcrest/downloads/detail?name=hamcrest-all-1.3.jar&can=2&q=
According to the JUnit GitHub team website (https://github.com/junit-team/junit/wiki/Download-and-Install), junit.jar and hamcrest-core.jar are both needed in the classpath when using JUnit 4.11.
Here is the Maven dependency block for including junit and hamcrest.
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.1.2</version>
<scope>test</scope>
</dependency>
<!-- Needed by junit -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
A few steps you have to follow:
Right click on the project.
Choose Build Path Then from its menu choose Add Libraries.
Choose JUnit then click Next.
Choose JUnit4 then Finish.
Works for me: IntelliJ IDEA 13.1.1, JUnit4, Java 6
I changed the file in project path: [PROJECT_NAME].iml
Replaced:
<library>
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.11.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
By:
<library name="JUnit4">
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.11.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-core-1.3.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-library-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
So the final .iml file is:
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="JUnit4">
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.11.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-core-1.3.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-library-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>
P.S.: save the file and don't let to IntelliJ Idea reload it. Just once.
You need junit-dep.jar because the junit.jar has a copy of old Hamcrest classes.
Just in case there's anyone here using netbeans and has the same problem, all you have to do is
Right click on TestLibraries
Click on Add Library
Select JUnit and click add library
Repeat the process but this time click on Hamcrest and the click add library
This should solve the problem
This problem is because of your classpath miss hamcrest-core-1.3.jar. To resolve this add hamcrest-core-1.3.jar as you add junit-4.XX.jar into your classpath.
At first, I encounter this problem too, but after I refer to the official site and add hamcrest-core-1.3.jar into classpath with command line, it works properly finally.
javac -d ../../../../bin/ -cp ~/libs/junit-4.12.jar:/home/limxtop/projects/algorithms/bin MaxHeapTest.java
java -cp ../../../../bin/:/home/limxtop/libs/junit-4.12.jar:/home/limxtop/libs/hamcrest-core-1.3.jar org.junit.runner.JUnitCore com.limxtop.heap.MaxHeapTest
You need to add the hamcrest-core JAR to the classpath as described here: https://github.com/junit-team/junit4/wiki/Download-and-Install
As a general rule, always make sure hamcrest is before any other testing libraries on the classpath, as many such libraries include hamcrest classes and may therefore conflict with the hamcrest version you're using. This will resolve most problems of the type you're describing.
the simplest way of solving the problem to begin with is copying latest version of hamcrest-code.jar into your CLASSPATH that is the file you store other .jar files needed for compilation and running of your application.
that could be e.g.: C:/ant/lib
It sounds like a classpath issue, so there are a few different ways to go about it. Where does org/hamcret/SelfDescribing come from? Is that your class or in a different jar?
Try going to your project Build Path and on the Libraries tab, add a Library. You should be able to choose JUnit to your project. This is a little bit different than just having the JUnit jar file In your project.
In your Run Configuration for the JUnit test, check the Classpath. You could probably fix this by adding making sure your Classpath can see that SelfDescribing class there. The Run option in Eclipse has a different set of options for the JUnit options.
If this problem arise in a RCP project it can be because JUnit has been explicitly imported.
Check the editor for your plugin.xml under Dependencies tab, remove the org.junit from the Imported Packages and add org.junit to the Required Plug-ins.
The problem is when you set up eclipse to point to JRE instead of JDK. JRE has junit4.jar in the lib/ext folder, but not hamcrest.jar :) So the solution is to check installed JREs in Eclipse, remove the existing one and create a new one pointing to your JDK.
This happens when you run Ant via command line. The implicit user dependencies are added in the classpath at the end and take precedence over the project-added classpath. Run Ant with -nouserlib flag. The implicit dependencies would be excluded from the classpath.
There is a better answer to solve this problem.
add dependency
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
The hamcrest-core-1.3.jar available on maven repository is deprecated.
Download working hamcrest-core-1.3.jar from official Junit4 github link .
If you want to download from maven repository, use latest hamcrest-XX.jar.
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
I had the same problem, the solution is to add in build path/plugin the jar org.hamcrest.core_1xx, you can find it in eclipse/plugins.
A few steps you have to follow:
Right click on the project.
Choose Build Path & then from its menu choose Add Libraries.
Choose JUnit then click Next.
Choose JUnit4 then Finish.
This works for me...
"java.lang.SecurityException: class" org.hamcrest.Matchers "'s signer information does not match signer information of other classes in the same package"
Do it:
Right-click on your package
click on Build Path -> Configure Build Path
Click on the Libraries tab
Remove JUnit
Apply and close
Ready.
Try adding the jar files manually or try with force update with the latest hamcrest.jar
How do I create a .war-file from my gwt-project in eclipse?
I always use Ant build file, so the project gets compiled and packaged as a war with one click.
Add an xml-file to your project with the following content:
<project name="test" basedir="." default="default">
<property name="src.dir" value="src" />
<property name="build.dir" value="war" />
<path id="compile.classpath">
<fileset dir="${build.dir}/WEB-INF/lib">
<include name="**/*.jar" />
<include name="**/*.xml" />
</fileset>
</path>
<target name="default" depends="gwtc, buildwar,deploy">
</target>
<target name="gwtc" description="GWT compile to JavaScript">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<pathelement location="${src.dir}" />
<path refid="compile.classpath" />
</classpath>
<arg line="-logLevel INFO" />
<jvmarg value="-Xmx1024M" />
<arg value="YourProject.EntryPointClass" />
</java>
</target>
<target name="buildwar">
<war basedir="war" destfile="YourProject.war" webxml="war/WEB-INF/web.xml">
<exclude name="WEB-INF/**" />
<webinf dir="war/WEB-INF/">
<include name="**/gwt-servlet.jar" />
<include name="**/classes/**" />
</webinf>
</war>
</target>
<target name="deploy">
<copy file="YourProject.war" todir="." />
</target>
</project>
(Edit `YourProject.EntryPointClass to the path to your EntryPoint-class)
You would need to add gwt-user.jar and gwt-dev.jarto your projects build path(right click on your project -> Build Path -> Add External Achives).
If you now look at your "Problems"-view you get a warning that the two files are not available on the server's class path. You can use the QuickFix to either copy it to WEB-INF/lib or hide the warning. The build file will not include those two file in the war-file.
All you need to do to compile and create the file is to right click the xml-file and select run as Ant Build.
Using Eclipse:
right click the project
choose GoogleâGWT Compile
when compilation has finished, the console will say i.e.
Linking into /home/janus/bpworkspace/gwtwerkstatt2/war/gwtwerkstatt2
Link succeeded
Compilation succeeded -- 28.623s
open a terminal and navigate to the directory
create the WAR: jar cv * > /tmp/myGWTproject.war
you can now launch it with jetty-runner or similar: java -jar jetty-runner-8.1.7.v20120910.jar /tmp/myGWTproject.war
I just found this solution, and it's amazing :)
Just install the jar and enjoy extracting to a war file.
Project Site
http://code.google.com/p/gwt-project-export-wizard/
One can also use webAppCreator to generate Ant build file.
webAppCreator ships with GWT SDK and also with Eclipse GWT Plugin. First locate GWT plugin directory
find $HOME/.eclipse/ -name "*gwt*sdk*"
this will output GWT plugin dir path. This dir has gwt dir something like gwt-2.4.0. WebAppCreator will be in this dir. Set this dir as GWTSDK_HOME.
export GWTSDK_HOME=/home/m/.eclipse/org.eclipse.platform_3.7.0_1364963873/plugins/com.google.gwt.eclipse.sdkbundle_2.4.0.v201201120043-rel-r37/gwt-2.4.0
make webAppCreator executable
chmod 755 $GWTSDK_HOME/webAppCreator
Now create a project using webAppCreator in some temp dir.
$GWTSDK_HOME/webAppCreator -out fins in.m.fins.Fins
in.m.fins.Fins is the module name. This has to match with your project's gwt.xml in Eclipse workspace. If your gwt.xml is src/in/m/fins/Fins.gwt.xml then module name should be in.m.fins.Fins
-out fins will create the project and build.xml in fins directory. Copy generated build.xml file to your project in Eclipse workspace.
Run war target in Eclipse Ant Window to package your project as war
You have to have GWT designer installed from here
http://dl.google.com/eclipse/inst/d2gwt/latest/3.7
In Eclipse on the main panel click on "Deploy module on aplication server" (It's next to blue google button).
Chose war file name and location where to store it
Click ok
That's it. Works on my GWT 2.4.0, Google Plugin for Eclipse 4.2, Eclipse Juno
For future reference: you'll find another tutorial on how to create a .war using Eclipse on http://blog.elitecoderz.net/.
Fist compile your project. Then:
1. Open your project.
2. Navigate to war folder.
3. Go to File>Export>Archive File
4. Export your war FOLDER as zip file.
5. Change your file extension form .zip to .war
6. Keep calm and enjoy your war file.
Compile your project. Then:
Open your project.
Navigate to war folder.
Go to File>Export>Archive File
Export your war FOLDER as zip file.
Change your file extension form .zip to .war
Keep calm and enjoy your war file.
This worked in Ant 1.7.1 but no longer works in Ant 1.8.1. Is this a bug or is there a new and/or better way to achieve what I'm trying to do?
The Project consists of 2 components, each component has it's own build file and properties file, there is also a top level build file and properties file for common ant targets and properties. It is laid out like so:
/project/
component-a/
build.properties
build.xml
component-b/
build.properties
build.xml
build.properties
build.xml
/project/build.properties:
common.root.dir=/project
/project/build.xml:
<project name="common">
<dirname file="${ant.file.common}" property="common.base.dir"/>
<loadproperties srcfile="${common.base.dir}/build.properties"/>
</project>
/project/component-b/build.properties:
dist.dir=${common.root.dir}/component-b/dist
/project/component-b/build.xml:
<project name="component-b">
<dirname property="component.b.base.dir" file="${ant.file.component-b}"/>
<import file="${component.b.base.dir}/../build.xml"/>
<loadproperties srcfile="${component.b.base.dir}/build.properties"/>
</project>
/project/component-a/build.properties:
dist.dir=${common.root.dir}/component-a/dist
/project/component-a/build.xml:
<project name="component-a">
<dirname property="component.a.base.dir" file="${ant.file.component-a}"/>
<property name="project.root.dir" location="${component.a.base.dir}/.."/>
<import file="${project.root.dir}/build.xml"/>
<loadproperties srcfile="${component.a.base.dir}/build.properties"/>
<loadproperties srcfile="${project.root.dir}/component-b/build.properties" prefix="component.b"/>
<target name="print.unresolved.property">
<echo>${component.b.dist.dir}</echo>
</target>
</project>
To see the error run: ant -f /project/component-a/build.xml print.unresolved.property
If using Ant 1.8.1 the output will be:
print.unresolved.property:
[echo] ${common.root.dir}/component-b/dist
Why is common.root.dir not resolving to /project?
For others encountering this problem, I've uncovered that it is indeed a bug; while I haven't found the relevant bug report, I built ant using the latest source code from their repository and the property now resolves correctly. Here's to hoping that v1.8.2 is released sooner rather than later.
Greeting, I'm trying to put some Beanshell script in my Ant build.xml file. I've followed the Ant manual as well as I can but I keep getting "Unable to create javax script engine for beanshell" when I run Ant. Here is the test target I wrote mostly from examples in the Ant manual:
<target name="test-target">
<script language="beanshell" setbeans="true">
<classpath>
<fileset dir="c:\TEMP" includes="*.jar" />
</classpath>
System.out.println("Hello world");
</script>
</target>
My beanshell "bsh-2.0b4.jar" file is on the script task's classpath the way the manual recommended. Hope I have the right file. I'm working in c:\TEMP right now.
I've been googling and trying for a while now. Any ideas would be greatly appreciated. Thanks.
First, you need jsr-engines.zip from here:
https://scripting.dev.java.net/servlets/ProjectDocumentList
Inside, you'll find jsr223/beanshell/build/bsh-engine.jar. Some searching implied that you need to download bsh-2.05b.jar. I found it here:
http://beanshell.org/bsh-2.0b5.jar
The more easily findable bsh-2.0b4.jar also seemed to work, but it printed a message that implied it was experimental.
Currently (2012) you need only 1 jar to fire the script task for BeanShell:
bsh-2.0b5.jar
Previously I also thought of the following, as mentioned by Ant Manual, Library Dependencies chapter:
bsf-2.4.0.jar
commons-logging-api-1.1.jar
But it looks like bsf is not needed for bsh, at least in my environment.
Once the jar is given to ant, the script task runs smoothly. There are 2 possible scenarios for getting the jars and making them available to ant.
Manual download way
Download the jars above. I provided the links from maven repository. Once you have all the jars downloaded, make them available to ant. There are
at least 3 ways to do it:
Put it in java library path
Put it in ant library directory
Give the correct classpath to script task.
I find the last method the best, because it is most easily ported between
different systems. The ant file for the script task could look as follows:
<project default="t1" >
<property name="bsh.path"
location="/mnt/q/jarek/lang/java/ant/stackoverflow/bsh-2.0b5.jar" />
<target name="t1">
<script language="beanshell" classpath="${bsh.path}">
javax.swing.JOptionPane.showMessageDialog(null, "Hello, Script!");
</script>
</target>
</project>
Automatic download method, employing Ivy
The manual method is not perfect when you want to distribute your build script. Then you would like a way to make sure the jars are present in the destination system. For distributing builds there's no better tool than ivy. Ivy will download the jars and put them in classpath for you. The problem is that there appears another dependency, which is ivy itself. But providing ivy.jar is quite easy and that is the last dependency we need to supply explicitly.
One may ask why to provide ivy.jar, while we could simply download bsh.jar in the same way. The answer is flexibility. When you have the ivy.jar, you get any jar you wish with a single step being adding it to the ivy.xml file. And there is an agreed universal location for the ivy.jar file, while for other file we would have to think of a suitable directory.
Below comes the full example that downloads ivy and then all the necessary dependencies. Ivy download script is based on Installation chapter of Ivy reference.
Then a simple ivy.xml file is needed, which is given after the sample build.xml.
Original auto-download ivy script has a disadvantage of always checking the ivy url, even if ivy.jar is already in the expected location. This may be overriden by specifying -Doffline=true. I prefer to add another target to the build file and to do the http check only if we don't already have the ivy.jar. This is the way the script here works. To observe what ivy actually downloaded, set IVY_HOME environment variable to a directory of your choice. It will be created and filled with ivy stuff.
build.xml:
<project default="t1"
xmlns:ivy="antlib:org.apache.ivy.ant" >
<property name="ivy.install.version" value="2.2.0" />
<property environment="env" />
<condition property="ivy.home" value="${env.IVY_HOME}">
<isset property="env.IVY_HOME" />
</condition>
<property name="ivy.home" value="${user.home}/.ant" />
<property name="ivy.jar.dir" value="${ivy.home}/lib" />
<property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar" />
<target name="check-ivy">
<condition property="ivy.present">
<available file="${ivy.jar.file}" type="file" />
</condition>
</target>
<target name="download-ivy" unless="ivy.present">
<mkdir dir="${ivy.jar.dir}"/>
<!-- download Ivy from web site so that it can be used even without any special installation -->
<get src="http://repo2.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar"
dest="${ivy.jar.file}" usetimestamp="true"/>
</target>
<target name="init-ivy" depends="check-ivy, download-ivy">
<!-- try to load ivy here from ivy home, in case the user has not already dropped
it into ant's lib dir (note that the latter copy will always take precedence).
We will not fail as long as local lib dir exists (it may be empty) and
ivy is in at least one of ant's lib dir or the local lib dir. -->
<path id="ivy.lib.path">
<fileset dir="${ivy.jar.dir}" includes="*.jar"/>
</path>
<taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
</target>
<target name="ivy-libs" depends="init-ivy" >
<ivy:cachepath pathid="path.from.ivy" log="download-only" />
</target>
<target name="t1" depends="ivy-libs" >
<script language="beanshell" classpathref="path.from.ivy">
javax.swing.JOptionPane.showMessageDialog(null, "Hello, Script!");
</script>
</target>
</project>
ivy.xml:
<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation=
"http://ant.apache.org/ivy/schemas/ivy.xsd">
<info organisation="example.com" module="testing-script-task" />
<dependencies>
<dependency org="org.beanshell" name="bsh" rev="2.0b5" />
<!-- <dependency org="bsf" name="bsf" rev="2.4.0" /> -->
</dependencies>
</ivy-module>
The Ant plug-in "org.apache.ant_1.7.0.v200803061910" have all the jar files needed
Don't use beanshell language. Use javascript instead, as it runs on jdk6 without any additional jars. Rebse told me that.
Javascript is also allowed to use java classes, for example java.lang.System.out.println()